1 #ifndef CONTENTMODEL_HPP 2 #define CONTENTMODEL_HPP 3 4 #include <QAbstractTableModel> 5 #include <QStringList> 6 #include <QSet> 7 #include <QIcon> 8 #include "loadordererror.hpp" 9 10 namespace ContentSelectorModel 11 { 12 class EsmFile; 13 14 typedef QList<EsmFile *> ContentFileList; 15 16 enum ContentType 17 { 18 ContentType_GameFile, 19 ContentType_Addon 20 }; 21 22 class ContentModel : public QAbstractTableModel 23 { 24 Q_OBJECT 25 public: 26 explicit ContentModel(QObject *parent, QIcon warningIcon); 27 ~ContentModel(); 28 29 void setEncoding(const QString &encoding); 30 31 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 32 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 33 34 QVariant data(const QModelIndex &index, int role) const override; 35 Qt::ItemFlags flags(const QModelIndex &index) const override; 36 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 37 38 bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override; 39 bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override; 40 41 Qt::DropActions supportedDropActions() const override; 42 QStringList mimeTypes() const override; 43 QMimeData *mimeData(const QModelIndexList &indexes) const override; 44 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 45 46 void addFiles(const QString &path); 47 void clearFiles(); 48 49 QModelIndex indexFromItem(const EsmFile *item) const; 50 const EsmFile *item(const QString &name) const; 51 const EsmFile *item(int row) const; 52 EsmFile *item(int row); 53 QStringList gameFiles() const; 54 55 bool isEnabled (QModelIndex index) const; 56 bool isChecked(const QString &filepath) const; 57 bool setCheckState(const QString &filepath, bool isChecked); 58 void setContentList(const QStringList &fileList); 59 ContentFileList checkedItems() const; 60 void uncheckAll(); 61 62 void refreshModel(); 63 64 /// Checks all plug-ins for load order errors and updates mPluginsWithLoadOrderError with plug-ins with issues 65 void checkForLoadOrderErrors(); 66 67 private: 68 69 void addFile(EsmFile *file); 70 71 void sortFiles(); 72 73 /// Checks a specific plug-in for load order errors 74 /// \return all errors found for specific plug-in 75 QList<LoadOrderError> checkForLoadOrderErrors(const EsmFile *file, int row) const; 76 77 /// \return true if plug-in has a Load Order error 78 bool isLoadOrderError(const EsmFile *file) const; 79 80 QString toolTip(const EsmFile *file) const; 81 82 ContentFileList mFiles; 83 QHash<QString, Qt::CheckState> mCheckStates; 84 QSet<QString> mPluginsWithLoadOrderError; 85 QString mEncoding; 86 QIcon mWarningIcon; 87 88 public: 89 90 QString mMimeType; 91 QStringList mMimeTypes; 92 int mColumnCount; 93 Qt::DropActions mDropActions; 94 }; 95 } 96 #endif // CONTENTMODEL_HPP 97