qundoview.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9