Warning, file /rolisteam/rolisteam/src/libraries/rwidgets/gmtoolbox/UnitConvertor/unitmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #ifndef UNITMODEL_H 0002 #define UNITMODEL_H 0003 0004 #include "rwidgets_global.h" 0005 #include "unit.h" 0006 #include <QAbstractListModel> 0007 #include <QSortFilterProxyModel> 0008 0009 namespace GMTOOL 0010 { 0011 class RWIDGET_EXPORT CategoryModel : public QSortFilterProxyModel 0012 { 0013 Q_OBJECT 0014 public: 0015 CategoryModel(QObject* parent= nullptr); 0016 0017 QString currentCategory() const; 0018 virtual void setCurrentCategory(const QString& currentCategory); 0019 0020 void addUnit(Unit*); 0021 0022 protected: 0023 bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const Q_DECL_OVERRIDE; 0024 QString m_currentCategory; 0025 }; 0026 0027 class RWIDGET_EXPORT UnitModel : public QAbstractListModel 0028 { 0029 Q_OBJECT 0030 public: 0031 enum Role 0032 { 0033 Category= Qt::UserRole, 0034 UnitRole 0035 }; 0036 UnitModel(QObject* parent= nullptr); 0037 0038 QVariant data(const QModelIndex& index, int role) const; 0039 int rowCount(const QModelIndex& parent= QModelIndex()) const; 0040 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 0041 0042 Unit* insertData(Unit* unit); 0043 Unit* getUnitFromIndex(const QModelIndex& i, int currentCat); 0044 0045 QHash<Unit::Category, QString> cat2Text() const; 0046 void setCat2Text(const QHash<Unit::Category, QString>& cat2Text); 0047 0048 QString getCatNameFromId(Unit::Category) const; 0049 0050 void readSettings(); 0051 void writeSettings(); 0052 0053 int getIndex(Unit* unit); 0054 Unit* getUnitByIndex(int i) const; 0055 0056 // Add data: 0057 bool insertUnit(Unit::Category cat); 0058 0059 // Remove data: 0060 bool removeUnit(const QModelIndex& index); 0061 0062 signals: 0063 void modelChanged(); 0064 0065 protected: 0066 Unit* indexToUnit(const QModelIndex& index) const; 0067 0068 private: 0069 QMap<Unit::Category, QList<Unit*>> m_data; 0070 static QHash<Unit::Category, QString> m_cat2Text; 0071 }; 0072 } // namespace GMTOOL 0073 #endif // UNITMODEL_H