forked from qt-creator/qt-creator
TaskList: Pimpl and avoid using the global object pool
Use the pattern that's currently being established. Change-Id: Icfb1472cc394f0e371056d5cb23fd22d291dbdaa Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -39,7 +39,6 @@
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QStringList>
|
||||
#include <QtPlugin>
|
||||
|
||||
using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
@@ -52,6 +51,14 @@ namespace Internal {
|
||||
|
||||
static TaskListPlugin *m_instance;
|
||||
|
||||
class TaskListPluginPrivate
|
||||
{
|
||||
public:
|
||||
QList<TaskFile *> m_openFiles;
|
||||
Core::IDocumentFactory m_fileFactory;
|
||||
StopMonitoringHandler m_stopMonitoringHandler;
|
||||
};
|
||||
|
||||
static Task::TaskType typeFrom(const QString &typeName)
|
||||
{
|
||||
Task::TaskType type = Task::Unknown;
|
||||
@@ -158,7 +165,7 @@ static bool parseTaskFile(QString *errorString, const FileName &name)
|
||||
|
||||
IDocument *TaskListPlugin::openTasks(const FileName &fileName)
|
||||
{
|
||||
foreach (TaskFile *doc, m_openFiles) {
|
||||
foreach (TaskFile *doc, d->m_openFiles) {
|
||||
if (doc->filePath() == fileName)
|
||||
return doc;
|
||||
}
|
||||
@@ -169,10 +176,10 @@ IDocument *TaskListPlugin::openTasks(const FileName &fileName)
|
||||
if (!file->load(&errorString, fileName)) {
|
||||
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), errorString);
|
||||
delete file;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_openFiles.append(file);
|
||||
d->m_openFiles.append(file);
|
||||
|
||||
// Register with filemanager:
|
||||
DocumentManager::addDocument(file);
|
||||
@@ -185,23 +192,27 @@ TaskListPlugin::TaskListPlugin()
|
||||
m_instance = this;
|
||||
}
|
||||
|
||||
TaskListPlugin::~TaskListPlugin()
|
||||
{
|
||||
delete d;
|
||||
m_instance = nullptr;
|
||||
}
|
||||
|
||||
bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
{
|
||||
Q_UNUSED(arguments)
|
||||
Q_UNUSED(errorMessage)
|
||||
|
||||
d = new TaskListPluginPrivate;
|
||||
|
||||
//: Category under which tasklist tasks are listed in Issues view
|
||||
TaskHub::addCategory(Constants::TASKLISTTASK_ID, tr("My Tasks"));
|
||||
|
||||
m_fileFactory = new IDocumentFactory;
|
||||
m_fileFactory->addMimeType(QLatin1String("text/x-tasklist"));
|
||||
m_fileFactory->setOpener([this](const QString &fileName) {
|
||||
d->m_fileFactory.addMimeType(QLatin1String("text/x-tasklist"));
|
||||
d->m_fileFactory.setOpener([this](const QString &fileName) {
|
||||
return openTasks(FileName::fromString(fileName));
|
||||
});
|
||||
|
||||
addAutoReleasedObject(m_fileFactory);
|
||||
addAutoReleasedObject(new StopMonitoringHandler);
|
||||
|
||||
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
|
||||
this, &TaskListPlugin::loadDataFromSession);
|
||||
|
||||
@@ -225,9 +236,9 @@ void TaskListPlugin::stopMonitoring()
|
||||
{
|
||||
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), QString());
|
||||
|
||||
foreach (TaskFile *document, m_instance->m_openFiles)
|
||||
foreach (TaskFile *document, m_instance->d->m_openFiles)
|
||||
document->deleteLater();
|
||||
m_instance->m_openFiles.clear();
|
||||
m_instance->d->m_openFiles.clear();
|
||||
}
|
||||
|
||||
void TaskListPlugin::clearTasks()
|
||||
|
||||
Reference in New Issue
Block a user