Some speed-optimizations for the Progress model.

This commit is contained in:
LoRd_MuldeR 2012-05-07 03:03:14 +02:00
parent 72e8558b5f
commit 21154b10c4
3 changed files with 36 additions and 20 deletions

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 5
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 1016
#define VER_LAMEXP_BUILD 1017
///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!)

View File

@ -136,7 +136,7 @@ QVariant ProgressModel::headerData(int section, Qt::Orientation orientation, int
void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState)
{
if(m_jobList.contains(jobId) || m_jobListHidden.contains(jobId))
if(m_jobIdentifiers.contains(jobId))
{
return;
}
@ -145,6 +145,7 @@ void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QSt
{
beginRemoveRows(QModelIndex(), 0, 0);
m_jobListHidden.append(m_jobList.takeFirst());
m_jobIndexCache.clear();
endRemoveRows();
}
@ -156,33 +157,41 @@ void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QSt
m_jobStatus.insert(jobId, jobInitialStatus);
m_jobState.insert(jobId, jobInitialState);
m_jobLogFile.insert(jobId, QStringList());
m_jobIdentifiers.insert(jobId);
endInsertRows();
}
void ProgressModel::updateJob(const QUuid &jobId, const QString &newStatus, int newState)
{
int row = m_jobList.indexOf(jobId);
if(row < 0)
if(!m_jobIdentifiers.contains(jobId))
{
if(m_jobListHidden.indexOf(jobId) >= 0)
{
if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus);
if(newState >= 0) m_jobState.insert(jobId, newState);
}
return;
}
if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus);
if(newState >= 0) m_jobState.insert(jobId, newState);
emit dataChanged(index(row, 0), index(row, 1));
const int row = m_jobIndexCache.value(jobId, -1);
if(row >= 0)
{
emit dataChanged(index(row, 0), index(row, 1));
}
else
{
const int tmp = m_jobList.indexOf(jobId);
if(tmp >= 0)
{
m_jobIndexCache.insert(jobId, tmp);
emit dataChanged(index(tmp, 0), index(tmp, 1));
}
}
}
void ProgressModel::appendToLog(const QUuid &jobId, const QString &line)
{
if(m_jobList.contains(jobId))
if(m_jobIdentifiers.contains(jobId))
{
m_jobLogFile[jobId].append(line.split('\n'));
}
@ -213,7 +222,7 @@ void ProgressModel::addSystemMessage(const QString &text, int type)
{
const QUuid &jobId = QUuid::createUuid();
if(m_jobList.contains(jobId))
if(m_jobIdentifiers.contains(jobId))
{
return;
}
@ -222,6 +231,7 @@ void ProgressModel::addSystemMessage(const QString &text, int type)
{
beginRemoveRows(QModelIndex(), 0, 0);
m_jobListHidden.append(m_jobList.takeFirst());
m_jobIndexCache.clear();
endRemoveRows();
}
@ -248,6 +258,7 @@ void ProgressModel::addSystemMessage(const QString &text, int type)
m_jobStatus.insert(jobId, QString());
m_jobState.insert(jobId, jobState);
m_jobLogFile.insert(jobId, QStringList());
m_jobIdentifiers.insert(jobId);
endInsertRows();
}
@ -261,6 +272,7 @@ void ProgressModel::restoreHiddenItems(void)
{
m_jobList.prepend(m_jobListHidden.takeLast());
}
m_jobIndexCache.clear();
endResetModel();
}
}

View File

@ -25,7 +25,9 @@
#include <QString>
#include <QStringList>
#include <QMap>
#include <QHash>
#include <QSet>
#include <QUuid>
#include <QIcon>
#include <QUuid>
@ -75,10 +77,12 @@ public slots:
private:
QList<QUuid> m_jobList;
QList<QUuid> m_jobListHidden;
QMap<QUuid, QString> m_jobName;
QMap<QUuid, QString> m_jobStatus;
QMap<QUuid, int> m_jobState;
QMap<QUuid, QStringList> m_jobLogFile;
QHash<QUuid, QString> m_jobName;
QHash<QUuid, QString> m_jobStatus;
QHash<QUuid, int> m_jobState;
QHash<QUuid, QStringList> m_jobLogFile;
QHash<QUuid, int> m_jobIndexCache;
QSet<QUuid> m_jobIdentifiers;
const QIcon m_iconRunning;
const QIcon m_iconPaused;