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
; }
56 void setHighlightRX(int value
) { highlightRX
= value
; }
57 bool isHighlightRX() const { return highlightRX
; }
59 quint16
getFlags() const { return flags
; }
60 void setFlags(const quint16
& value
) { flags
= value
; }
61 void setFlag(const quint16
& flag
, const bool on
= true);
63 bool isCategory() const;
67 QList
<TreeItem
*> childItems
;
68 QVector
<QVariant
> itemData
;
69 TreeItem
* parentItem
;
77 class TreeModel
: public QAbstractItemModel
82 struct MimeHeaderData
{
87 TreeModel(RadioData
* radioData
, QObject
*parent
= 0);
90 virtual QVariant
data(const QModelIndex
&index
, int role
= Qt::DisplayRole
) const Q_DECL_OVERRIDE
;
91 virtual QVariant
headerData(int section
, Qt::Orientation orientation
, int role
= Qt::DisplayRole
) const Q_DECL_OVERRIDE
;
92 virtual bool setData(const QModelIndex
&index
, const QVariant
&value
, int role
= Qt::EditRole
) Q_DECL_OVERRIDE
;
94 virtual QModelIndex
index(int row
, int column
, const QModelIndex
&parent
= QModelIndex()) const Q_DECL_OVERRIDE
;
95 virtual QModelIndex
parent(const QModelIndex
&index
) const Q_DECL_OVERRIDE
;
96 virtual Qt::ItemFlags
flags(const QModelIndex
&index
) const Q_DECL_OVERRIDE
;
98 virtual int rowCount(const QModelIndex
&parent
= QModelIndex()) const Q_DECL_OVERRIDE
;
99 virtual int columnCount(const QModelIndex
&parent
= QModelIndex()) const Q_DECL_OVERRIDE
;
100 virtual bool removeRows(int position
, int rows
, const QModelIndex
&parent
= QModelIndex()) Q_DECL_OVERRIDE
;
101 //virtual bool insertRows(int row, int count, const QModelIndex & parent) Q_DECL_OVERRIDE;
103 virtual QStringList
mimeTypes() const Q_DECL_OVERRIDE
;
104 virtual Qt::DropActions
supportedDropActions() const Q_DECL_OVERRIDE
;
105 virtual Qt::DropActions
supportedDragActions() const Q_DECL_OVERRIDE
;
106 virtual QMimeData
* mimeData(const QModelIndexList
& indexes
) const Q_DECL_OVERRIDE
;
107 virtual bool canDropMimeData(const QMimeData
* data
, Qt::DropAction action
, int row
, int column
, const QModelIndex
& parent
) const Q_DECL_OVERRIDE
;
108 virtual bool dropMimeData(const QMimeData
* data
, Qt::DropAction action
, int row
, int column
, const QModelIndex
& parent
) Q_DECL_OVERRIDE
;
110 void encodeModelsData(const QModelIndexList
& indexes
, QByteArray
* data
) const;
111 void encodeGeneralData(QByteArray
* data
) const;
112 void encodeHeaderData(QByteArray
* data
) const;
113 QMimeData
* getModelsMimeData(const QModelIndexList
& indexes
, QMimeData
* mimeData
= NULL
) const;
114 QMimeData
* getGeneralMimeData(QMimeData
* mimeData
= NULL
) const;
115 QMimeData
* getHeaderMimeData(QMimeData
* mimeData
= NULL
) const;
116 QUuid
getMimeDataSourceId(const QMimeData
* mimeData
) const;
117 bool hasSupportedMimeData(const QMimeData
* mimeData
) const;
118 bool hasModelsMimeData(const QMimeData
* mimeData
) const;
119 bool hasGenralMimeData(const QMimeData
* mimeData
) const;
120 bool hasHeaderMimeData(const QMimeData
* mimeData
) const;
121 bool hasOwnMimeData(const QMimeData
* mimeData
) const;
123 static bool decodeHeaderData(const QMimeData
* mimeData
, MimeHeaderData
* header
);
124 static bool decodeMimeData(const QMimeData
* mimeData
, QVector
<ModelData
> * models
= NULL
, GeneralSettings
* gs
= NULL
, bool * hasGenSet
= NULL
);
125 static int countModelsInMimeData(const QMimeData
* mimeData
);
127 QModelIndex
getIndexForModel(const int modelIndex
, QModelIndex parent
= QModelIndex());
128 QModelIndex
getIndexForCategory(const int categoryIndex
);
129 int getAvailableEEpromSize();
130 int getModelIndex(const QModelIndex
& index
) const;
131 int getCategoryIndex(const QModelIndex
& index
) const;
132 int rowNumber(const QModelIndex
& index
= QModelIndex()) const;
133 bool isCategoryType(const QModelIndex
& index
) const;
134 bool isModelType(const QModelIndex
& index
) const;
137 void markItemForCut(const QModelIndex
& index
, bool on
= true);
138 void markItemsForCut(const QModelIndexList
& indexes
, bool on
= true);
142 void modelsDropped(const QMimeData
* mimeData
, const QModelIndex toRowIdx
, const bool insert
, const bool move
);
143 void modelsRemoved(const QVector
<int> modelIndices
);
144 void refreshRequested();
147 //void onRowsAboutToBeRemoved(const QModelIndex & parent, int first, int last);
148 void onRowsRemoved(const QModelIndex
& parent
, int first
, int last
);
151 TreeItem
* getItem(const QModelIndex
& index
) const;
152 bool isModelIdUnique(unsigned modelId
, unsigned module
, unsigned protocol
);
155 RadioData
* radioData
;
156 int availableEEpromSize
;
157 MimeHeaderData mimeHeaderData
;
161 #endif // _MODELSLIST_H_