Commit 98917598 authored by hjk's avatar hjk

ProjectManager: Use Core::Id for progress types

Change-Id: I72993fda50ad70ad2d7c2f449923ac6e34b9e737
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 1f340d44
...@@ -235,10 +235,10 @@ void Manager::initialize() ...@@ -235,10 +235,10 @@ void Manager::initialize()
SLOT(onProjectListChanged()), Qt::QueuedConnection); SLOT(onProjectListChanged()), Qt::QueuedConnection);
// connect to the progress manager for signals about Parsing tasks // connect to the progress manager for signals about Parsing tasks
connect(ProgressManager::instance(), SIGNAL(taskStarted(QString)), connect(ProgressManager::instance(), SIGNAL(taskStarted(Core::Id)),
SLOT(onTaskStarted(QString)), Qt::QueuedConnection); SLOT(onTaskStarted(Core::Id)), Qt::QueuedConnection);
connect(ProgressManager::instance(), SIGNAL(allTasksFinished(QString)), connect(ProgressManager::instance(), SIGNAL(allTasksFinished(Core::Id)),
SLOT(onAllTasksFinished(QString)), Qt::QueuedConnection); SLOT(onAllTasksFinished(Core::Id)), Qt::QueuedConnection);
// when we signals that really document is updated - sent it to the parser // when we signals that really document is updated - sent it to the parser
connect(this, SIGNAL(requestDocumentUpdated(CPlusPlus::Document::Ptr)), connect(this, SIGNAL(requestDocumentUpdated(CPlusPlus::Document::Ptr)),
...@@ -379,9 +379,9 @@ void Manager::onProjectListChanged() ...@@ -379,9 +379,9 @@ void Manager::onProjectListChanged()
\sa CppTools::Constants::TASK_INDEX \sa CppTools::Constants::TASK_INDEX
*/ */
void Manager::onTaskStarted(const QString &type) void Manager::onTaskStarted(Core::Id type)
{ {
if (type != QLatin1String(CppTools::Constants::TASK_INDEX)) if (type != CppTools::Constants::TASK_INDEX)
return; return;
// disable tree updates to speed up // disable tree updates to speed up
...@@ -395,9 +395,9 @@ void Manager::onTaskStarted(const QString &type) ...@@ -395,9 +395,9 @@ void Manager::onTaskStarted(const QString &type)
\sa CppTools::Constants::TASK_INDEX \sa CppTools::Constants::TASK_INDEX
*/ */
void Manager::onAllTasksFinished(const QString &type) void Manager::onAllTasksFinished(Core::Id type)
{ {
if (type != QLatin1String(CppTools::Constants::TASK_INDEX)) if (type != CppTools::Constants::TASK_INDEX)
return; return;
// parsing is finished, enable tree updates // parsing is finished, enable tree updates
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QStandardItem> #include <QStandardItem>
#include <coreplugin/id.h>
#include <cplusplus/CppDocument.h> #include <cplusplus/CppDocument.h>
namespace ClassView { namespace ClassView {
...@@ -85,19 +86,12 @@ public slots: ...@@ -85,19 +86,12 @@ public slots:
protected slots: protected slots:
void onWidgetIsCreated(); void onWidgetIsCreated();
void onWidgetVisibilityIsChanged(bool visibility); void onWidgetVisibilityIsChanged(bool visibility);
void onStateChanged(bool state); void onStateChanged(bool state);
void onProjectListChanged(); void onProjectListChanged();
void onDocumentUpdated(CPlusPlus::Document::Ptr doc); void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
void onTaskStarted(Core::Id type);
void onTaskStarted(const QString &type); void onAllTasksFinished(Core::Id type);
void onAllTasksFinished(const QString &type);
void onTreeDataUpdate(QSharedPointer<QStandardItem> result); void onTreeDataUpdate(QSharedPointer<QStandardItem> result);
protected: protected:
......
...@@ -371,8 +371,8 @@ bool ClearCasePlugin::initialize(const QStringList & /*arguments */, QString *er ...@@ -371,8 +371,8 @@ bool ClearCasePlugin::initialize(const QStringList & /*arguments */, QString *er
m_clearcasePluginInstance = this; m_clearcasePluginInstance = this;
connect(ICore::instance(), SIGNAL(coreAboutToClose()), this, SLOT(closing())); connect(ICore::instance(), SIGNAL(coreAboutToClose()), this, SLOT(closing()));
connect(ProgressManager::instance(), SIGNAL(allTasksFinished(QString)), connect(ProgressManager::instance(), SIGNAL(allTasksFinished(Core::Id)),
this, SLOT(tasksFinished(QString))); this, SLOT(tasksFinished(Core::Id)));
if (!MimeDatabase::addMimeTypes(QLatin1String(":/clearcase/ClearCase.mimetypes.xml"), errorMessage)) if (!MimeDatabase::addMimeTypes(QLatin1String(":/clearcase/ClearCase.mimetypes.xml"), errorMessage))
return false; return false;
...@@ -1891,7 +1891,7 @@ void ClearCasePlugin::projectChanged(Project *project) ...@@ -1891,7 +1891,7 @@ void ClearCasePlugin::projectChanged(Project *project)
m_stream.clear(); m_stream.clear();
m_intStream.clear(); m_intStream.clear();
disconnect(ICore::mainWindow(), SIGNAL(windowActivated()), this, SLOT(syncSlot())); disconnect(ICore::mainWindow(), SIGNAL(windowActivated()), this, SLOT(syncSlot()));
ProgressManager::cancelTasks(QLatin1String(Constants::TASK_INDEX)); ProgressManager::cancelTasks(ClearCase::Constants::TASK_INDEX);
if (project) { if (project) {
QString projDir = project->projectDirectory(); QString projDir = project->projectDirectory();
QString topLevel = findTopLevel(projDir); QString topLevel = findTopLevel(projDir);
...@@ -1908,16 +1908,16 @@ void ClearCasePlugin::projectChanged(Project *project) ...@@ -1908,16 +1908,16 @@ void ClearCasePlugin::projectChanged(Project *project)
qDebug() << "stream: " << m_stream << "; intStream: " << m_intStream << "view: " << m_viewData.name; qDebug() << "stream: " << m_stream << "; intStream: " << m_intStream << "view: " << m_viewData.name;
} }
void ClearCasePlugin::tasksFinished(const QString &type) void ClearCasePlugin::tasksFinished(Core::Id type)
{ {
if (type == QLatin1String(Constants::TASK_INDEX)) if (type == ClearCase::Constants::TASK_INDEX)
m_checkInAllAction->setEnabled(true); m_checkInAllAction->setEnabled(true);
} }
void ClearCasePlugin::updateIndex() void ClearCasePlugin::updateIndex()
{ {
QTC_ASSERT(currentState().hasTopLevel(), return); QTC_ASSERT(currentState().hasTopLevel(), return);
ProgressManager::cancelTasks(QLatin1String(Constants::TASK_INDEX)); ProgressManager::cancelTasks(ClearCase::Constants::TASK_INDEX);
Project *project = ProjectExplorerPlugin::currentProject(); Project *project = ProjectExplorerPlugin::currentProject();
if (!project) if (!project)
return; return;
...@@ -1926,8 +1926,7 @@ void ClearCasePlugin::updateIndex() ...@@ -1926,8 +1926,7 @@ void ClearCasePlugin::updateIndex()
QFuture<void> result = QtConcurrent::run(&sync, QFuture<void> result = QtConcurrent::run(&sync,
project->files(Project::ExcludeGeneratedFiles)); project->files(Project::ExcludeGeneratedFiles));
if (!m_settings.disableIndexer) if (!m_settings.disableIndexer)
ProgressManager::addTask(result, tr("CC Indexing"), ProgressManager::addTask(result, tr("CC Indexing"), ClearCase::Constants::TASK_INDEX);
QLatin1String(Constants::TASK_INDEX));
} }
/*! retrieve a \a file (usually of the form path\to\filename.cpp@@\main\ver) /*! retrieve a \a file (usually of the form path\to\filename.cpp@@\main\ver)
...@@ -2069,7 +2068,7 @@ void ClearCasePlugin::syncSlot() ...@@ -2069,7 +2068,7 @@ void ClearCasePlugin::syncSlot()
void ClearCasePlugin::closing() void ClearCasePlugin::closing()
{ {
// prevent syncSlot from being called on shutdown // prevent syncSlot from being called on shutdown
ProgressManager::cancelTasks(QLatin1String(Constants::TASK_INDEX)); ProgressManager::cancelTasks(ClearCase::Constants::TASK_INDEX);
disconnect(ICore::mainWindow(), SIGNAL(windowActivated()), this, SLOT(syncSlot())); disconnect(ICore::mainWindow(), SIGNAL(windowActivated()), this, SLOT(syncSlot()));
} }
......
...@@ -33,7 +33,9 @@ ...@@ -33,7 +33,9 @@
#include "clearcasesettings.h" #include "clearcasesettings.h"
#include <coreplugin/id.h>
#include <vcsbase/vcsbaseplugin.h> #include <vcsbase/vcsbaseplugin.h>
#include <QFile> #include <QFile>
#include <QPair> #include <QPair>
#include <QStringList> #include <QStringList>
...@@ -191,7 +193,7 @@ private slots: ...@@ -191,7 +193,7 @@ private slots:
void updateIndex(); void updateIndex();
void updateView(); void updateView();
void projectChanged(ProjectExplorer::Project *project); void projectChanged(ProjectExplorer::Project *project);
void tasksFinished(const QString &type); void tasksFinished(Core::Id type);
void syncSlot(); void syncSlot();
void closing(); void closing();
void updateStatusActions(); void updateStatusActions();
......
...@@ -48,9 +48,10 @@ ...@@ -48,9 +48,10 @@
using namespace Core; using namespace Core;
using namespace Core::Internal; using namespace Core::Internal;
CorePlugin::CorePlugin() : CorePlugin::CorePlugin() : m_editMode(0), m_designMode(0)
m_mainWindow(new MainWindow), m_editMode(0), m_designMode(0)
{ {
qRegisterMetaType<Core::Id>();
m_mainWindow = new MainWindow;
} }
CorePlugin::~CorePlugin() CorePlugin::~CorePlugin()
......
...@@ -118,7 +118,7 @@ MainWindow::MainWindow() : ...@@ -118,7 +118,7 @@ MainWindow::MainWindow() :
m_actionManager(new ActionManager(this)), m_actionManager(new ActionManager(this)),
m_editorManager(0), m_editorManager(0),
m_externalToolManager(0), m_externalToolManager(0),
m_progressManager(new ProgressManagerPrivate()), m_progressManager(new ProgressManagerPrivate),
m_variableManager(new VariableManager), m_variableManager(new VariableManager),
m_vcsManager(new VcsManager), m_vcsManager(new VcsManager),
m_statusBarManager(0), m_statusBarManager(0),
......
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
QWidget *m_widget; QWidget *m_widget;
QHBoxLayout *m_widgetLayout; QHBoxLayout *m_widgetLayout;
QWidget *m_statusBarWidget; QWidget *m_statusBarWidget;
QString m_type; Id m_type;
FutureProgress::KeepOnFinishType m_keep; FutureProgress::KeepOnFinishType m_keep;
bool m_waitingForUserInteraction; bool m_waitingForUserInteraction;
FutureProgress *m_q; FutureProgress *m_q;
...@@ -304,12 +304,12 @@ bool FutureProgress::hasError() const ...@@ -304,12 +304,12 @@ bool FutureProgress::hasError() const
return d->m_progress->hasError(); return d->m_progress->hasError();
} }
void FutureProgress::setType(const QString &type) void FutureProgress::setType(Id type)
{ {
d->m_type = type; d->m_type = type;
} }
QString FutureProgress::type() const Id FutureProgress::type() const
{ {
return d->m_type; return d->m_type;
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define FUTUREPROGRESS_H #define FUTUREPROGRESS_H
#include <coreplugin/core_global.h> #include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QString> #include <QString>
#include <QFuture> #include <QFuture>
...@@ -60,8 +61,8 @@ public: ...@@ -60,8 +61,8 @@ public:
void setTitle(const QString &title); void setTitle(const QString &title);
QString title() const; QString title() const;
void setType(const QString &type); void setType(Id type);
QString type() const; Id type() const;
void setKeepOnFinish(KeepOnFinishType keepType); void setKeepOnFinish(KeepOnFinishType keepType);
bool keepOnFinish() const; bool keepOnFinish() const;
......
...@@ -245,7 +245,7 @@ using namespace Core::Internal; ...@@ -245,7 +245,7 @@ using namespace Core::Internal;
*/ */
/*! /*!
\fn void Core::ProgressManager::cancelTasks(const QString &type) \fn void Core::ProgressManager::cancelTasks(Core::Id type)
Schedules a cancel for all running tasks of the given \a type. Schedules a cancel for all running tasks of the given \a type.
Please note that the cancel functionality depends on the Please note that the cancel functionality depends on the
...@@ -254,13 +254,13 @@ using namespace Core::Internal; ...@@ -254,13 +254,13 @@ using namespace Core::Internal;
*/ */
/*! /*!
\fn void Core::ProgressManager::taskStarted(const QString &type) \fn void Core::ProgressManager::taskStarted(Core::Id type)
Sent whenever a task of a given \a type is started. Sent whenever a task of a given \a type is started.
*/ */
/*! /*!
\fn void Core::ProgressManager::allTasksFinished(const QString &type) \fn void Core::ProgressManager::allTasksFinished(Core::Id type)
Sent when all tasks of a \a type have finished. Sent when all tasks of a \a type have finished.
*/ */
...@@ -347,10 +347,10 @@ void ProgressManagerPrivate::init() ...@@ -347,10 +347,10 @@ void ProgressManagerPrivate::init()
initInternal(); initInternal();
} }
void ProgressManagerPrivate::doCancelTasks(const QString &type) void ProgressManagerPrivate::doCancelTasks(Id type)
{ {
bool found = false; bool found = false;
QMap<QFutureWatcher<void> *, QString>::iterator task = m_runningTasks.begin(); QMap<QFutureWatcher<void> *, Id>::iterator task = m_runningTasks.begin();
while (task != m_runningTasks.end()) { while (task != m_runningTasks.end()) {
if (task.value() != type) { if (task.value() != type) {
++task; ++task;
...@@ -398,7 +398,7 @@ bool ProgressManagerPrivate::eventFilter(QObject *obj, QEvent *event) ...@@ -398,7 +398,7 @@ bool ProgressManagerPrivate::eventFilter(QObject *obj, QEvent *event)
void ProgressManagerPrivate::cancelAllRunningTasks() void ProgressManagerPrivate::cancelAllRunningTasks()
{ {
QMap<QFutureWatcher<void> *, QString>::const_iterator task = m_runningTasks.constBegin(); QMap<QFutureWatcher<void> *, Id>::const_iterator task = m_runningTasks.constBegin();
while (task != m_runningTasks.constEnd()) { while (task != m_runningTasks.constEnd()) {
disconnect(task.key(), SIGNAL(finished()), this, SLOT(taskFinished())); disconnect(task.key(), SIGNAL(finished()), this, SLOT(taskFinished()));
if (m_applicationTask == task.key()) if (m_applicationTask == task.key())
...@@ -412,7 +412,7 @@ void ProgressManagerPrivate::cancelAllRunningTasks() ...@@ -412,7 +412,7 @@ void ProgressManagerPrivate::cancelAllRunningTasks()
} }
FutureProgress *ProgressManagerPrivate::doAddTask(const QFuture<void> &future, const QString &title, FutureProgress *ProgressManagerPrivate::doAddTask(const QFuture<void> &future, const QString &title,
const QString &type, ProgressFlags flags) Id type, ProgressFlags flags)
{ {
// watch // watch
QFutureWatcher<void> *watcher = new QFutureWatcher<void>(); QFutureWatcher<void> *watcher = new QFutureWatcher<void>();
...@@ -473,7 +473,7 @@ void ProgressManagerPrivate::taskFinished() ...@@ -473,7 +473,7 @@ void ProgressManagerPrivate::taskFinished()
QFutureWatcher<void> *task = static_cast<QFutureWatcher<void> *>(taskObject); QFutureWatcher<void> *task = static_cast<QFutureWatcher<void> *>(taskObject);
if (m_applicationTask == task) if (m_applicationTask == task)
disconnectApplicationTask(); disconnectApplicationTask();
QString type = m_runningTasks.value(task); Id type = m_runningTasks.value(task);
m_runningTasks.remove(task); m_runningTasks.remove(task);
delete task; delete task;
updateSummaryProgressBar(); updateSummaryProgressBar();
...@@ -506,7 +506,7 @@ void ProgressManagerPrivate::updateSummaryProgressBar() ...@@ -506,7 +506,7 @@ void ProgressManagerPrivate::updateSummaryProgressBar()
stopFadeOfSummaryProgress(); stopFadeOfSummaryProgress();
m_summaryProgressBar->setFinished(false); m_summaryProgressBar->setFinished(false);
QMapIterator<QFutureWatcher<void> *, QString> it(m_runningTasks); QMapIterator<QFutureWatcher<void> *, Id> it(m_runningTasks);
static const int TASK_RANGE = 100; static const int TASK_RANGE = 100;
int value = 0; int value = 0;
while (it.hasNext()) { while (it.hasNext()) {
...@@ -563,12 +563,12 @@ void ProgressManagerPrivate::slotRemoveTask() ...@@ -563,12 +563,12 @@ void ProgressManagerPrivate::slotRemoveTask()
{ {
FutureProgress *progress = qobject_cast<FutureProgress *>(sender()); FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
QTC_ASSERT(progress, return); QTC_ASSERT(progress, return);
QString type = progress->type(); Id type = progress->type();
removeTask(progress); removeTask(progress);
removeOldTasks(type, true); removeOldTasks(type, true);
} }
void ProgressManagerPrivate::removeOldTasks(const QString &type, bool keepOne) void ProgressManagerPrivate::removeOldTasks(const Id type, bool keepOne)
{ {
bool firstFound = !keepOne; // start with false if we want to keep one bool firstFound = !keepOne; // start with false if we want to keep one
QList<FutureProgress *>::iterator i = m_taskList.end(); QList<FutureProgress *>::iterator i = m_taskList.end();
...@@ -600,7 +600,7 @@ void ProgressManagerPrivate::removeOneOldTask() ...@@ -600,7 +600,7 @@ void ProgressManagerPrivate::removeOneOldTask()
} }
// no ended process, look for a task type with multiple running tasks and remove the oldest one // no ended process, look for a task type with multiple running tasks and remove the oldest one
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) { for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
QString type = (*i)->type(); Id type = (*i)->type();
int taskCount = 0; int taskCount = 0;
foreach (FutureProgress *p, m_taskList) foreach (FutureProgress *p, m_taskList)
...@@ -735,7 +735,7 @@ QObject *ProgressManager::instance() ...@@ -735,7 +735,7 @@ QObject *ProgressManager::instance()
return m_instance; return m_instance;
} }
FutureProgress *ProgressManager::addTask(const QFuture<void> &future, const QString &title, const QString &type, ProgressFlags flags) FutureProgress *ProgressManager::addTask(const QFuture<void> &future, const QString &title, Id type, ProgressFlags flags)
{ {
return m_instance->doAddTask(future, title, type, flags); return m_instance->doAddTask(future, title, type, flags);
} }
...@@ -745,7 +745,8 @@ void ProgressManager::setApplicationLabel(const QString &text) ...@@ -745,7 +745,8 @@ void ProgressManager::setApplicationLabel(const QString &text)
m_instance->doSetApplicationLabel(text); m_instance->doSetApplicationLabel(text);
} }
void ProgressManager::cancelTasks(const QString &type) void ProgressManager::cancelTasks(const Id type)
{ {
if (m_instance)
m_instance->doCancelTasks(type); m_instance->doCancelTasks(type);
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define PROGRESSMANAGER_H #define PROGRESSMANAGER_H
#include <coreplugin/core_global.h> #include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QObject> #include <QObject>
#include <QFuture> #include <QFuture>
...@@ -53,20 +54,20 @@ public: ...@@ -53,20 +54,20 @@ public:
static QObject *instance(); static QObject *instance();
static FutureProgress *addTask(const QFuture<void> &future, const QString &title, static FutureProgress *addTask(const QFuture<void> &future, const QString &title,
const QString &type, ProgressFlags flags = 0); Core::Id type, ProgressFlags flags = 0);
static void setApplicationLabel(const QString &text); static void setApplicationLabel(const QString &text);
public slots: public slots:
static void cancelTasks(const QString &type); static void cancelTasks(const Core::Id type);
signals: signals:
void taskStarted(const QString &type); void taskStarted(Core::Id type);
void allTasksFinished(const QString &type); void allTasksFinished(Core::Id type);
protected: protected:
virtual void doCancelTasks(const QString &type) = 0; virtual void doCancelTasks(Core::Id type) = 0;
virtual FutureProgress *doAddTask(const QFuture<void> &future, const QString &title, virtual FutureProgress *doAddTask(const QFuture<void> &future, const QString &title,
const QString &type, ProgressFlags flags = 0) = 0; Core::Id type, ProgressFlags flags = 0) = 0;
virtual void doSetApplicationLabel(const QString &text) = 0; virtual void doSetApplicationLabel(const QString &text) = 0;
private: private:
......
...@@ -58,14 +58,14 @@ public: ...@@ -58,14 +58,14 @@ public:
void init(); void init();
void cleanup(); void cleanup();
FutureProgress *doAddTask(const QFuture<void> &future, const QString &title, const QString &type, FutureProgress *doAddTask(const QFuture<void> &future, const QString &title, Id type,
ProgressFlags flags); ProgressFlags flags);
void doSetApplicationLabel(const QString &text); void doSetApplicationLabel(const QString &text);
ProgressView *progressView(); ProgressView *progressView();
public slots: public slots:
void doCancelTasks(const QString &type); void doCancelTasks(Core::Id type);
protected: protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);
...@@ -94,14 +94,14 @@ private: ...@@ -94,14 +94,14 @@ private:
bool hasError() const; bool hasError() const;
bool isLastFading() const; bool isLastFading() const;
void removeOldTasks(const QString &type, bool keepOne = false); void removeOldTasks(Id type, bool keepOne = false);
void removeOneOldTask(); void removeOneOldTask();
void removeTask(FutureProgress *task); void removeTask(FutureProgress *task);
void deleteTask(FutureProgress *task);