~ubuntu-branches/ubuntu/precise/kdewebdev-kde4/precise

1.1.5 by Jonathan Riddell
Import upstream version 4.0.83
1
/**
2
 *
3
 *  This file is part of the kxsldbg package
4
 *  Copyright (c) 2008 Keith Isdale <keith@kdewebdev.org>
5
 *
6
 *  This library is free software; you can redistribute it and/or
7
 *  This library is free software; you can redistribute it and/or 
8
 *  modify it under the terms of the GNU General Public License as 
9
 *  published by the Free Software Foundation; either version 2 of 
10
 *  the License, or (at your option) any later version.
11
 *  This library is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 *  Library General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU Library General Public License
17
 *  along with this library; see the file COPYING.LIB.  If not, write to
18
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
 *  Boston, MA 02110-1301, USA.
20
 **/
21
22
23
24
#ifndef XSLDBGSETTINGSMODEL_H
25
#define XSLDBGSETTINGSMODEL_H
26
27
#include <QVariant>
28
#include <QStringList>
29
#include <QAbstractTableModel>
30
#include <QHash>
31
#include <QMutex>
32
#include "kconfiggroup.h"
33
34
class XsldbgSettingsModelPrivate;
35
36
class XsldbgSettingData
37
{
38
    public:
39
        XsldbgSettingData();
40
        XsldbgSettingData(const QString & name, const QVariant &value, int row);
41
        XsldbgSettingData(int optionID, const QVariant &value, int row);
42
        XsldbgSettingData & operator=(const XsldbgSettingData & other);
43
44
        QString m_name;
45
        QVariant m_value;
46
        int m_type;
47
        int m_id;
48
        int m_row;
49
        static QString myKey(const QString &name, int type);
50
};
51
52
typedef QHash<QString, XsldbgSettingData>::iterator XsldbgSettingDataIterator;
53
typedef QHash<QString, XsldbgSettingData>::const_iterator XsldbgSettingDataConstIterator;
54
QDebug operator<< ( QDebug stream, const XsldbgSettingData &item);
55
56
57
/**
58
 * class XsldbgSettingsModel
59
 */
60
61
class XsldbgSettingsModel : public QAbstractTableModel
62
{
63
    public:
64
65
        enum SettingsType {
66
            UnknownSettingType = -1,
67
            BoolSettingType = 1,
68
            IntSettingType = 2,
69
            StringSettingType = 4,
70
            ParamSettingType = 8,
71
            HiddenSettingType = 16,
72
            VisibleSettingType = BoolSettingType | IntSettingType | StringSettingType | ParamSettingType,
73
            AnySimpleSettingType = BoolSettingType | IntSettingType | StringSettingType | HiddenSettingType,
74
            AnySettingType = BoolSettingType | IntSettingType | StringSettingType | ParamSettingType | HiddenSettingType
75
        };
76
77
        enum SortType {
78
            SortNone,
79
            SortById = 1,
80
            SortByName 
81
        };
82
83
        static const int SettingTypeRole = Qt::UserRole + 2;
84
        static const int SettingNameRole = Qt::UserRole + 3;
85
        static const int SettingValueRole = Qt::UserRole + 4;
86
        static const int SettingIDRole = Qt::UserRole + 5;
87
88
        /**
89
         * Empty Constructor
90
         */
91
        XsldbgSettingsModel();
92
93
        // perform setup of the settings, reverting to a pristine state
94
        void init();
95
96
        /**
97
         * Empty Destructor
98
         */
99
        virtual ~XsldbgSettingsModel();
100
101
        /**
102
         * Sets the role data for the item at index to value. Returns true if successful;
103
         * otherwise returns false.
104
         * @return Sets the role data for the item at index to value. Returns true if successful;
105
         * otherwise returns false.
106
         * @param  index
107
         * @param  value
108
         * @param  role
109
         */
110
        bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
111
112
113
        /**
114
         * Returns the data stored under the given role for the item referred to by the
115
         * index.
116
         * @return Returns the data stored under the given role for the item referred to by the 
117
         * index
118
         * @param  index
119
         * @param  role
120
         */
121
        QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
122
123
124
        /**
125
         * Returns the number of columns for the children of the given parent. When the
126
         * parent is valid it means that rowCount is returning the number of children of
127
         * parent.
128
         * @return Returns the number of columns for the children of the given parent. When the
129
         * parent is valid it means that rowCount is returning the number of children of
130
         * parent 
131
         * @param  parent
132
         */
133
        int columnCount(const QModelIndex & parent = QModelIndex()) const;
134
135
136
        /**
137
         * Returns the number of rows under the given parent. When the parent is valid it
138
         * means that rowCount is returning the number of children of parent.
139
         * @return  Returns the number of rows under the given parent. When the parent is valid it
140
         * means that rowCount is returning the number of children of parent.
141
         * @param  parent
142
         */
143
        int rowCount(const QModelIndex & parent = QModelIndex()) const;
144
145
146
        /**
1.1.10 by Jonathan Thomas
Import upstream version 4.1.80
147
         * Add a XSLT parameter
148
         * @return Returns true if able to add XSLT parameter with name @a name and value @a value
1.1.5 by Jonathan Riddell
Import upstream version 4.0.83
149
         *            otherwise return false
150
         * @param  name
151
         * @param  value
152
         */
153
        bool addParameter(const QString & name, const QVariant & value);
154
155
        /**
156
         * Remove a XSLT parameter
157
         */
158
        bool removeParameter(const QString & name);
159
160
        void removeAllParameters();
161
162
        /**
163
         * Return a list of setting name that match type requested
164
         * @return Return a list of setting name that match type requested
165
         * @param  settingtype
166
         * @param  sortType what sorting is required, if non required
167
         */
168
        QStringList settingsList(SettingsType settingType, SortType sortType=SortNone) const;
169
170
171
        /**
172
         * Returns true if able to find the item named @a name that matches type @a settingType and 
173
         *  sets outItem to the value of item found otherwise false
174
         * @return Returns true if able to find the item named @a name that matches type @a type and 
175
         *  sets outItem to the value of item found otherwise false
176
         * @param name
177
         * @param settingType
178
         * @param outItem
179
         */
180
        bool findSetting(const QString & name, SettingsType settingType, XsldbgSettingData &outItem) const;
181
182
183
        /**
184
         * Returns true if able to find the item with optionID @a optionID and 
185
         *  sets outItem to the value of item found otherwise false
186
         * @returns Returns true if able to find the item with optionID @a optionID and 
187
         *  sets outItem to the value of item found otherwise false
188
         * @param optionID
189
         * @param outItem
190
         */
191
        bool findSetting(int optionID, XsldbgSettingData &outItem) const;
192
193
194
        int  findModelRow(int optionID, bool isParameter=false) const;
195
196
197
        bool updateSetting(int optionID, QVariant & value);
198
199
200
        /**
201
         * Return true if able to save settings to supplied configGroup
202
         * @return bool
203
         * @param  configGroup
204
         */
205
        bool saveSettings (KConfigGroup & configGroup ) const;
206
207
208
        /**
209
         * Return true if able to loadsettings from supplied configGroup
210
         * @return bool
211
         * @param  configGroup
212
         */
213
        bool loadSettings (const KConfigGroup & configGroup );
214
215
        void lock(bool lockState);
216
217
    private:
218
        XsldbgSettingsModelPrivate *d_ptr;
219
        QString optionPrefix;
220
        QString paramPrefix;
221
        QMutex mutext;
222
};
223
224
#endif // XSLDBGSETTINGSMODEL_H