6#if QT_CONFIG(undogroup)
7#include <QtGui/qundogroup.h>
9#include <QtGui/qundostack.h>
10#include <QtCore/qabstractitemmodel.h>
11#include <QtCore/qpointer.h>
12#include <QtGui/qicon.h>
13#include <private/qlistview_p.h>
26 const QModelIndex &parent = QModelIndex())
const override;
28 virtual int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
29 virtual int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
46 void stackDestroyed(QObject *obj);
47 void setStackCurrentIndex(
const QModelIndex &index);
51 QItemSelectionModel *m_sel_model;
57 : QAbstractItemModel(parent)
60 m_sel_model =
new QItemSelectionModel(
this,
this);
61 connect(m_sel_model, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
62 this, SLOT(setStackCurrentIndex(QModelIndex)));
63 m_emty_label = tr(
"<empty>");
81 if (m_stack !=
nullptr) {
82 disconnect(m_stack, SIGNAL(cleanChanged(
bool)),
this, SLOT(stackChanged()));
83 disconnect(m_stack, SIGNAL(indexChanged(
int)),
this, SLOT(stackChanged()));
84 disconnect(m_stack, SIGNAL(destroyed(QObject*)),
this, SLOT(stackDestroyed(QObject*)));
87 if (m_stack !=
nullptr) {
88 connect(m_stack, SIGNAL(cleanChanged(
bool)),
this, SLOT(stackChanged()));
89 connect(m_stack, SIGNAL(indexChanged(
int)),
this, SLOT(stackChanged()));
90 connect(m_stack, SIGNAL(destroyed(QObject*)),
this, SLOT(stackDestroyed(QObject*)));
109 m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect);
112void QUndoModel::setStackCurrentIndex(
const QModelIndex &index)
114 if (m_stack ==
nullptr)
117 if (index == selectedIndex())
120 if (index.column() != 0)
123 m_stack->setIndex(index.row());
128 return m_stack ==
nullptr ? QModelIndex() : createIndex(m_stack->index(), 0);
133 if (m_stack ==
nullptr)
134 return QModelIndex();
136 if (parent.isValid())
137 return QModelIndex();
140 return QModelIndex();
142 if (row < 0 || row > m_stack->count())
143 return QModelIndex();
145 return createIndex(row, column);
150 return QModelIndex();
155 if (m_stack ==
nullptr)
158 if (parent.isValid())
161 return m_stack->count() + 1;
171 if (m_stack ==
nullptr)
174 if (index.column() != 0)
177 if (index.row() < 0 || index.row() > m_stack->count())
180 if (role == Qt::DisplayRole) {
181 if (index.row() == 0)
183 return m_stack->text(index.row() - 1);
184 }
else if (role == Qt::DecorationRole) {
185 if (index.row() == m_stack->cleanIndex() && !m_clean_icon.isNull())
200 m_emty_label = label;
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
237 Q_DECLARE_PUBLIC(QUndoView)
240#if QT_CONFIG(undogroup)
245#if QT_CONFIG(undogroup)
257 model =
new QUndoModel(q);
259 q->setSelectionModel(model->selectionModel());
263
264
266QUndoView::QUndoView(QWidget *parent)
267 : QListView(*
new QUndoViewPrivate(), parent)
274
275
277QUndoView::QUndoView(QUndoStack *stack, QWidget *parent)
278 : QListView(*
new QUndoViewPrivate(), parent)
285#if QT_CONFIG(undogroup)
288
289
290
291
293QUndoView::QUndoView(QUndoGroup *group, QWidget *parent)
294 : QListView(*
new QUndoViewPrivate(), parent)
304
305
307QUndoView::~QUndoView()
312
313
314
315
316
318QUndoStack *QUndoView::stack()
const
320 Q_D(
const QUndoView);
321 return d->model->stack();
325
326
327
328
329
330
331
333void QUndoView::setStack(QUndoStack *stack)
336#if QT_CONFIG(undogroup)
339 d->model->setStack(stack);
342#if QT_CONFIG(undogroup)
345
346
347
348
349
350
351
353void QUndoView::setGroup(QUndoGroup *group)
357 if (d->group == group)
360 if (d->group !=
nullptr) {
361 disconnect(d->group, SIGNAL(activeStackChanged(QUndoStack*)),
362 d->model, SLOT(setStack(QUndoStack*)));
367 if (d->group !=
nullptr) {
368 connect(d->group, SIGNAL(activeStackChanged(QUndoStack*)),
369 d->model, SLOT(setStack(QUndoStack*)));
370 d->model->setStack(d->group->activeStack());
372 d->model->setStack(
nullptr);
377
378
379
380
381
382
384QUndoGroup *QUndoView::group()
const
386 Q_D(
const QUndoView);
393
394
395
396
397
398
399
401void QUndoView::setEmptyLabel(
const QString &label)
404 d->model->setEmptyLabel(label);
407QString QUndoView::emptyLabel()
const
409 Q_D(
const QUndoView);
410 return d->model->emptyLabel();
414
415
416
417
418
419
420
421
423void QUndoView::setCleanIcon(
const QIcon &icon)
425 Q_D(
const QUndoView);
426 d->model->setCleanIcon(icon);
430QIcon QUndoView::cleanIcon()
const
432 Q_D(
const QUndoView);
433 return d->model->cleanIcon();
438#include "qundoview.moc"
439#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.
Combined button and popup list for selecting options.