1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 05:53:54 +00:00
openmw/apps/opencs/model/world/idtableproxymodel.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
1.9 KiB
C++
Raw Normal View History

#ifndef CSM_WOLRD_IDTABLEPROXYMODEL_H
#define CSM_WOLRD_IDTABLEPROXYMODEL_H
#include <map>
2022-10-19 17:02:00 +00:00
#include <memory>
#include <string>
#include <utility>
#include <vector>
2022-10-19 17:02:00 +00:00
#include <QModelIndex>
#include <QSortFilterProxyModel>
2022-10-19 17:02:00 +00:00
#include <QString>
#include "columns.hpp"
2022-10-19 17:02:00 +00:00
class QObject;
namespace CSMFilter
{
class Node;
}
namespace CSMWorld
{
2022-10-19 17:02:00 +00:00
class IdTableBase;
class IdTableProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
std::shared_ptr<CSMFilter::Node> mFilter;
std::map<int, int> mColumnMap; // column ID, column index in this model (or -1)
// Cache of enum values for enum columns (e.g. Modified, Record Type).
// Used to speed up comparisons during the sort by such columns.
typedef std::map<Columns::ColumnId, std::vector<std::pair<int, std::string>>> EnumColumnCache;
mutable EnumColumnCache mEnumColumnCache;
protected:
IdTableBase* mSourceModel;
2022-09-22 18:26:05 +00:00
private:
void updateColumnMap();
public:
IdTableProxyModel(QObject* parent = nullptr);
virtual QModelIndex getModelIndex(const std::string& id, int column) const;
void setSourceModel(QAbstractItemModel* model) override;
2020-11-13 07:39:47 +00:00
void setFilter(const std::shared_ptr<CSMFilter::Node>& filter);
void refreshFilter();
protected:
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
QString getRecordId(int sourceRow) const;
protected slots:
virtual void sourceRowsInserted(const QModelIndex& parent, int start, int end);
virtual void sourceRowsRemoved(const QModelIndex& parent, int start, int end);
virtual void sourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
signals:
void rowAdded(const std::string& id);
};
}
#endif