Commit a7370ae4 authored by Friedemann Kleint's avatar Friedemann Kleint

Analyzer: Add status label.

Factor out the status label with timeout from the debugger plugin.
Use in analyzer manager, add standard messages and use that
in memcheck.

Task-number: QTCREATORBUG-4077
Reviewed-by: default avatarDaniel Molkentin <daniel.molkentin@nokia.com>
parent 18074ccc
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "statuslabel.h"
#include <QtCore/QTimer>
/*!
\class Utils::StatusLabel
\brief A status label that displays messages for a while with a timeout.
*/
namespace Utils {
StatusLabel::StatusLabel(QWidget *parent) : QLabel(parent), m_timer(0)
{
// A manual size let's us shrink below minimum text width which is what
// we want in [fake] status bars.
setMinimumSize(QSize(30, 10));
}
void StatusLabel::stopTimer()
{
if (m_timer && m_timer->isActive())
m_timer->stop();
}
void StatusLabel::showStatusMessage(const QString &message, int timeoutMS)
{
setText(message);
if (timeoutMS > 0) {
if (!m_timer) {
m_timer = new QTimer(this);
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
}
m_timer->start(timeoutMS);
} else {
m_lastPermanentStatusMessage = message;
stopTimer();
}
}
void StatusLabel::slotTimeout()
{
setText(m_lastPermanentStatusMessage);
}
void StatusLabel::clearStatusMessage()
{
stopTimer();
m_lastPermanentStatusMessage.clear();
clear();
}
} // namespace Utils
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef UTILS_STATUSLABEL_H
#define UTILS_STATUSLABEL_H
#include "utils_global.h"
QT_FORWARD_DECLARE_CLASS(QTimer)
#include <QtGui/QLabel>
namespace Utils {
class QTCREATOR_UTILS_EXPORT StatusLabel : public QLabel
{
Q_OBJECT
public:
explicit StatusLabel(QWidget *parent = 0);
public slots:
void showStatusMessage(const QString &message, int timeoutMS = 5000);
void clearStatusMessage();
private slots:
void slotTimeout();
private:
void stopTimer();
QTimer *m_timer;
QString m_lastPermanentStatusMessage;
};
} // namespace Utils
#endif // UTILS_STATUSLABEL_H
......@@ -57,6 +57,7 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/annotateditemdelegate.cpp \
$$PWD/fileinprojectfinder.cpp \
$$PWD/ipaddresslineedit.cpp \
$$PWD/statuslabel.cpp \
$$PWD/ssh/sshsendfacility.cpp \
$$PWD/ssh/sshremoteprocess.cpp \
$$PWD/ssh/sshpacketparser.cpp \
......@@ -169,7 +170,8 @@ HEADERS += $$PWD/environment.h \
$$PWD/ssh/sftpchannel.h \
$$PWD/ssh/sftpchannel_p.h \
$$PWD/ssh/sshremoteprocessrunner.h \
$$PWD/settingsutils.h
$$PWD/settingsutils.h \
$$PWD/statuslabel.h
FORMS += $$PWD/filewizardpage.ui \
$$PWD/projectintropage.ui \
......
......@@ -71,6 +71,7 @@
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
#include <utils/checkablemessagebox.h>
#include <utils/statuslabel.h>
#include <cmakeprojectmanager/cmakeprojectconstants.h>
#include <qt4projectmanager/qt4projectmanagerconstants.h>
......@@ -210,6 +211,7 @@ public:
QMenu *m_menu;
QComboBox *m_toolBox;
ActionContainer *m_viewsMenu;
Utils::StatusLabel *m_statusLabel;
typedef QPair<Qt::DockWidgetArea, QDockWidget*> ToolWidgetPair;
typedef QList<ToolWidgetPair> ToolWidgetPairList;
QMap<IAnalyzerTool*, ToolWidgetPairList> m_toolWidgets;
......@@ -236,6 +238,7 @@ AnalyzerManager::AnalyzerManagerPrivate::AnalyzerManagerPrivate(AnalyzerManager
m_menu(0),
m_toolBox(new QComboBox),
m_viewsMenu(0),
m_statusLabel(new Utils::StatusLabel),
m_resizeEventFilter(new DockWidgetEventFilter(qq)),
m_initialized(false)
{
......@@ -339,12 +342,13 @@ static QToolButton *toolButton(QAction *action)
return button;
}
QWidgetList AnalyzerManager::outputPaneToolBarWidgets() const
void AnalyzerManager::addOutputPaneToolBarWidgets(QWidgetList *list) const
{
QWidgetList result;
result << toolButton(d->m_startAction) << toolButton(d->m_stopAction)
<< new Utils::StyledSeparator << d->m_toolBox;
return result;
list->prepend(d->m_toolBox);
list->prepend(toolButton(d->m_stopAction));
list->prepend(toolButton(d->m_startAction));
(*list) << new Utils::StyledSeparator << d->m_statusLabel;
}
QWidget *AnalyzerManager::AnalyzerManagerPrivate::createModeMainWindow()
......@@ -733,4 +737,26 @@ void AnalyzerManager::updateRunActions()
d->m_startAction->setEnabled(startEnabled);
}
void AnalyzerManager::showStatusMessage(const QString &message, int timeoutMS)
{
d->m_statusLabel->showStatusMessage(message, timeoutMS);
}
void AnalyzerManager::showPermanentStatusMessage(const QString &message)
{
showStatusMessage(message, -1);
}
QString AnalyzerManager::msgToolStarted(const QString &name)
{
return tr("Tool '%1' started...").arg(name);
}
QString AnalyzerManager::msgToolFinished(const QString &name, int issuesFound)
{
return issuesFound ?
tr("Tool '%1' finished, %n issues were found.", 0, issuesFound).arg(name) :
tr("Tool '%1' finished, no issues were found.").arg(name);
}
#include "analyzermanager.moc"
......@@ -88,7 +88,14 @@ public:
void selectTool(IAnalyzerTool *tool);
QList<QWidget *> outputPaneToolBarWidgets() const;
void addOutputPaneToolBarWidgets(QList<QWidget *> *) const;
static QString msgToolStarted(const QString &name);
static QString msgToolFinished(const QString &name, int issuesFound);
public slots:
void showStatusMessage(const QString &message, int timeoutMS = 10000);
void showPermanentStatusMessage(const QString &message);
private slots:
void startTool();
......
......@@ -227,8 +227,9 @@ QWidgetList AnalyzerOutputPane::toolBarWidgets() const
qDebug() << "AnalyzerOutputPane::toolBarWidget";
QTC_ASSERT(isInitialized(), return QWidgetList(); )
QWidgetList list = AnalyzerManager::instance()->outputPaneToolBarWidgets();
QWidgetList list;
list << m_toolBarSeparator << m_toolbarStackedWidget;
AnalyzerManager::instance()->addOutputPaneToolBarWidgets(&list);
return list;
}
......
......@@ -106,6 +106,7 @@
#include <utils/savedaction.h>
#include <utils/styledbar.h>
#include <utils/proxyaction.h>
#include <utils/statuslabel.h>
#include <qml/scriptconsole.h>
......@@ -746,8 +747,6 @@ public slots:
void updateWatchersWindow();
void onCurrentProjectChanged(ProjectExplorer::Project *project);
void clearStatusMessage();
void sessionLoaded();
void aboutToUnloadSession();
void aboutToSaveSession();
......@@ -1018,7 +1017,7 @@ public:
QIcon m_interruptIcon;
QIcon m_locationMarkIcon;
QLabel *m_statusLabel;
Utils::StatusLabel *m_statusLabel;
QComboBox *m_threadBox;
BreakWindow *m_breakWindow;
......@@ -1037,7 +1036,6 @@ public:
ScriptConsole *m_scriptConsoleWindow;
bool m_busy;
QTimer m_statusTimer;
QString m_lastPermanentStatusMessage;
mutable CPlusPlus::Snapshot m_codeModelSnapshot;
......@@ -2152,11 +2150,6 @@ void DebuggerPluginPrivate::dumpLog()
ts << m_logWindow->combinedContents();
}
void DebuggerPluginPrivate::clearStatusMessage()
{
m_statusLabel->setText(m_lastPermanentStatusMessage);
}
/*! Activates the previous mode when the current mode is the debug mode. */
void DebuggerPluginPrivate::activatePreviousMode()
{
......@@ -2216,15 +2209,8 @@ void DebuggerPluginPrivate::showStatusMessage(const QString &msg0, int timeout)
{
showMessage(msg0, LogStatus);
QString msg = msg0;
msg.replace(QLatin1Char('\n'), QString());
m_statusLabel->setText(msg);
if (timeout > 0) {
m_statusTimer.setSingleShot(true);
m_statusTimer.start(timeout);
} else {
m_lastPermanentStatusMessage = msg;
m_statusTimer.stop();
}
msg.remove(QLatin1Char('\n'));
m_statusLabel->showStatusMessage(msg, timeout);
}
void DebuggerPluginPrivate::scriptExpressionEntered(const QString &expression)
......@@ -2550,8 +2536,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
m_busy = false;
m_statusLabel = new QLabel;
m_statusLabel->setMinimumSize(QSize(30, 10));
m_statusLabel = new Utils::StatusLabel;
m_breakHandler = new BreakHandler;
m_breakWindow = new BreakWindow;
......@@ -2674,8 +2659,6 @@ void DebuggerPluginPrivate::extensionsInitialized()
connect(action(OperateByInstruction), SIGNAL(triggered(bool)),
SLOT(handleOperateByInstructionTriggered(bool)));
connect(&m_statusTimer, SIGNAL(timeout()), SLOT(clearStatusMessage()));
ActionContainer *debugMenu =
am->actionContainer(ProjectExplorer::Constants::M_DEBUG);
......
......@@ -430,6 +430,8 @@ IAnalyzerEngine *MemcheckTool::createEngine(ProjectExplorer::RunConfiguration *r
this, SLOT(parserError(Valgrind::XmlProtocol::Error)));
connect(engine, SIGNAL(internalParserError(QString)),
this, SLOT(internalParserError(QString)));
connect(engine, SIGNAL(finished()), this, SLOT(finished()));
AnalyzerManager::instance()->showStatusMessage(AnalyzerManager::msgToolStarted(displayName()));
return engine;
}
......@@ -523,5 +525,11 @@ IAnalyzerOutputPaneAdapter *MemcheckTool::outputPaneAdapter()
return m_outputPaneAdapter;
}
void MemcheckTool::finished()
{
const QString msg = AnalyzerManager::msgToolFinished(displayName(), m_errorModel->rowCount());
AnalyzerManager::instance()->showStatusMessage(msg);
}
} // namespace Internal
} // namespace Analyzer
......@@ -111,6 +111,7 @@ private slots:
void internalParserError(const QString &errorString);
void updateErrorFilter();
void suppressionActionTriggered();
void finished();
QMenu *filterMenu() const;
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment