File indexing completed on 2024-06-16 04:16:12
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2010 Matus Talcik <matus.talcik@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 /**************************************************************************** 0007 ** 0008 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 0009 ** All rights reserved. 0010 ** Contact: Nokia Corporation (qt-info@nokia.com) 0011 ** 0012 ** This file is part of the QtGui module of the Qt Toolkit. 0013 ** 0014 ** $QT_BEGIN_LICENSE:LGPL$ 0015 ** No Commercial Usage 0016 ** This file contains pre-release code and may not be distributed. 0017 ** You may use this file in accordance with the terms and conditions 0018 ** contained in the Technology Preview License Agreement accompanying 0019 ** this package. 0020 ** 0021 ** GNU Lesser General Public License Usage 0022 ** Alternatively, this file may be used under the terms of the GNU Lesser 0023 ** General Public License version 2.1 as published by the Free Software 0024 ** Foundation and appearing in the file LICENSE.LGPL included in the 0025 ** packaging of this file. Please review the following information to 0026 ** ensure the GNU Lesser General Public License version 2.1 requirements 0027 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 0028 ** 0029 ** In addition, as a special exception, Nokia gives you certain additional 0030 ** rights. These rights are described in the Nokia Qt LGPL Exception 0031 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 0032 ** 0033 ** If you have questions regarding the use of this file, please contact 0034 ** Nokia at qt-info@nokia.com. 0035 ** 0036 ** $QT_END_LICENSE$ 0037 ** 0038 ****************************************************************************/ 0039 #ifndef KIS_UNDO_MODEL_H 0040 #define KIS_UNDO_MODEL_H 0041 #include <QAbstractItemModel> 0042 0043 #include <kundo2qstack.h> 0044 #include <QItemSelectionModel> 0045 #include <QIcon> 0046 #include <QPointer> 0047 0048 #include <kundo2command.h> 0049 0050 #include "kis_types.h" 0051 #include "kis_canvas2.h" 0052 #include "KisViewManager.h" 0053 #include "kis_image.h" 0054 #include "kis_paint_device.h" 0055 0056 class KisUndoModel : public QAbstractItemModel 0057 { 0058 Q_OBJECT 0059 public: 0060 KisUndoModel(QObject *parent = 0); 0061 0062 KUndo2QStack *stack() const; 0063 0064 QModelIndex index(int row, int column, 0065 const QModelIndex &parent = QModelIndex()) const override; 0066 QModelIndex parent(const QModelIndex &child) const override; 0067 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0068 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0069 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0070 0071 QModelIndex selectedIndex() const; 0072 QItemSelectionModel *selectionModel() const; 0073 0074 QString emptyLabel() const; 0075 void setEmptyLabel(const QString &label); 0076 0077 void setCleanIcon(const QIcon &icon); 0078 QIcon cleanIcon() const; 0079 0080 void setCanvas(KisCanvas2* canvas); 0081 bool checkMergedCommand(int index); 0082 0083 // It's a bit weird to have "setDevicePixelRatio" 0084 // in a model class, but it's needed for 0085 // QImages inside, because there is no 0086 // ItemDelegate for the items, 0087 // so it's better to initialize QImages already 0088 // devicePixelRatio-corrected. 0089 void setDevicePixelRatio(qreal devicePixelRatio); 0090 0091 public Q_SLOTS: 0092 void setStack(KUndo2QStack *stack); 0093 void addImage(int idx); 0094 0095 private Q_SLOTS: 0096 void stackChanged(); 0097 void stackDestroyed(QObject *obj); 0098 void setStackCurrentIndex(const QModelIndex &index); 0099 0100 private: 0101 bool m_blockOutgoingHistoryChange {false}; 0102 KUndo2QStack *m_stack {0}; 0103 QItemSelectionModel *m_sel_model {0}; 0104 QString m_empty_label; 0105 QIcon m_clean_icon; 0106 QPointer<KisCanvas2> m_canvas; 0107 QMap<const KUndo2Command*, QImage> m_imageMap; 0108 qreal m_devicePixelRatioF {1.0}; 0109 }; 0110 #endif