QElectroTech  0.8-dev
itemmodelcommand.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ITEMMODELCOMMAND_H
19 #define ITEMMODELCOMMAND_H
20 
21 #include <QUndoCommand>
22 #include <QModelIndex>
23 #include <QPointer>
24 
25 class QAbstractItemModel;
26 
31 class ModelIndexCommand : public QUndoCommand
32 {
33  public:
34  ModelIndexCommand(QAbstractItemModel *model, const QModelIndex &index, QUndoCommand *parent = nullptr);
35  void setData(const QVariant &value, int role = Qt::DisplayRole);
36 
37  virtual void redo() override;
38  virtual void undo() override;
39 
40  private:
41  QPointer<QAbstractItemModel> m_model;
42  QModelIndex m_index;
43  QVariant m_old_value,
45  int m_role=0;
46 };
47 
52 class ModelHeaderDataCommand : public QUndoCommand
53 {
54  public:
55  ModelHeaderDataCommand(QAbstractItemModel *model, QUndoCommand *parent = nullptr);
56  void setData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::DisplayRole);
57 
58  virtual void redo() override;
59  virtual void undo() override;
60 
61  private:
62  QPointer<QAbstractItemModel> m_model;
63  Qt::Orientation m_orientation;
64  QVariant m_old_value,
66  int m_section,
68 };
69 
70 #endif // ITEMMODELCOMMAND_H
ModelIndexCommand::setData
void setData(const QVariant &value, int role=Qt::DisplayRole)
ModelIndexCommand::setData.
Definition: itemmodelcommand.cpp:37
ModelIndexCommand::m_role
int m_role
Definition: itemmodelcommand.h:45
ModelIndexCommand::m_model
QPointer< QAbstractItemModel > m_model
Definition: itemmodelcommand.h:41
ModelHeaderDataCommand::m_role
int m_role
Definition: itemmodelcommand.h:67
ModelIndexCommand::redo
virtual void redo() override
ModelIndexCommand::redo Reimplemented from QUndoCommand.
Definition: itemmodelcommand.cpp:53
itemmodelcommand.h
ModelHeaderDataCommand
The ModelHeaderDataCommand class Change the data of a header.
Definition: itemmodelcommand.h:53
ModelHeaderDataCommand::m_orientation
Qt::Orientation m_orientation
Definition: itemmodelcommand.h:63
ModelIndexCommand::m_new_value
QVariant m_new_value
Definition: itemmodelcommand.h:44
ModelHeaderDataCommand::m_old_value
QVariant m_old_value
Definition: itemmodelcommand.h:64
ModelIndexCommand
The ModelIndexCommand class Change a data of an index of QAbstractItemModel.
Definition: itemmodelcommand.h:32
ModelIndexCommand::m_index
QModelIndex m_index
Definition: itemmodelcommand.h:42
ModelHeaderDataCommand::redo
virtual void redo() override
ModelHeaderDataCommand::redo Reimplemented from QUndoCommand.
Definition: itemmodelcommand.cpp:104
ModelHeaderDataCommand::m_section
int m_section
Definition: itemmodelcommand.h:66
ModelHeaderDataCommand::ModelHeaderDataCommand
ModelHeaderDataCommand(QAbstractItemModel *model, QUndoCommand *parent=nullptr)
ModelHeaderDataCommand::ModelHeaderDataCommand.
Definition: itemmodelcommand.cpp:74
ModelHeaderDataCommand::setData
void setData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole)
ModelHeaderDataCommand::setData See QAbstractItemModel::setHeaderData.
Definition: itemmodelcommand.cpp:87
ModelHeaderDataCommand::m_new_value
QVariant m_new_value
Definition: itemmodelcommand.h:65
ModelHeaderDataCommand::m_model
QPointer< QAbstractItemModel > m_model
Definition: itemmodelcommand.h:62
ModelIndexCommand::undo
virtual void undo() override
ModelIndexCommand::undo Reimplemented from QUndoCommand.
Definition: itemmodelcommand.cpp:63
ModelIndexCommand::ModelIndexCommand
ModelIndexCommand(QAbstractItemModel *model, const QModelIndex &index, QUndoCommand *parent=nullptr)
ModelIndexCommand::ModelIndexCommand.
Definition: itemmodelcommand.cpp:26
ModelIndexCommand::m_old_value
QVariant m_old_value
Definition: itemmodelcommand.h:43
ModelHeaderDataCommand::undo
virtual void undo() override
ModelHeaderDataCommand::undo Reimplemented from QUndoCommand.
Definition: itemmodelcommand.cpp:115