File indexing completed on 2023-05-30 10:45:26
0001 /* 0002 SPDX-FileCopyrightText: 2002-2010 Peter Hedlund <peter.hedlund@kdemail.net> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KWQCOMMANDS_H 0007 #define KWQCOMMANDS_H 0008 0009 #include <QUndoCommand> 0010 0011 #include <KLocalizedString> 0012 0013 #include "kwqtableview.h" 0014 #include "kwqsortfiltermodel.h" 0015 #include "prefs.h" 0016 0017 void copyToClipboard(QTableView * view); 0018 0019 struct IndexAndData 0020 { 0021 QModelIndex index; 0022 QVariant data; 0023 QVariant image; 0024 QVariant sound; 0025 int height; 0026 }; 0027 0028 typedef QList<IndexAndData> IndexAndDataList; 0029 0030 struct ColumnData 0031 { 0032 QString identifier; 0033 QString layout; 0034 int width; 0035 }; 0036 0037 typedef QList<ColumnData> ColumnDataList; 0038 0039 0040 class KWQUndoCommand : public QUndoCommand 0041 { 0042 public: 0043 explicit KWQUndoCommand(KWQTableView *view); 0044 0045 void undo() override; 0046 void redo() override {}; 0047 0048 KWQTableView * view() {return m_view;}; 0049 QModelIndex oldCurrentIndex() const {return m_currentIndex;}; 0050 QModelIndexList oldSelectedIndexes() const {return m_selectedIndexes;}; 0051 IndexAndDataList oldData() {return m_indexAndData;}; 0052 0053 private: 0054 KWQTableView *m_view; 0055 IndexAndDataList m_indexAndData; 0056 QModelIndexList m_selectedIndexes; 0057 QModelIndex m_currentIndex; 0058 }; 0059 0060 0061 class KWQCommandClear : public KWQUndoCommand 0062 { 0063 public: 0064 explicit KWQCommandClear(KWQTableView *view); 0065 void redo() override; 0066 }; 0067 0068 0069 class KWQCommandCut : public KWQCommandClear 0070 { 0071 public: 0072 explicit KWQCommandCut(KWQTableView *view); 0073 void redo() override; 0074 }; 0075 0076 0077 class KWQCommandPaste : public KWQUndoCommand 0078 { 0079 public: 0080 explicit KWQCommandPaste(KWQTableView *view); 0081 void undo() override; 0082 void redo() override; 0083 private: 0084 int m_rowCount; 0085 IndexAndDataList m_pasteIndexAndData; 0086 }; 0087 0088 0089 class KWQCommandFont : public KWQUndoCommand 0090 { 0091 public: 0092 KWQCommandFont(KWQTableView *view, const QFont &oldFont, const QFont &newFont) : KWQUndoCommand(view), m_oldFont(oldFont), m_newFont(newFont) 0093 { setText(i18n("Font")); } 0094 void undo() override 0095 { Prefs::setEditorFont(m_oldFont); 0096 view()->reset(); } 0097 void redo() override 0098 { Prefs::setEditorFont(m_newFont); 0099 view()->reset(); } 0100 private: 0101 QFont m_oldFont; 0102 QFont m_newFont; 0103 }; 0104 0105 0106 class KWQCommandEntry : public KWQUndoCommand 0107 { 0108 public: 0109 KWQCommandEntry(KWQTableView *view, const QString &oldText, const QString &newText) 0110 : KWQUndoCommand(view), m_oldText(oldText), m_newText(newText) 0111 { setText(i18n("Entry")); } 0112 0113 void redo() override 0114 { view()->model()->setData(oldCurrentIndex(), m_newText, Qt::EditRole); 0115 view()->setCurrentIndex(oldCurrentIndex()); } 0116 private: 0117 QString m_oldText; 0118 QString m_newText; 0119 }; 0120 0121 0122 class KWQCommandSort : public QUndoCommand 0123 { 0124 public: 0125 KWQCommandSort(QTableView *view, int column); 0126 void undo() override; 0127 void redo() override; 0128 private: 0129 QTableView *m_view; 0130 int m_column; 0131 }; 0132 0133 0134 class KWQCommandShuffle : public KWQCommandSort 0135 { 0136 public: 0137 KWQCommandShuffle(QTableView *view, int column); 0138 void undo() override; 0139 void redo() override; 0140 private: 0141 QTableView *m_view; 0142 }; 0143 0144 0145 class KWQCommandInsert : public KWQUndoCommand 0146 { 0147 public: 0148 explicit KWQCommandInsert(KWQTableView *view); 0149 void undo() override; 0150 void redo() override; 0151 }; 0152 0153 0154 class KWQCommandDelete : public KWQUndoCommand 0155 { 0156 public: 0157 explicit KWQCommandDelete(KWQTableView *view); 0158 void undo() override; 0159 void redo() override; 0160 private: 0161 IndexAndDataList m_deleteIndexAndData; 0162 }; 0163 0164 0165 class KWQCommandUnmarkBlank : public KWQUndoCommand 0166 { 0167 public: 0168 explicit KWQCommandUnmarkBlank(KWQTableView *view); 0169 //virtual void undo(); 0170 void redo() override; 0171 }; 0172 0173 0174 class KWQCommandIdentifiers : public KWQUndoCommand 0175 { 0176 public: 0177 KWQCommandIdentifiers(KWQTableView *view, const ColumnDataList &newColumnData); 0178 void undo() override; 0179 void redo() override; 0180 private: 0181 ColumnDataList m_oldColumnData; 0182 ColumnDataList m_newColumnData; 0183 }; 0184 0185 0186 class KWQCommandImage : public KWQUndoCommand 0187 { 0188 public: 0189 KWQCommandImage(KWQTableView *view, const QUrl &); 0190 void undo() override; 0191 void redo() override; 0192 0193 private: 0194 QUrl m_oldUrl; 0195 QUrl m_newUrl; 0196 }; 0197 0198 0199 class KWQCommandSound : public KWQUndoCommand 0200 { 0201 public: 0202 KWQCommandSound(KWQTableView *view, const QUrl &); 0203 void undo() override; 0204 void redo() override; 0205 0206 private: 0207 QUrl m_oldUrl; 0208 QUrl m_newUrl; 0209 }; 0210 0211 #endif // KWQCOMMANDS_H