From d0288b7c57768d7bd92ba98db962b88df2a48fc0 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 18 Nov 2012 14:23:54 +0100 Subject: [PATCH] Made getLogFile() function "const" and made sure that we will return a const reference to the QStringList object inside the QHash, rather than a reference to a local object. --- src/Model_Progress.cpp | 15 +++++++++------ src/Model_Progress.h | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Model_Progress.cpp b/src/Model_Progress.cpp index cc2d0ff9..5ded8c7f 100644 --- a/src/Model_Progress.cpp +++ b/src/Model_Progress.cpp @@ -35,7 +35,9 @@ ProgressModel::ProgressModel(void) m_iconWarning(":/icons/error.png"), m_iconPerformance(":/icons/clock.png"), m_iconSkipped(":/icons/step_over.png"), - m_iconUndefined(":/icons/report.png") + m_iconUndefined(":/icons/report.png"), + m_emptyUuid(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), + m_emptyList("Oups, no data available!") { } @@ -177,15 +179,16 @@ void ProgressModel::appendToLog(const QUuid &jobId, const QString &line) } } -const QStringList &ProgressModel::getLogFile(const QModelIndex &index) +const QStringList &ProgressModel::getLogFile(const QModelIndex &index) const { if(index.row() < m_jobList.count()) { QUuid id = m_jobList.at(index.row()); - return m_jobLogFile[id]; + QHash::const_iterator iter = m_jobLogFile.constFind(id); + if(iter != m_jobLogFile.constEnd()) { return iter.value(); } } - return *(reinterpret_cast(NULL)); + return m_emptyList; } const QUuid &ProgressModel::getJobId(const QModelIndex &index) const @@ -195,7 +198,7 @@ const QUuid &ProgressModel::getJobId(const QModelIndex &index) const return m_jobList.at(index.row()); } - return *(reinterpret_cast(NULL)); + return m_emptyUuid; } const ProgressModel::JobState ProgressModel::getJobState(const QModelIndex &index) const @@ -205,7 +208,7 @@ const ProgressModel::JobState ProgressModel::getJobState(const QModelIndex &inde return static_cast(m_jobState.value(m_jobList.at(index.row()), -1)); } - return static_cast(NULL); + return static_cast(-1); } void ProgressModel::addSystemMessage(const QString &text, int type) diff --git a/src/Model_Progress.h b/src/Model_Progress.h index a2efdcec..9e868774 100644 --- a/src/Model_Progress.h +++ b/src/Model_Progress.h @@ -65,7 +65,7 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; //Public functions - const QStringList &getLogFile(const QModelIndex &index); + const QStringList &getLogFile(const QModelIndex &index) const; const QUuid &getJobId(const QModelIndex &index) const; const JobState getJobState(const QModelIndex &index) const; const QIcon &ProgressModel::getIcon(ProgressModel::JobState state) const; @@ -96,4 +96,7 @@ private: const QIcon m_iconPerformance; const QIcon m_iconSkipped; const QIcon m_iconUndefined; + + const QStringList m_emptyList; + const QUuid m_emptyUuid; };