Updraft
1.0
Open source glider flight visualisation tool.
|
00001 #ifndef UPDRAFT_SRC_CORE_SETTINGSMODEL_H_ 00002 #define UPDRAFT_SRC_CORE_SETTINGSMODEL_H_ 00003 00004 #include <QtGui> 00005 #include <QtXml/QDomDocument> 00006 00007 namespace Updraft { 00008 namespace Core { 00009 00010 class SettingsModel; 00011 00014 class SettingsItem { 00015 public: 00020 SettingsItem(QDomNode node, SettingsModel* model); 00021 ~SettingsItem(); 00022 00025 void prependChild(SettingsItem* item); 00026 00029 void appendChild(SettingsItem* item); 00030 00035 void insertChild(SettingsItem* item, int index); 00036 00039 SettingsItem* getChild(int index); 00040 00044 int childIndex(SettingsItem* item); 00045 00048 SettingsItem* getParent() { return parent; } 00049 00052 QDomNode getNode() { return domNode; } 00053 00055 int rowCount(); 00056 00058 SettingsModel* getModel() { return myModel; } 00059 00062 void setIcon(QIcon i) { icon = i; } 00063 00066 QIcon getIcon() { return icon; } 00067 00068 private: 00070 QDomNode domNode; 00071 00073 QVector<SettingsItem*> children; 00074 00076 SettingsItem* parent; 00077 00079 SettingsModel* myModel; 00080 00082 QIcon icon; 00083 }; 00084 00086 enum SettingsDataRole { 00087 ValueRole = Qt::EditRole, 00088 DecorationRole = Qt::DecorationRole, 00089 DescriptionRole = Qt::DisplayRole, 00090 NameRole = Qt::UserRole, 00091 DefaultValueRole = Qt::UserRole+1, 00092 NeedsRestartRole = Qt::UserRole+2 00093 }; 00094 00098 class SettingsModel: public QAbstractItemModel { 00099 Q_OBJECT 00100 00101 public: 00102 SettingsModel(); 00103 ~SettingsModel(); 00104 00108 void loadSettings(QString filename); 00109 00112 void saveSettings(QString filename); 00113 00114 00119 int columnCount(const QModelIndex& index) const { return 1; } 00120 00126 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; 00127 00133 QModelIndex index(int row, int column, 00134 const QModelIndex& parent = QModelIndex()) const; 00135 00139 QModelIndex indexFromItem(SettingsItem* item) const; 00140 00145 bool insertRow(int row, const QModelIndex& parent = QModelIndex()); 00146 00150 SettingsItem* itemFromIndex(const QModelIndex& index) const; 00151 00155 QModelIndex parent(const QModelIndex& index) const; 00156 00160 int rowCount(const QModelIndex& parent = QModelIndex()) const; 00161 00167 bool setData(const QModelIndex& index, const QVariant& value, 00168 int role = Qt::DisplayRole); 00169 00175 QModelIndex sibling(int row, int column, const QModelIndex& index) const; 00176 00177 signals: 00180 void itemChanged(SettingsItem* item); 00181 00182 private: 00187 QString dataRoleToString(int role) const; 00188 00192 void insertRowInternal(int row, SettingsItem* item); 00193 00196 void reinitializeData(); 00197 00199 QDomDocument domDoc; 00200 00202 SettingsItem* rootItem; 00203 }; 00204 00205 } // End namespace Core 00206 } // End namespace Updraft 00207 00208 #endif // UPDRAFT_SRC_CORE_SETTINGSMODEL_H_ 00209