7#if QT_CONFIG(undogroup)
8#include <QtGui/qundogroup.h>
10#include <QtGui/qundostack.h>
11#include <QtCore/qabstractitemmodel.h>
12#include <QtCore/qpointer.h>
13#include <QtGui/qicon.h>
14#include <private/qlistview_p.h>
27 const QModelIndex &parent = QModelIndex())
const override;
29 virtual int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
30 virtual int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
47 void stackDestroyed(QObject *obj);
48 void setStackCurrentIndex(
const QModelIndex &index);
52 QItemSelectionModel *m_sel_model;
58 : QAbstractItemModel(parent)
61 m_sel_model =
new QItemSelectionModel(
this,
this);
62 connect(m_sel_model, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
63 this, SLOT(setStackCurrentIndex(QModelIndex)));
64 m_emty_label = tr(
"<empty>");
82 if (m_stack !=
nullptr) {
83 disconnect(m_stack, SIGNAL(cleanChanged(
bool)),
this, SLOT(stackChanged()));
84 disconnect(m_stack, SIGNAL(indexChanged(
int)),
this, SLOT(stackChanged()));
85 disconnect(m_stack, SIGNAL(destroyed(QObject*)),
this, SLOT(stackDestroyed(QObject*)));
88 if (m_stack !=
nullptr) {
89 connect(m_stack, SIGNAL(cleanChanged(
bool)),
this, SLOT(stackChanged()));
90 connect(m_stack, SIGNAL(indexChanged(
int)),
this, SLOT(stackChanged()));
91 connect(m_stack, SIGNAL(destroyed(QObject*)),
this, SLOT(stackDestroyed(QObject*)));
110 m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect);
113void QUndoModel::setStackCurrentIndex(
const QModelIndex &index)
115 if (m_stack ==
nullptr)
118 if (index == selectedIndex())
121 if (index.column() != 0)
124 m_stack->setIndex(index.row());
129 return m_stack ==
nullptr ? QModelIndex() : createIndex(m_stack->index(), 0);
134 if (m_stack ==
nullptr)
135 return QModelIndex();
137 if (parent.isValid())
138 return QModelIndex();
141 return QModelIndex();
143 if (row < 0 || row > m_stack->count())
144 return QModelIndex();
146 return createIndex(row, column);
151 return QModelIndex();
156 if (m_stack ==
nullptr)
159 if (parent.isValid())
162 return m_stack->count() + 1;
172 if (m_stack ==
nullptr)
175 if (index.column() != 0)
178 if (index.row() < 0 || index.row() > m_stack->count())
181 if (role == Qt::DisplayRole) {
182 if (index.row() == 0)
184 return m_stack->text(index.row() - 1);
185 }
else if (role == Qt::DecorationRole) {
186 if (index.row() == m_stack->cleanIndex() && !m_clean_icon.isNull())
201 m_emty_label = label;
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
238 Q_DECLARE_PUBLIC(QUndoView)
241#if QT_CONFIG(undogroup)
246#if QT_CONFIG(undogroup)
258 model =
new QUndoModel(q);
260 q->setSelectionModel(model->selectionModel());
264
265
267QUndoView::QUndoView(QWidget *parent)
268 : QListView(*
new QUndoViewPrivate(), parent)
275
276
278QUndoView::QUndoView(QUndoStack *stack, QWidget *parent)
279 : QListView(*
new QUndoViewPrivate(), parent)
286#if QT_CONFIG(undogroup)
289
290
291
292
294QUndoView::QUndoView(QUndoGroup *group, QWidget *parent)
295 : QListView(*
new QUndoViewPrivate(), parent)
305
306
308QUndoView::~QUndoView()
313
314
315
316
317
319QUndoStack *QUndoView::stack()
const
321 Q_D(
const QUndoView);
322 return d->model->stack();
326
327
328
329
330
331
332
334void QUndoView::setStack(QUndoStack *stack)
337#if QT_CONFIG(undogroup)
340 d->model->setStack(stack);
343#if QT_CONFIG(undogroup)
346
347
348
349
350
351
352
354void QUndoView::setGroup(QUndoGroup *group)
358 if (d->group == group)
361 if (d->group !=
nullptr) {
362 disconnect(d->group, SIGNAL(activeStackChanged(QUndoStack*)),
363 d->model, SLOT(setStack(QUndoStack*)));
368 if (d->group !=
nullptr) {
369 connect(d->group, SIGNAL(activeStackChanged(QUndoStack*)),
370 d->model, SLOT(setStack(QUndoStack*)));
371 d->model->setStack(d->group->activeStack());
373 d->model->setStack(
nullptr);
378
379
380
381
382
383
385QUndoGroup *QUndoView::group()
const
387 Q_D(
const QUndoView);
394
395
396
397
398
399
400
402void QUndoView::setEmptyLabel(
const QString &label)
405 d->model->setEmptyLabel(label);
408QString QUndoView::emptyLabel()
const
410 Q_D(
const QUndoView);
411 return d->model->emptyLabel();
415
416
417
418
419
420
421
422
424void QUndoView::setCleanIcon(
const QIcon &icon)
426 Q_D(
const QUndoView);
427 d->model->setCleanIcon(icon);
431QIcon QUndoView::cleanIcon()
const
433 Q_D(
const QUndoView);
434 return d->model->cleanIcon();
439#include "qundoview.moc"
440#include "moc_qundoview.cpp"
QItemSelectionModel * selectionModel() const
void setCleanIcon(const QIcon &icon)
QString emptyLabel() const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
void setEmptyLabel(const QString &label)
QUndoStack * stack() const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns for the children of the given parent.
QModelIndex selectedIndex() const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the item in the model specified by the given row, column and parent index.
virtual QModelIndex parent(const QModelIndex &child) const override
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.