From a7370ae4b0fdaa233875d8302c2df3ebbf3d37c0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 16 Mar 2011 13:49:28 +0100 Subject: [PATCH] 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: Daniel Molkentin --- src/libs/utils/statuslabel.cpp | 87 +++++++++++++++++++++++++ src/libs/utils/statuslabel.h | 67 +++++++++++++++++++ src/libs/utils/utils-lib.pri | 4 +- src/plugins/analyzerbase/analyzermanager.cpp | 36 ++++++++-- src/plugins/analyzerbase/analyzermanager.h | 9 ++- src/plugins/analyzerbase/analyzeroutputpane.cpp | 3 +- src/plugins/debugger/debuggerplugin.cpp | 27 ++------ src/plugins/memcheck/memchecktool.cpp | 8 +++ src/plugins/memcheck/memchecktool.h | 1 + 9 files changed, 212 insertions(+), 30 deletions(-) create mode 100644 src/libs/utils/statuslabel.cpp create mode 100644 src/libs/utils/statuslabel.h diff --git a/src/libs/utils/statuslabel.cpp b/src/libs/utils/statuslabel.cpp new file mode 100644 index 0000000000..9c5f72fe5d --- /dev/null +++ b/src/libs/utils/statuslabel.cpp @@ -0,0 +1,87 @@ +/************************************************************************** +** +** 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 + +/*! + \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 diff --git a/src/libs/utils/statuslabel.h b/src/libs/utils/statuslabel.h new file mode 100644 index 0000000000..3836b292af --- /dev/null +++ b/src/libs/utils/statuslabel.h @@ -0,0 +1,67 @@ +/************************************************************************** +** +** 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 + +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 diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 00106c8b4e..698659fd6e 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -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 \ diff --git a/src/plugins/analyzerbase/analyzermanager.cpp b/src/plugins/analyzerbase/analyzermanager.cpp index 2e72046df8..ee872b9950 100644 --- a/src/plugins/analyzerbase/analyzermanager.cpp +++ b/src/plugins/analyzerbase/analyzermanager.cpp @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -210,6 +211,7 @@ public: QMenu *m_menu; QComboBox *m_toolBox; ActionContainer *m_viewsMenu; + Utils::StatusLabel *m_statusLabel; typedef QPair ToolWidgetPair; typedef QList ToolWidgetPairList; QMap 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" diff --git a/src/plugins/analyzerbase/analyzermanager.h b/src/plugins/analyzerbase/analyzermanager.h index 0187eeb3d3..b069d49483 100644 --- a/src/plugins/analyzerbase/analyzermanager.h +++ b/src/plugins/analyzerbase/analyzermanager.h @@ -88,7 +88,14 @@ public: void selectTool(IAnalyzerTool *tool); - QList outputPaneToolBarWidgets() const; + void addOutputPaneToolBarWidgets(QList *) 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(); diff --git a/src/plugins/analyzerbase/analyzeroutputpane.cpp b/src/plugins/analyzerbase/analyzeroutputpane.cpp index e1d8bb6b41..4d8f0b2018 100644 --- a/src/plugins/analyzerbase/analyzeroutputpane.cpp +++ b/src/plugins/analyzerbase/analyzeroutputpane.cpp @@ -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; } diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 9d0f50a0f4..54c4bc0c6b 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -106,6 +106,7 @@ #include #include #include +#include #include @@ -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); diff --git a/src/plugins/memcheck/memchecktool.cpp b/src/plugins/memcheck/memchecktool.cpp index f5470a95a9..9d1e9df5d8 100644 --- a/src/plugins/memcheck/memchecktool.cpp +++ b/src/plugins/memcheck/memchecktool.cpp @@ -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 diff --git a/src/plugins/memcheck/memchecktool.h b/src/plugins/memcheck/memchecktool.h index e71cb83ed8..658c7bf822 100644 --- a/src/plugins/memcheck/memchecktool.h +++ b/src/plugins/memcheck/memchecktool.h @@ -111,6 +111,7 @@ private slots: void internalParserError(const QString &errorString); void updateErrorFilter(); void suppressionActionTriggered(); + void finished(); QMenu *filterMenu() const; private: -- 2.11.0