undo_model.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* undo_model.h - undo/redo action list model
  2. * Copyright (C) 2017 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef STUDIO_MODELS_UNDO_MODEL_H_51ADE8C2_A0E9_5F83_A862_2E9B1691C0AA
  18. #define STUDIO_MODELS_UNDO_MODEL_H_51ADE8C2_A0E9_5F83_A862_2E9B1691C0AA
  19. #include <QAbstractItemModel>
  20. #include <generic/context_listener.h>
  21. namespace rainynite::core {
  22. class AbstractAction;
  23. class ActionStack;
  24. } // namespace rainynite::core
  25. namespace rainynite::studio {
  26. class UndoModel : public QAbstractItemModel, public ContextListener {
  27. public:
  28. explicit UndoModel(shared_ptr<core::ActionStack> action_stack_, QObject* parent=nullptr);
  29. virtual ~UndoModel();
  30. QVariant data(QModelIndex const& index, int role) const override;
  31. Qt::ItemFlags flags(QModelIndex const& index) const override;
  32. QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override;
  33. QModelIndex index(int row, int column, QModelIndex const& parent={}) const override;
  34. QModelIndex parent(QModelIndex const& index) const override;
  35. int rowCount(QModelIndex const& parent={}) const override;
  36. int columnCount(QModelIndex const& parent={}) const override;
  37. void reset();
  38. protected:
  39. unique_ptr<core::AbstractAction> const& get_action(QModelIndex const& index) const;
  40. private:
  41. shared_ptr<core::ActionStack> action_stack;
  42. };
  43. } // namespace rainynite::studio
  44. #endif