Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210#include "reportmodel.hpp"
#include <algorithm>#include <memory>#include <sstream>#include <stdexcept>
#include <apps/opencs/model/doc/messages.hpp>#include <apps/opencs/model/world/universalid.hpp>
#include "../world/columns.hpp"
CSMTools::ReportModel::ReportModel(bool fieldColumn, bool severityColumn) : mColumnField(-1) , mColumnSeverity(-1){ int index = 3;
if (severityColumn) mColumnSeverity = index++;
if (fieldColumn) mColumnField = index++;
mColumnDescription = index;}
int CSMTools::ReportModel::rowCount(const QModelIndex& parent) const{ if (parent.isValid()) return 0;
return static_cast<int>(mRows.size());}
int CSMTools::ReportModel::columnCount(const QModelIndex& parent) const{ if (parent.isValid()) return 0;
return mColumnDescription + 1;}
QVariant CSMTools::ReportModel::data(const QModelIndex& index, int role) const{ if (role != Qt::DisplayRole && role != Qt::UserRole) return QVariant();
switch (index.column()) { case Column_Type:
if (role == Qt::UserRole) return QString::fromUtf8(mRows.at(index.row()).mId.getTypeName().c_str()); else return static_cast<int>(mRows.at(index.row()).mId.getType());
case Column_Id: { CSMWorld::UniversalId id = mRows.at(index.row()).mId;
switch (id.getArgumentType()) { case CSMWorld::UniversalId::ArgumentType_None: return QString("-"); case CSMWorld::UniversalId::ArgumentType_Index: return QString::number(id.getIndex()); case CSMWorld::UniversalId::ArgumentType_Id: return QString::fromStdString(id.getId()); case CSMWorld::UniversalId::ArgumentType_RefId: return QString::fromStdString(id.getRefId().toString()); }
return QString("unsupported"); }
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' || type == 'R')) { field = CSMWorld::Columns::getName(static_cast<CSMWorld::Columns::ColumnId>(fieldIndex)); }
return QString::fromUtf8(field.c_str()); }
if (index.column() == mColumnSeverity) { return QString::fromUtf8(CSMDoc::Message::toString(mRows.at(index.row()).mSeverity).c_str()); }
return QVariant();}
QVariant CSMTools::ReportModel::headerData(int section, Qt::Orientation orientation, int role) const{ if (role != Qt::DisplayRole) return QVariant();
if (orientation == Qt::Vertical) return QVariant();
switch (section) { case Column_Type: return "Type"; case Column_Id: return "ID"; }
if (section == mColumnDescription) return "Description";
if (section == mColumnField) return "Field";
if (section == mColumnSeverity) return "Severity";
return "-";}
bool CSMTools::ReportModel::removeRows(int row, int count, const QModelIndex& parent){ if (parent.isValid()) return false;
if (count > 0) { beginRemoveRows(parent, row, row + count - 1);
mRows.erase(mRows.begin() + row, mRows.begin() + row + count);
endRemoveRows(); }
return true;}
void CSMTools::ReportModel::add(const CSMDoc::Message& message){ beginInsertRows(QModelIndex(), static_cast<int>(mRows.size()), static_cast<int>(mRows.size()));
mRows.push_back(message);
endInsertRows();}
void CSMTools::ReportModel::flagAsReplaced(int index){ CSMDoc::Message& line = mRows.at(index); std::string hint = line.mHint;
if (hint.empty() || hint[0] != 'R') throw std::logic_error("trying to flag message as replaced that is not replaceable");
hint[0] = 'r';
line.mHint = std::move(hint);
emit dataChanged(this->index(index, 0), this->index(index, columnCount()));}
const CSMWorld::UniversalId& CSMTools::ReportModel::getUniversalId(int row) const{ return mRows.at(row).mId;}
std::string CSMTools::ReportModel::getHint(int row) const{ return mRows.at(row).mHint;}
void CSMTools::ReportModel::clear(){ if (!mRows.empty()) { beginRemoveRows(QModelIndex(), 0, static_cast<int>(mRows.size()) - 1); mRows.clear(); endRemoveRows(); }}
int CSMTools::ReportModel::countErrors() const{ int count = 0;
for (std::vector<CSMDoc::Message>::const_iterator iter(mRows.begin()); iter != mRows.end(); ++iter) if (iter->mSeverity == CSMDoc::Message::Severity_Error || iter->mSeverity == CSMDoc::Message::Severity_SeriousError) ++count;
return count;}