1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

added field column to report table

This commit is contained in:
Marc Zinnschlag 2015-03-29 15:28:31 +02:00
parent 416b8165cd
commit e8091c4e7e
4 changed files with 59 additions and 9 deletions

View File

@ -2,12 +2,29 @@
#include "reportmodel.hpp"
#include <stdexcept>
#include <sstream>
#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<CSMWorld::Columns::ColumnId> (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 "-";
}

View File

@ -26,13 +26,20 @@ namespace CSMTools
std::vector<Line> 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;

View File

@ -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());

View File

@ -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);
}