QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
itemmodelcommand.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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
25class QAbstractItemModel;
26
31class 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
52class 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,
68};
69
70#endif // ITEMMODELCOMMAND_H
The ModelHeaderDataCommand class Change the data of a header.
Definition itemmodelcommand.h:53
virtual void undo() override
ModelHeaderDataCommand::undo Reimplemented from QUndoCommand.
Definition itemmodelcommand.cpp:117
virtual void redo() override
ModelHeaderDataCommand::redo Reimplemented from QUndoCommand.
Definition itemmodelcommand.cpp:106
QPointer< QAbstractItemModel > m_model
Definition itemmodelcommand.h:62
int m_section
Definition itemmodelcommand.h:66
QVariant m_old_value
Definition itemmodelcommand.h:64
Qt::Orientation m_orientation
Definition itemmodelcommand.h:63
QVariant m_new_value
Definition itemmodelcommand.h:65
int m_role
Definition itemmodelcommand.h:67
void setData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole)
ModelHeaderDataCommand::setData See QAbstractItemModel::setHeaderData.
Definition itemmodelcommand.cpp:89
The ModelIndexCommand class Change a data of an index of QAbstractItemModel.
Definition itemmodelcommand.h:32
int m_role
Definition itemmodelcommand.h:45
QModelIndex m_index
Definition itemmodelcommand.h:42
void setData(const QVariant &value, int role=Qt::DisplayRole)
ModelIndexCommand::setData.
Definition itemmodelcommand.cpp:37
QPointer< QAbstractItemModel > m_model
Definition itemmodelcommand.h:41
QVariant m_old_value
Definition itemmodelcommand.h:43
virtual void undo() override
ModelIndexCommand::undo Reimplemented from QUndoCommand.
Definition itemmodelcommand.cpp:64
QVariant m_new_value
Definition itemmodelcommand.h:44
virtual void redo() override
ModelIndexCommand::redo Reimplemented from QUndoCommand.
Definition itemmodelcommand.cpp:53