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

#include <KisUndoModel.h>

+ Inheritance diagram for KisUndoModel:

Public Slots

void addImage (int idx)
 
void setStack (KUndo2QStack *stack)
 

Public Member Functions

bool checkMergedCommand (int index)
 
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
 
 KisUndoModel (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 setCanvas (KisCanvas2 *canvas)
 
void setCleanIcon (const QIcon &icon)
 
void setDevicePixelRatio (qreal devicePixelRatio)
 
void setEmptyLabel (const QString &label)
 
KUndo2QStackstack () const
 

Private Slots

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

Private Attributes

bool m_blockOutgoingHistoryChange {false}
 
QPointer< KisCanvas2m_canvas
 
QIcon m_clean_icon
 
qreal m_devicePixelRatioF {1.0}
 
QString m_empty_label
 
QMap< const KUndo2Command *, QImage > m_imageMap
 
QItemSelectionModel * m_sel_model {0}
 
KUndo2QStackm_stack {0}
 

Detailed Description

Definition at line 56 of file KisUndoModel.h.

Constructor & Destructor Documentation

◆ KisUndoModel()

KisUndoModel::KisUndoModel ( QObject * parent = 0)

Definition at line 49 of file KisUndoModel.cpp.

50 : QAbstractItemModel(parent)
51{
53 m_stack = 0;
54 m_canvas = 0;
55 m_sel_model = new QItemSelectionModel(this, this);
56 connect(m_sel_model, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(setStackCurrentIndex(QModelIndex)));
57 m_empty_label = i18n("<empty>");
58}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool m_blockOutgoingHistoryChange
QPointer< KisCanvas2 > m_canvas
void setStackCurrentIndex(const QModelIndex &index)
QString m_empty_label
QModelIndex parent(const QModelIndex &child) const override
KUndo2QStack * m_stack
QItemSelectionModel * m_sel_model

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

Member Function Documentation

◆ addImage

void KisUndoModel::addImage ( int idx)
slot

Definition at line 249 of file KisUndoModel.cpp.

250{
251
252 if (m_stack == 0 || m_stack->count() == 0) {
253 return;
254 }
255
256 const KUndo2Command* currentCommand = m_stack->command(idx-1);
257 if (m_stack->count() == idx && !m_imageMap.contains(currentCommand)) {
258 KisImageWSP historyImage = m_canvas->image();
259 KisPaintDeviceSP paintDevice = historyImage->projection();
260 QSize size = QSize(32, 32)*m_devicePixelRatioF;
261 QImage image = paintDevice->createThumbnail(size.width(), size.height(), 1,
264 image.setDevicePixelRatio(m_devicePixelRatioF);
265 m_imageMap[currentCommand] = image;
266 }
267
269
270 for (int i = 0; i < m_stack->count(); ++i) {
271 list << m_stack->command(i);
272 }
273
274 for (QMap<const KUndo2Command*, QImage>:: iterator it = m_imageMap.begin(); it != m_imageMap.end();) {
275 if (!list.contains(it.key())) {
276 it = m_imageMap.erase(it);
277 }
278 else {
279 ++it;
280 }
281 }
282}
int count() const
const KUndo2Command * command(int index) const
KisPaintDeviceSP projection() const
QImage createThumbnail(qint32 maxw, qint32 maxh, QRect rect, qreal oversample=1, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags())
qreal m_devicePixelRatioF
QMap< const KUndo2Command *, QImage > m_imageMap
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KUndo2QStack::command(), KUndo2QStack::count(), KisPaintDevice::createThumbnail(), KoColorConversionTransformation::internalConversionFlags(), KoColorConversionTransformation::internalRenderingIntent(), m_canvas, m_devicePixelRatioF, m_imageMap, m_stack, and KisImage::projection().

◆ checkMergedCommand()

bool KisUndoModel::checkMergedCommand ( int index)

Definition at line 283 of file KisUndoModel.cpp.

284{
285 Q_UNUSED(index);
286 return false;
287}
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override

References index().

◆ cleanIcon()

QIcon KisUndoModel::cleanIcon ( ) const

Definition at line 239 of file KisUndoModel.cpp.

240{
241 return m_clean_icon;
242}

References m_clean_icon.

◆ columnCount()

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

Definition at line 170 of file KisUndoModel.cpp.

171{
172 return 1;
173}

◆ data()

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

Definition at line 187 of file KisUndoModel.cpp.

188{
189 if (m_stack == 0){
190 return QVariant();
191 }
192
193 if (index.column() != 0){
194 return QVariant();
195 }
196
197 if (index.row() < 0 || index.row() > m_stack->count()){
198 return QVariant();
199 }
200
201 if (role == Qt::DisplayRole) {
202 if (index.row() == 0){
203 return m_empty_label;
204 }
205 KUndo2Command* currentCommand = const_cast<KUndo2Command*>(m_stack->command(index.row() - 1));
206
207 return currentCommand->isMerged() ?
208 QString("%1 (Merged %2)").arg(currentCommand->text().toString()).arg(calcNumMergedCommands(currentCommand)) :
209 currentCommand->text().toString();
210 }
211 else if (role == Qt::DecorationRole) {
212 if (index.row() > 0) {
213 const KUndo2Command* currentCommand = m_stack->command(index.row() - 1);
214 if (m_imageMap.contains(currentCommand)) {
215 return m_imageMap[currentCommand];
216 }
217 }
218 }
219 return QVariant();
220}
KUndo2MagicString text() const
virtual bool isMerged() const
QString toString() const

References KUndo2QStack::command(), KUndo2QStack::count(), index(), KUndo2Command::isMerged(), m_empty_label, m_imageMap, m_stack, KUndo2Command::text(), and KUndo2MagicString::toString().

◆ emptyLabel()

QString KisUndoModel::emptyLabel ( ) const

Definition at line 222 of file KisUndoModel.cpp.

223{
224 return m_empty_label;
225}

References m_empty_label.

◆ index()

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

Definition at line 137 of file KisUndoModel.cpp.

138{
139 if (m_stack == 0)
140 return QModelIndex();
141
142 if (parent.isValid())
143 return QModelIndex();
144
145 if (column != 0)
146 return QModelIndex();
147
148 if (row < 0 || row > m_stack->count())
149 return QModelIndex();
150
151 return createIndex(row, column);
152}

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

◆ parent()

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

Definition at line 154 of file KisUndoModel.cpp.

155{
156 return QModelIndex();
157}

◆ rowCount()

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

Definition at line 159 of file KisUndoModel.cpp.

160{
161 if (m_stack == 0)
162 return 0;
163
164 if (parent.isValid())
165 return 0;
166
167 return m_stack->count() + 1;
168}

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

◆ selectedIndex()

QModelIndex KisUndoModel::selectedIndex ( ) const

Definition at line 132 of file KisUndoModel.cpp.

133{
134 return m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0);
135}

References KUndo2QStack::index(), and m_stack.

◆ selectionModel()

QItemSelectionModel * KisUndoModel::selectionModel ( ) const

Definition at line 60 of file KisUndoModel.cpp.

61{
62 return m_sel_model;
63}

References m_sel_model.

◆ setCanvas()

void KisUndoModel::setCanvas ( KisCanvas2 * canvas)

Definition at line 244 of file KisUndoModel.cpp.

245{
246 m_canvas = canvas;
247}

References m_canvas.

◆ setCleanIcon()

void KisUndoModel::setCleanIcon ( const QIcon & icon)

Definition at line 233 of file KisUndoModel.cpp.

234{
235 m_clean_icon = icon;
236 stackChanged();
237}

References m_clean_icon, and stackChanged().

◆ setDevicePixelRatio()

void KisUndoModel::setDevicePixelRatio ( qreal devicePixelRatio)

Definition at line 289 of file KisUndoModel.cpp.

290{
291 m_devicePixelRatioF = devicePixelRatio;
292}

References m_devicePixelRatioF.

◆ setEmptyLabel()

void KisUndoModel::setEmptyLabel ( const QString & label)

Definition at line 227 of file KisUndoModel.cpp.

228{
229 m_empty_label = label;
230 stackChanged();
231}

References m_empty_label, and stackChanged().

◆ setStack

void KisUndoModel::setStack ( KUndo2QStack * stack)
slot

Definition at line 70 of file KisUndoModel.cpp.

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

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

◆ setStackCurrentIndex

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

Definition at line 115 of file KisUndoModel.cpp.

116{
118 return;
119
120 if (m_stack == 0)
121 return;
122
123 if (index == selectedIndex())
124 return;
125
126 if (index.column() != 0)
127 return;
128
129 m_stack->setIndex(index.row());
130}
virtual void setIndex(int idx)
QModelIndex selectedIndex() const

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

◆ stack()

KUndo2QStack * KisUndoModel::stack ( ) const

Definition at line 65 of file KisUndoModel.cpp.

66{
67 return m_stack;
68}

References m_stack.

◆ stackChanged

void KisUndoModel::stackChanged ( )
privateslot

Definition at line 105 of file KisUndoModel.cpp.

106{
107 beginResetModel();
108 endResetModel();
109
111 m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect);
113}

References m_blockOutgoingHistoryChange, m_sel_model, and selectedIndex().

◆ stackDestroyed

void KisUndoModel::stackDestroyed ( QObject * obj)
privateslot

Definition at line 96 of file KisUndoModel.cpp.

97{
98 if (obj != m_stack)
99 return;
100 m_stack = 0;
101
102 stackChanged();
103}

References m_stack, and stackChanged().

Member Data Documentation

◆ m_blockOutgoingHistoryChange

bool KisUndoModel::m_blockOutgoingHistoryChange {false}
private

Definition at line 101 of file KisUndoModel.h.

101{false};

◆ m_canvas

QPointer<KisCanvas2> KisUndoModel::m_canvas
private

Definition at line 106 of file KisUndoModel.h.

◆ m_clean_icon

QIcon KisUndoModel::m_clean_icon
private

Definition at line 105 of file KisUndoModel.h.

◆ m_devicePixelRatioF

qreal KisUndoModel::m_devicePixelRatioF {1.0}
private

Definition at line 108 of file KisUndoModel.h.

108{1.0};

◆ m_empty_label

QString KisUndoModel::m_empty_label
private

Definition at line 104 of file KisUndoModel.h.

◆ m_imageMap

QMap<const KUndo2Command*, QImage> KisUndoModel::m_imageMap
private

Definition at line 107 of file KisUndoModel.h.

◆ m_sel_model

QItemSelectionModel* KisUndoModel::m_sel_model {0}
private

Definition at line 103 of file KisUndoModel.h.

103{0};

◆ m_stack

KUndo2QStack* KisUndoModel::m_stack {0}
private

Definition at line 102 of file KisUndoModel.h.

102{0};

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