From e8091c4e7e21964187d8edd50c5d45685629c7bb Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 29 Mar 2015 15:28:31 +0200 Subject: [PATCH] added field column to report table --- apps/opencs/model/tools/reportmodel.cpp | 51 ++++++++++++++++++++++--- apps/opencs/model/tools/reportmodel.hpp | 9 ++++- apps/opencs/model/tools/search.cpp | 6 ++- apps/opencs/model/tools/tools.cpp | 2 +- 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/apps/opencs/model/tools/reportmodel.cpp b/apps/opencs/model/tools/reportmodel.cpp index 218f391c9..627199c22 100644 --- a/apps/opencs/model/tools/reportmodel.cpp +++ b/apps/opencs/model/tools/reportmodel.cpp @@ -2,12 +2,29 @@ #include "reportmodel.hpp" #include +#include + +#include "../world/columns.hpp" CSMTools::ReportModel::Line::Line (const CSMWorld::UniversalId& id, const std::string& message, const std::string& hint) : mId (id), mMessage (message), mHint (hint) {} +CSMTools::ReportModel::ReportModel (bool fieldColumn) +{ + if (fieldColumn) + { + mColumnField = 3; + mColumnDescription = 4; + } + else + { + mColumnDescription = 3; + + mColumnField = -1; + } +} int CSMTools::ReportModel::rowCount (const QModelIndex & parent) const { @@ -22,7 +39,7 @@ int CSMTools::ReportModel::columnCount (const QModelIndex & parent) const if (parent.isValid()) return 0; - return 4; + return mColumnDescription+1; } QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const @@ -46,15 +63,32 @@ QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const return QString ("-"); } - case Column_Description: - - return QString::fromUtf8 (mRows.at (index.row()).mMessage.c_str()); - case Column_Hint: return QString::fromUtf8 (mRows.at (index.row()).mHint.c_str()); } + if (index.column()==mColumnDescription) + return QString::fromUtf8 (mRows.at (index.row()).mMessage.c_str()); + + if (index.column()==mColumnField) + { + std::string field; + + std::istringstream stream (mRows.at (index.row()).mHint); + + char type, ignore; + int fieldIndex; + + if ((stream >> type >> ignore >> fieldIndex) && type=='r') + { + field = CSMWorld::Columns::getName ( + static_cast (fieldIndex)); + } + + return QString::fromUtf8 (field.c_str()); + } + return QVariant(); } @@ -70,9 +104,14 @@ QVariant CSMTools::ReportModel::headerData (int section, Qt::Orientation orienta { case Column_Type: return "Type"; case Column_Id: return "ID"; - case Column_Description: return "Description"; } + if (section==mColumnDescription) + return "Description"; + + if (section==mColumnField) + return "Field"; + return "-"; } diff --git a/apps/opencs/model/tools/reportmodel.hpp b/apps/opencs/model/tools/reportmodel.hpp index 5f39316aa..7e733fab6 100644 --- a/apps/opencs/model/tools/reportmodel.hpp +++ b/apps/opencs/model/tools/reportmodel.hpp @@ -26,13 +26,20 @@ namespace CSMTools std::vector mRows; + // Fixed columns enum Columns { - Column_Type = 0, Column_Id = 1, Column_Hint = 2, Column_Description = 3 + Column_Type = 0, Column_Id = 1, Column_Hint = 2 }; + // Configurable columns + int mColumnDescription; + int mColumnField; + public: + ReportModel (bool fieldColumn = false); + virtual int rowCount (const QModelIndex & parent = QModelIndex()) const; virtual int columnCount (const QModelIndex & parent = QModelIndex()) const; diff --git a/apps/opencs/model/tools/search.cpp b/apps/opencs/model/tools/search.cpp index 2d3e4f952..a0eb429b0 100644 --- a/apps/opencs/model/tools/search.cpp +++ b/apps/opencs/model/tools/search.cpp @@ -27,7 +27,11 @@ void CSMTools::Search::searchTextCell (const CSMWorld::IdTableBase *model, message << getLocation (model, index, id) << text.mid (pos).toUtf8().data(); std::ostringstream hint; - hint << "r: " << index.column() << " " << pos << " " << search.length(); + hint + << "r: " + << model->getColumnId (index.column()) + << " " << pos + << " " << search.length(); messages.add (id, message.str(), hint.str()); diff --git a/apps/opencs/model/tools/tools.cpp b/apps/opencs/model/tools/tools.cpp index 957e20296..970a8ac4f 100644 --- a/apps/opencs/model/tools/tools.cpp +++ b/apps/opencs/model/tools/tools.cpp @@ -147,7 +147,7 @@ CSMWorld::UniversalId CSMTools::Tools::runVerifier() CSMWorld::UniversalId CSMTools::Tools::newSearch() { - mReports.insert (std::make_pair (mNextReportNumber++, new ReportModel)); + mReports.insert (std::make_pair (mNextReportNumber++, new ReportModel (true))); return CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Search, mNextReportNumber-1); }