5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _MODELSLIST_H_
22 #define _MODELSLIST_H_
24 #include "eeprominterface.h"
25 #include <QAbstractItemModel>
32 enum TreeItemFlags
{ MarkedForCut
= 0x01 };
34 explicit TreeItem(const QVector
<QVariant
> & itemData
);
35 explicit TreeItem(TreeItem
* parent
, int categoryIndex
, int modelIndex
);
38 TreeItem
* child(int number
);
39 int childCount() const;
40 int columnCount() const;
41 QVariant
data(int column
) const;
42 TreeItem
* appendChild(int categoryIndex
, int modelIndex
);
43 TreeItem
* insertChild(const int row
, int categoryIndex
, int modelIndex
);
44 bool removeChildren(int position
, int count
);
45 bool insertChildren(int row
, int count
);
47 int childNumber() const;
48 bool setData(int column
, const QVariant
&value
);
50 TreeItem
* parent() { return parentItem
; }
51 void setParent(TreeItem
* p
) { parentItem
= p
; }
52 int getModelIndex() const { return modelIndex
; }
53 void setModelIndex(int value
) { modelIndex
= value
; }
54 int getCategoryIndex() const { return categoryIndex
; }
55 void setCategoryIndex(int value
) { categoryIndex
= value
; }
57 quint16
getFlags() const { return flags
; }
58 void setFlags(const quint16
& value
) { flags
= value
; }
59 void setFlag(const quint16
& flag
, const bool on
= true);
61 bool isCategory() const;
65 QList
<TreeItem
*> childItems
;
66 QVector
<QVariant
> itemData
;
67 TreeItem
* parentItem
;
74 class TreeModel
: public QAbstractItemModel
79 struct MimeHeaderData
{
84 TreeModel(RadioData
* radioData
, QObject
*parent
= 0);
87 virtual QVariant
data(const QModelIndex
&index
, int role
= Qt::DisplayRole
) const Q_DECL_OVERRIDE
;
88 virtual QVariant
headerData(int section
, Qt::Orientation orientation
, int role
= Qt::DisplayRole
) const Q_DECL_OVERRIDE
;
89 virtual bool setData(const QModelIndex
&index
, const QVariant
&value
, int role
= Qt::EditRole
) Q_DECL_OVERRIDE
;
91 virtual QModelIndex
index(int row
, int column
, const QModelIndex
&parent
= QModelIndex()) const Q_DECL_OVERRIDE
;
92 virtual QModelIndex
parent(const QModelIndex
&index
) const Q_DECL_OVERRIDE
;
93 virtual Qt::ItemFlags
flags(const QModelIndex
&index
) const Q_DECL_OVERRIDE
;
95 virtual int rowCount(const QModelIndex
&parent
= QModelIndex()) const Q_DECL_OVERRIDE
;
96 virtual int columnCount(const QModelIndex
&parent
= QModelIndex()) const Q_DECL_OVERRIDE
;
97 virtual bool removeRows(int position
, int rows
, const QModelIndex
&parent
= QModelIndex()) Q_DECL_OVERRIDE
;
98 //virtual bool insertRows(int row, int count, const QModelIndex & parent) Q_DECL_OVERRIDE;
100 virtual QStringList
mimeTypes() const Q_DECL_OVERRIDE
;
101 virtual Qt::DropActions
supportedDropActions() const Q_DECL_OVERRIDE
;
102 virtual Qt::DropActions
supportedDragActions() const Q_DECL_OVERRIDE
;
103 virtual QMimeData
* mimeData(const QModelIndexList
& indexes
) const Q_DECL_OVERRIDE
;
104 virtual bool canDropMimeData(const QMimeData
* data
, Qt::DropAction action
, int row
, int column
, const QModelIndex
& parent
) const Q_DECL_OVERRIDE
;
105 virtual bool dropMimeData(const QMimeData
* data
, Qt::DropAction action
, int row
, int column
, const QModelIndex
& parent
) Q_DECL_OVERRIDE
;
107 void encodeModelsData(const QModelIndexList
& indexes
, QByteArray
* data
) const;
108 void encodeGeneralData(QByteArray
* data
) const;
109 void encodeHeaderData(QByteArray
* data
) const;
110 QMimeData
* getModelsMimeData(const QModelIndexList
& indexes
, QMimeData
* mimeData
= NULL
) const;
111 QMimeData
* getGeneralMimeData(QMimeData
* mimeData
= NULL
) const;
112 QMimeData
* getHeaderMimeData(QMimeData
* mimeData
= NULL
) const;
113 QUuid
getMimeDataSourceId(const QMimeData
* mimeData
) const;
114 bool hasSupportedMimeData(const QMimeData
* mimeData
) const;
115 bool hasModelsMimeData(const QMimeData
* mimeData
) const;
116 bool hasGenralMimeData(const QMimeData
* mimeData
) const;
117 bool hasHeaderMimeData(const QMimeData
* mimeData
) const;
118 bool hasOwnMimeData(const QMimeData
* mimeData
) const;
120 static bool decodeHeaderData(const QMimeData
* mimeData
, MimeHeaderData
* header
);
121 static bool decodeMimeData(const QMimeData
* mimeData
, QVector
<ModelData
> * models
= NULL
, GeneralSettings
* gs
= NULL
, bool * hasGenSet
= NULL
);
122 static int countModelsInMimeData(const QMimeData
* mimeData
);
124 QModelIndex
getIndexForModel(const int modelIndex
, QModelIndex parent
= QModelIndex());
125 QModelIndex
getIndexForCategory(const int categoryIndex
);
126 int getAvailableEEpromSize();
127 int getModelIndex(const QModelIndex
& index
) const;
128 int getCategoryIndex(const QModelIndex
& index
) const;
129 int rowNumber(const QModelIndex
& index
= QModelIndex()) const;
130 bool isCategoryType(const QModelIndex
& index
) const;
131 bool isModelType(const QModelIndex
& index
) const;
134 void markItemForCut(const QModelIndex
& index
, bool on
= true);
135 void markItemsForCut(const QModelIndexList
& indexes
, bool on
= true);
139 void modelsDropped(const QMimeData
* mimeData
, const QModelIndex toRowIdx
, const bool insert
, const bool move
);
140 void modelsRemoved(const QVector
<int> modelIndices
);
141 void refreshRequested();
144 //void onRowsAboutToBeRemoved(const QModelIndex & parent, int first, int last);
145 void onRowsRemoved(const QModelIndex
& parent
, int first
, int last
);
148 TreeItem
* getItem(const QModelIndex
& index
) const;
151 RadioData
* radioData
;
152 int availableEEpromSize
;
153 MimeHeaderData mimeHeaderData
;
156 #endif // _MODELSLIST_H_