OpenMW
components/contentselector/model/contentmodel.hpp
Go to the documentation of this file.
00001 #ifndef CONTENTMODEL_HPP
00002 #define CONTENTMODEL_HPP
00003 
00004 #include <QAbstractTableModel>
00005 #include <QStringList>
00006 
00007 namespace ContentSelectorModel
00008 {
00009     class EsmFile;
00010 
00011     typedef QList<EsmFile *> ContentFileList;
00012 
00013     enum ContentType
00014     {
00015         ContentType_GameFile,
00016         ContentType_Addon
00017     };
00018 
00019     class ContentModel : public QAbstractTableModel
00020     {
00021         Q_OBJECT
00022     public:
00023         explicit ContentModel(QObject *parent = 0);
00024 
00025         void setEncoding(const QString &encoding);
00026 
00027         int rowCount(const QModelIndex &parent = QModelIndex()) const;
00028         int columnCount(const QModelIndex &parent = QModelIndex()) const;
00029 
00030         QVariant data(const QModelIndex &index, int role) const;
00031         Qt::ItemFlags flags(const QModelIndex &index) const;
00032         bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00033 
00034         bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex());
00035         bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex());
00036 
00037         Qt::DropActions supportedDropActions() const;
00038         QStringList mimeTypes() const;
00039         QMimeData *mimeData(const QModelIndexList &indexes) const;
00040         bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
00041 
00042         void addFiles(const QString &path);
00043 
00044         QModelIndex indexFromItem(const EsmFile *item) const;
00045         const EsmFile *item(const QString &name) const;
00046 
00047         bool isEnabled (QModelIndex index) const;
00048         bool isChecked(const QString &name) const;
00049         bool setCheckState(const QString &name, bool isChecked);
00050         void setCheckStates (const QStringList &fileList, bool isChecked);
00051         ContentFileList checkedItems() const;
00052         void uncheckAll();
00053 
00054         void refreshModel();
00055 
00056     private:
00057 
00058         void addFile(EsmFile *file);
00059         const EsmFile *item(int row) const;
00060         EsmFile *item(int row);
00061 
00062         void sortFiles();
00063 
00064         ContentFileList mFiles;
00065         QHash<QString, Qt::CheckState> mCheckStates;
00066         QTextCodec *mCodec;
00067 
00068     public:
00069 
00070         QString mMimeType;
00071         QStringList mMimeTypes;
00072         int mColumnCount;
00073         Qt::ItemFlags mDragDropFlags;
00074         Qt::DropActions mDropActions;
00075     };
00076 }
00077 #endif // CONTENTMODEL_HPP