report model and view
parent
2db930a5cf
commit
c75563c184
@ -0,0 +1,66 @@
|
||||
|
||||
#include "reportmodel.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
int CSMTools::ReportModel::rowCount (const QModelIndex & parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return mRows.size();
|
||||
}
|
||||
|
||||
int CSMTools::ReportModel::columnCount (const QModelIndex & parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const
|
||||
{
|
||||
if (role!=Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (index.column()==0)
|
||||
return static_cast<int> (mRows.at (index.row()).first.getType());
|
||||
else
|
||||
return mRows.at (index.row()).second.c_str();
|
||||
}
|
||||
|
||||
QVariant CSMTools::ReportModel::headerData (int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role!=Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation==Qt::Vertical)
|
||||
return QVariant();
|
||||
|
||||
return tr (section==0 ? "Type" : "Description");
|
||||
}
|
||||
|
||||
bool CSMTools::ReportModel::removeRows (int row, int count, const QModelIndex& parent)
|
||||
{
|
||||
if (parent.isValid())
|
||||
return false;
|
||||
|
||||
mRows.erase (mRows.begin()+row, mRows.begin()+row+count);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSMTools::ReportModel::add (const std::string& row)
|
||||
{
|
||||
std::string::size_type index = row.find ('|');
|
||||
|
||||
if (index==std::string::npos)
|
||||
throw std::logic_error ("invalid report message");
|
||||
|
||||
beginInsertRows (QModelIndex(), mRows.size(), mRows.size());
|
||||
|
||||
mRows.push_back (std::make_pair (row.substr (0, index), row.substr (index+1)));
|
||||
|
||||
endInsertRows();
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#ifndef CSM_TOOLS_REPORTMODEL_H
|
||||
#define CSM_TOOLS_REPORTMODEL_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
#include "../world/universalid.hpp"
|
||||
|
||||
namespace CSMTools
|
||||
{
|
||||
class ReportModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
std::vector<std::pair<CSMWorld::UniversalId, std::string> > mRows;
|
||||
|
||||
public:
|
||||
|
||||
virtual int rowCount (const QModelIndex & parent = QModelIndex()) const;
|
||||
|
||||
virtual int columnCount (const QModelIndex & parent = QModelIndex()) const;
|
||||
|
||||
virtual QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
|
||||
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
|
||||
virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex());
|
||||
|
||||
void add (const std::string& row);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,25 @@
|
||||
|
||||
#include "reportsubview.hpp"
|
||||
|
||||
#include <QTableView>
|
||||
#include <QHeaderView>
|
||||
|
||||
#include "../../model/tools/reportmodel.hpp"
|
||||
|
||||
CSVTools::ReportSubView::ReportSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
: CSVDoc::SubView (id)
|
||||
{
|
||||
setWidget (mTable = new QTableView (this));
|
||||
mTable->setModel (document.getReport (id));
|
||||
|
||||
mTable->horizontalHeader()->setResizeMode (QHeaderView::Interactive);
|
||||
mTable->verticalHeader()->hide();
|
||||
mTable->setSortingEnabled (true);
|
||||
mTable->setSelectionBehavior (QAbstractItemView::SelectRows);
|
||||
mTable->setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||
}
|
||||
|
||||
void CSVTools::ReportSubView::setEditLock (bool locked)
|
||||
{
|
||||
// ignored. We don't change document state anyway.
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef CSV_TOOLS_REPORTSUBVIEW_H
|
||||
#define CSV_TOOLS_REPORTSUBVIEW_H
|
||||
|
||||
#include "../doc/subview.hpp"
|
||||
|
||||
class QTableView;
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVTools
|
||||
{
|
||||
class Table;
|
||||
|
||||
class ReportSubView : public CSVDoc::SubView
|
||||
{
|
||||
QTableView *mTable;
|
||||
|
||||
public:
|
||||
|
||||
ReportSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
|
||||
virtual void setEditLock (bool locked);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,12 @@
|
||||
|
||||
#include "subviews.hpp"
|
||||
|
||||
#include "../doc/subviewfactoryimp.hpp"
|
||||
|
||||
#include "reportsubview.hpp"
|
||||
|
||||
void CSVTools::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||
{
|
||||
manager.add (CSMWorld::UniversalId::Type_VerificationResults,
|
||||
new CSVDoc::SubViewFactory<ReportSubView>);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
#ifndef CSV_TOOLS_SUBVIEWS_H
|
||||
#define CSV_TOOLS_SUBVIEWS_H
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class SubViewFactoryManager;
|
||||
}
|
||||
|
||||
namespace CSVTools
|
||||
{
|
||||
void addSubViewFactories (CSVDoc::SubViewFactoryManager& manager);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue