Krita Source Code Documentation
Loading...
Searching...
No Matches
KUndo2Model Class Reference

#include <kundo2model.h>

+ Inheritance diagram for KUndo2Model:

Public Slots

void setStack (KUndo2QStack *stack)
 

Public Member Functions

QIcon cleanIcon () const
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
QString emptyLabel () const
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
 KUndo2Model (QObject *parent=0)
 
QModelIndex parent (const QModelIndex &child) const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
QModelIndex selectedIndex () const
 
QItemSelectionModel * selectionModel () const
 
void setCleanIcon (const QIcon &icon)
 
void setEmptyLabel (const QString &label)
 
KUndo2QStackstack () const
 

Private Slots

void setStackCurrentIndex (const QModelIndex &index)
 
void stackChanged ()
 
void stackDestroyed (QObject *obj)
 

Private Attributes

QIcon m_clean_icon
 
QString m_empty_label
 
QItemSelectionModel * m_sel_model
 
KUndo2QStackm_stack
 

Detailed Description

Definition at line 54 of file kundo2model.h.

Constructor & Destructor Documentation

◆ KUndo2Model()

KUndo2Model::KUndo2Model ( QObject * parent = 0)
explicit

Definition at line 48 of file kundo2model.cpp.

49 : QAbstractItemModel(parent)
50{
51 m_stack = 0;
52 m_sel_model = new QItemSelectionModel(this, this);
53 connect(m_sel_model, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(setStackCurrentIndex(QModelIndex)));
54 m_empty_label = i18n("<empty>");
55}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QModelIndex parent(const QModelIndex &child) const override
KUndo2QStack * m_stack
Definition kundo2model.h:87
QItemSelectionModel * m_sel_model
Definition kundo2model.h:88
QString m_empty_label
Definition kundo2model.h:89
void setStackCurrentIndex(const QModelIndex &index)

References connect(), m_empty_label, m_sel_model, m_stack, and setStackCurrentIndex().

Member Function Documentation

◆ cleanIcon()

QIcon KUndo2Model::cleanIcon ( ) const

Definition at line 202 of file kundo2model.cpp.

203{
204 return m_clean_icon;
205}
QIcon m_clean_icon
Definition kundo2model.h:90

References m_clean_icon.

◆ columnCount()

int KUndo2Model::columnCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 157 of file kundo2model.cpp.

158{
159 return 1;
160}

◆ data()

QVariant KUndo2Model::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
override

Definition at line 162 of file kundo2model.cpp.

163{
164 if (m_stack == 0)
165 return QVariant();
166
167 if (index.column() != 0)
168 return QVariant();
169
170 if (index.row() < 0 || index.row() > m_stack->count())
171 return QVariant();
172
173 if (role == Qt::DisplayRole) {
174 if (index.row() == 0)
175 return m_empty_label;
176 return m_stack->text(index.row() - 1);
177 } else if (role == Qt::DecorationRole) {
178 if (index.row() == m_stack->cleanIndex() && !m_clean_icon.isNull())
179 return m_clean_icon;
180 }
181
182 return QVariant();
183}
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int cleanIndex() const
QString text(int idx) const
int count() const

References KUndo2QStack::cleanIndex(), KUndo2QStack::count(), index(), m_clean_icon, m_empty_label, m_stack, and KUndo2QStack::text().

◆ emptyLabel()

QString KUndo2Model::emptyLabel ( ) const

Definition at line 185 of file kundo2model.cpp.

186{
187 return m_empty_label;
188}

References m_empty_label.

◆ index()

QModelIndex KUndo2Model::index ( int row,
int column,
const QModelIndex & parent = QModelIndex() ) const
override

Definition at line 124 of file kundo2model.cpp.

125{
126 if (m_stack == 0)
127 return QModelIndex();
128
129 if (parent.isValid())
130 return QModelIndex();
131
132 if (column != 0)
133 return QModelIndex();
134
135 if (row < 0 || row > m_stack->count())
136 return QModelIndex();
137
138 return createIndex(row, column);
139}

References KUndo2QStack::count(), m_stack, and parent().

◆ parent()

QModelIndex KUndo2Model::parent ( const QModelIndex & child) const
override

Definition at line 141 of file kundo2model.cpp.

142{
143 return QModelIndex();
144}

◆ rowCount()

int KUndo2Model::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 146 of file kundo2model.cpp.

147{
148 if (m_stack == 0)
149 return 0;
150
151 if (parent.isValid())
152 return 0;
153
154 return m_stack->count() + 1;
155}

References KUndo2QStack::count(), m_stack, and parent().

◆ selectedIndex()

QModelIndex KUndo2Model::selectedIndex ( ) const

Definition at line 119 of file kundo2model.cpp.

120{
121 return m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0);
122}

References KUndo2QStack::index(), and m_stack.

◆ selectionModel()

QItemSelectionModel * KUndo2Model::selectionModel ( ) const

Definition at line 57 of file kundo2model.cpp.

58{
59 return m_sel_model;
60}

References m_sel_model.

◆ setCleanIcon()

void KUndo2Model::setCleanIcon ( const QIcon & icon)

Definition at line 196 of file kundo2model.cpp.

197{
198 m_clean_icon = icon;
199 stackChanged();
200}
void stackChanged()

References m_clean_icon, and stackChanged().

◆ setEmptyLabel()

void KUndo2Model::setEmptyLabel ( const QString & label)

Definition at line 190 of file kundo2model.cpp.

191{
192 m_empty_label = label;
193 stackChanged();
194}

References m_empty_label, and stackChanged().

◆ setStack

void KUndo2Model::setStack ( KUndo2QStack * stack)
slot

Definition at line 67 of file kundo2model.cpp.

68{
69 if (m_stack == stack)
70 return;
71
72 if (m_stack != 0) {
73 disconnect(m_stack, SIGNAL(cleanChanged(bool)), this, SLOT(stackChanged()));
74 disconnect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(stackChanged()));
75 disconnect(m_stack, SIGNAL(destroyed(QObject*)), this, SLOT(stackDestroyed(QObject*)));
76 disconnect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(addImage(int)));
77 }
78 m_stack = stack;
79 if (m_stack != 0) {
80 connect(m_stack, SIGNAL(cleanChanged(bool)), this, SLOT(stackChanged()));
81 connect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(stackChanged()));
82 connect(m_stack, SIGNAL(destroyed(QObject*)), this, SLOT(stackDestroyed(QObject*)));
83 connect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(addImage(int)));
84 }
85
87}
KUndo2QStack * stack() const
void stackDestroyed(QObject *obj)

References connect(), m_stack, stack(), stackChanged(), and stackDestroyed().

◆ setStackCurrentIndex

void KUndo2Model::setStackCurrentIndex ( const QModelIndex & index)
privateslot

Definition at line 105 of file kundo2model.cpp.

106{
107 if (m_stack == 0)
108 return;
109
110 if (index == selectedIndex())
111 return;
112
113 if (index.column() != 0)
114 return;
115
116 m_stack->setIndex(index.row());
117}
QModelIndex selectedIndex() const
virtual void setIndex(int idx)

References index(), m_stack, selectedIndex(), and KUndo2QStack::setIndex().

◆ stack()

KUndo2QStack * KUndo2Model::stack ( ) const

Definition at line 62 of file kundo2model.cpp.

63{
64 return m_stack;
65}

References m_stack.

◆ stackChanged

void KUndo2Model::stackChanged ( )
privateslot

Definition at line 98 of file kundo2model.cpp.

99{
100 beginResetModel();
101 endResetModel();
102 m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect);
103}

References m_sel_model, and selectedIndex().

◆ stackDestroyed

void KUndo2Model::stackDestroyed ( QObject * obj)
privateslot

Definition at line 89 of file kundo2model.cpp.

90{
91 if (obj != m_stack)
92 return;
93 m_stack = 0;
94
96}

References m_stack, and stackChanged().

Member Data Documentation

◆ m_clean_icon

QIcon KUndo2Model::m_clean_icon
private

Definition at line 90 of file kundo2model.h.

◆ m_empty_label

QString KUndo2Model::m_empty_label
private

Definition at line 89 of file kundo2model.h.

◆ m_sel_model

QItemSelectionModel* KUndo2Model::m_sel_model
private

Definition at line 88 of file kundo2model.h.

◆ m_stack

KUndo2QStack* KUndo2Model::m_stack
private

Definition at line 87 of file kundo2model.h.


The documentation for this class was generated from the following files: