Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | class QUndoModel : public QAbstractItemModel | - |
8 | { | - |
9 | public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; | - |
10 | public: | - |
11 | QUndoModel(QObject *parent = 0); | - |
12 | | - |
13 | QUndoStack *stack() const; | - |
14 | | - |
15 | virtual QModelIndex index(int row, int column, | - |
16 | const QModelIndex &parent = QModelIndex()) const; | - |
17 | virtual QModelIndex parent(const QModelIndex &child) const; | - |
18 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; | - |
19 | virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; | - |
20 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | - |
21 | | - |
22 | QModelIndex selectedIndex() const; | - |
23 | QItemSelectionModel *selectionModel() const; | - |
24 | | - |
25 | QString emptyLabel() const; | - |
26 | void setEmptyLabel(const QString &label); | - |
27 | | - |
28 | void setCleanIcon(const QIcon &icon); | - |
29 | QIcon cleanIcon() const; | - |
30 | | - |
31 | public : | - |
32 | void setStack(QUndoStack *stack); | - |
33 | | - |
34 | private : | - |
35 | void stackChanged(); | - |
36 | void stackDestroyed(QObject *obj); | - |
37 | void setStackCurrentIndex(const QModelIndex &index); | - |
38 | | - |
39 | private: | - |
40 | QUndoStack *m_stack; | - |
41 | QItemSelectionModel *m_sel_model; | - |
42 | QString m_emty_label; | - |
43 | QIcon m_clean_icon; | - |
44 | }; | - |
45 | | - |
46 | QUndoModel::QUndoModel(QObject *parent) | - |
47 | : QAbstractItemModel(parent) | - |
48 | { | - |
49 | m_stack = 0; | - |
50 | m_sel_model = new QItemSelectionModel(this, this); | - |
51 | connect(m_sel_model, "2""currentChanged(QModelIndex,QModelIndex)", | - |
52 | this, "1""setStackCurrentIndex(QModelIndex)"); | - |
53 | m_emty_label = tr("<empty>"); | - |
54 | } | 0 |
55 | | - |
56 | QItemSelectionModel *QUndoModel::selectionModel() const | - |
57 | { | - |
58 | return m_sel_model; never executed: return m_sel_model; | 0 |
59 | } | - |
60 | | - |
61 | QUndoStack *QUndoModel::stack() const | - |
62 | { | - |
63 | return m_stack; never executed: return m_stack; | 0 |
64 | } | - |
65 | | - |
66 | void QUndoModel::setStack(QUndoStack *stack) | - |
67 | { | - |
68 | if (m_stack == stack) never evaluated: m_stack == stack | 0 |
69 | return; | 0 |
70 | | - |
71 | if (m_stack != 0) { never evaluated: m_stack != 0 | 0 |
72 | disconnect(m_stack, "2""cleanChanged(bool)", this, "1""stackChanged()"); | - |
73 | disconnect(m_stack, "2""indexChanged(int)", this, "1""stackChanged()"); | - |
74 | disconnect(m_stack, "2""destroyed(QObject*)", this, "1""stackDestroyed(QObject*)"); | - |
75 | } | 0 |
76 | m_stack = stack; | - |
77 | if (m_stack != 0) { never evaluated: m_stack != 0 | 0 |
78 | connect(m_stack, "2""cleanChanged(bool)", this, "1""stackChanged()"); | - |
79 | connect(m_stack, "2""indexChanged(int)", this, "1""stackChanged()"); | - |
80 | connect(m_stack, "2""destroyed(QObject*)", this, "1""stackDestroyed(QObject*)"); | - |
81 | } | 0 |
82 | | - |
83 | stackChanged(); | - |
84 | } | 0 |
85 | | - |
86 | void QUndoModel::stackDestroyed(QObject *obj) | - |
87 | { | - |
88 | if (obj != m_stack) never evaluated: obj != m_stack | 0 |
89 | return; | 0 |
90 | m_stack = 0; | - |
91 | | - |
92 | stackChanged(); | - |
93 | } | 0 |
94 | | - |
95 | void QUndoModel::stackChanged() | - |
96 | { | - |
97 | beginResetModel(); | - |
98 | endResetModel(); | - |
99 | m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect); | - |
100 | } | 0 |
101 | | - |
102 | void QUndoModel::setStackCurrentIndex(const QModelIndex &index) | - |
103 | { | - |
104 | if (m_stack == 0) never evaluated: m_stack == 0 | 0 |
105 | return; | 0 |
106 | | - |
107 | if (index == selectedIndex()) never evaluated: index == selectedIndex() | 0 |
108 | return; | 0 |
109 | | - |
110 | if (index.column() != 0) never evaluated: index.column() != 0 | 0 |
111 | return; | 0 |
112 | | - |
113 | m_stack->setIndex(index.row()); | - |
114 | } | 0 |
115 | | - |
116 | QModelIndex QUndoModel::selectedIndex() const | - |
117 | { | - |
118 | return m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0); never executed: return m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0); | 0 |
119 | } | - |
120 | | - |
121 | QModelIndex QUndoModel::index(int row, int column, const QModelIndex &parent) const | - |
122 | { | - |
123 | if (m_stack == 0) never evaluated: m_stack == 0 | 0 |
124 | return QModelIndex(); never executed: return QModelIndex(); | 0 |
125 | | - |
126 | if (parent.isValid()) never evaluated: parent.isValid() | 0 |
127 | return QModelIndex(); never executed: return QModelIndex(); | 0 |
128 | | - |
129 | if (column != 0) never evaluated: column != 0 | 0 |
130 | return QModelIndex(); never executed: return QModelIndex(); | 0 |
131 | | - |
132 | if (row < 0 || row > m_stack->count()) never evaluated: row > m_stack->count() | 0 |
133 | return QModelIndex(); never executed: return QModelIndex(); | 0 |
134 | | - |
135 | return createIndex(row, column); never executed: return createIndex(row, column); | 0 |
136 | } | - |
137 | | - |
138 | QModelIndex QUndoModel::parent(const QModelIndex&) const | - |
139 | { | - |
140 | return QModelIndex(); never executed: return QModelIndex(); | 0 |
141 | } | - |
142 | | - |
143 | int QUndoModel::rowCount(const QModelIndex &parent) const | - |
144 | { | - |
145 | if (m_stack == 0) never evaluated: m_stack == 0 | 0 |
146 | return 0; never executed: return 0; | 0 |
147 | | - |
148 | if (parent.isValid()) never evaluated: parent.isValid() | 0 |
149 | return 0; never executed: return 0; | 0 |
150 | | - |
151 | return m_stack->count() + 1; never executed: return m_stack->count() + 1; | 0 |
152 | } | - |
153 | | - |
154 | int QUndoModel::columnCount(const QModelIndex&) const | - |
155 | { | - |
156 | return 1; never executed: return 1; | 0 |
157 | } | - |
158 | | - |
159 | QVariant QUndoModel::data(const QModelIndex &index, int role) const | - |
160 | { | - |
161 | if (m_stack == 0) never evaluated: m_stack == 0 | 0 |
162 | return QVariant(); never executed: return QVariant(); | 0 |
163 | | - |
164 | if (index.column() != 0) never evaluated: index.column() != 0 | 0 |
165 | return QVariant(); never executed: return QVariant(); | 0 |
166 | | - |
167 | if (index.row() < 0 || index.row() > m_stack->count()) never evaluated: index.row() < 0 never evaluated: index.row() > m_stack->count() | 0 |
168 | return QVariant(); never executed: return QVariant(); | 0 |
169 | | - |
170 | if (role == Qt::DisplayRole) { never evaluated: role == Qt::DisplayRole | 0 |
171 | if (index.row() == 0) never evaluated: index.row() == 0 | 0 |
172 | return m_emty_label; never executed: return m_emty_label; | 0 |
173 | return m_stack->text(index.row() - 1); never executed: return m_stack->text(index.row() - 1); | 0 |
174 | } else if (role == Qt::DecorationRole) { never evaluated: role == Qt::DecorationRole | 0 |
175 | if (index.row() == m_stack->cleanIndex() && !m_clean_icon.isNull()) never evaluated: index.row() == m_stack->cleanIndex() never evaluated: !m_clean_icon.isNull() | 0 |
176 | return m_clean_icon; never executed: return m_clean_icon; | 0 |
177 | return QVariant(); never executed: return QVariant(); | 0 |
178 | } | - |
179 | | - |
180 | return QVariant(); never executed: return QVariant(); | 0 |
181 | } | - |
182 | | - |
183 | QString QUndoModel::emptyLabel() const | - |
184 | { | - |
185 | return m_emty_label; never executed: return m_emty_label; | 0 |
186 | } | - |
187 | | - |
188 | void QUndoModel::setEmptyLabel(const QString &label) | - |
189 | { | - |
190 | m_emty_label = label; | - |
191 | stackChanged(); | - |
192 | } | 0 |
193 | | - |
194 | void QUndoModel::setCleanIcon(const QIcon &icon) | - |
195 | { | - |
196 | m_clean_icon = icon; | - |
197 | stackChanged(); | - |
198 | } | 0 |
199 | | - |
200 | QIcon QUndoModel::cleanIcon() const | - |
201 | { | - |
202 | return m_clean_icon; never executed: return m_clean_icon; | 0 |
203 | } | - |
204 | class QUndoViewPrivate : public QListViewPrivate | - |
205 | { | - |
206 | inline QUndoView* q_func() { return static_cast<QUndoView *>(q_ptr); } inline const QUndoView* q_func() const { return static_cast<const QUndoView *>(q_ptr); } friend class QUndoView; | - |
207 | public: | - |
208 | QUndoViewPrivate() : | - |
209 | | - |
210 | group(0), | - |
211 | | - |
212 | model(0) {} | 0 |
213 | | - |
214 | | - |
215 | QPointer<QUndoGroup> group; | - |
216 | | - |
217 | QUndoModel *model; | - |
218 | | - |
219 | void init(); | - |
220 | }; | - |
221 | | - |
222 | void QUndoViewPrivate::init() | - |
223 | { | - |
224 | QUndoView * const q = q_func(); | - |
225 | | - |
226 | model = new QUndoModel(q); | - |
227 | q->setModel(model); | - |
228 | q->setSelectionModel(model->selectionModel()); | - |
229 | } | 0 |
230 | | - |
231 | | - |
232 | | - |
233 | | - |
234 | | - |
235 | QUndoView::QUndoView(QWidget *parent) | - |
236 | : QListView(*new QUndoViewPrivate(), parent) | - |
237 | { | - |
238 | QUndoViewPrivate * const d = d_func(); | - |
239 | d->init(); | - |
240 | } | 0 |
241 | | - |
242 | | - |
243 | | - |
244 | | - |
245 | | - |
246 | QUndoView::QUndoView(QUndoStack *stack, QWidget *parent) | - |
247 | : QListView(*new QUndoViewPrivate(), parent) | - |
248 | { | - |
249 | QUndoViewPrivate * const d = d_func(); | - |
250 | d->init(); | - |
251 | setStack(stack); | - |
252 | } | 0 |
253 | QUndoView::QUndoView(QUndoGroup *group, QWidget *parent) | - |
254 | : QListView(*new QUndoViewPrivate(), parent) | - |
255 | { | - |
256 | QUndoViewPrivate * const d = d_func(); | - |
257 | d->init(); | - |
258 | setGroup(group); | - |
259 | } | 0 |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
266 | | - |
267 | QUndoView::~QUndoView() | - |
268 | { | - |
269 | } | - |
270 | QUndoStack *QUndoView::stack() const | - |
271 | { | - |
272 | const QUndoViewPrivate * const d = d_func(); | - |
273 | return d->model->stack(); never executed: return d->model->stack(); | 0 |
274 | } | - |
275 | void QUndoView::setStack(QUndoStack *stack) | - |
276 | { | - |
277 | QUndoViewPrivate * const d = d_func(); | - |
278 | | - |
279 | setGroup(0); | - |
280 | | - |
281 | d->model->setStack(stack); | - |
282 | } | 0 |
283 | void QUndoView::setGroup(QUndoGroup *group) | - |
284 | { | - |
285 | QUndoViewPrivate * const d = d_func(); | - |
286 | | - |
287 | if (d->group == group) never evaluated: d->group == group | 0 |
288 | return; | 0 |
289 | | - |
290 | if (d->group != 0) { never evaluated: d->group != 0 | 0 |
291 | disconnect(d->group, "2""activeStackChanged(QUndoStack*)", | - |
292 | d->model, "1""setStack(QUndoStack*)"); | - |
293 | } | 0 |
294 | | - |
295 | d->group = group; | - |
296 | | - |
297 | if (d->group != 0) { never evaluated: d->group != 0 | 0 |
298 | connect(d->group, "2""activeStackChanged(QUndoStack*)", | - |
299 | d->model, "1""setStack(QUndoStack*)"); | - |
300 | d->model->setStack(d->group->activeStack()); | - |
301 | } else { | 0 |
302 | d->model->setStack(0); | - |
303 | } | 0 |
304 | } | - |
305 | QUndoGroup *QUndoView::group() const | - |
306 | { | - |
307 | const QUndoViewPrivate * const d = d_func(); | - |
308 | return d->group; never executed: return d->group; | 0 |
309 | } | - |
310 | void QUndoView::setEmptyLabel(const QString &label) | - |
311 | { | - |
312 | QUndoViewPrivate * const d = d_func(); | - |
313 | d->model->setEmptyLabel(label); | - |
314 | } | 0 |
315 | | - |
316 | QString QUndoView::emptyLabel() const | - |
317 | { | - |
318 | const QUndoViewPrivate * const d = d_func(); | - |
319 | return d->model->emptyLabel(); never executed: return d->model->emptyLabel(); | 0 |
320 | } | - |
321 | void QUndoView::setCleanIcon(const QIcon &icon) | - |
322 | { | - |
323 | const QUndoViewPrivate * const d = d_func(); | - |
324 | d->model->setCleanIcon(icon); | - |
325 | | - |
326 | } | 0 |
327 | | - |
328 | QIcon QUndoView::cleanIcon() const | - |
329 | { | - |
330 | const QUndoViewPrivate * const d = d_func(); | - |
331 | return d->model->cleanIcon(); never executed: return d->model->cleanIcon(); | 0 |
332 | } | - |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
| | |