Files
xtree.ng/src/model/xqviewmodel.h

128 lines
3.6 KiB
C
Raw Normal View History

2025-08-22 22:57:06 +02:00
/***************************************************************************
source::worx xtree
Copyright © 2024-2025 c.holzheuer
christoph.holzheuer@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#ifndef XQVIEWMODEL_H
#define XQVIEWMODEL_H
#include <QUndoStack>
#include <QMenu>
#include <QStandardItemModel>
#include <QAbstractItemView>
2025-08-26 17:45:06 +02:00
#include <QtQmlIntegration>
2025-08-22 22:57:06 +02:00
#include <xqsimpleclipboard.h>
2025-09-05 11:49:36 +02:00
#include <xqsectionmanager.h>
2025-08-22 22:57:06 +02:00
#include <xqitemfactory.h>
#include <xqcontextmenu.h>
class XQTreeTable;
class XQItem;
class XQCommand;
//! ein erweitertes QStandardItemModel welches 'seine' view bereits enthält.
class XQViewModel : public QStandardItemModel
{
Q_OBJECT
2025-08-26 19:41:28 +02:00
QML_ELEMENT
2025-08-22 22:57:06 +02:00
public:
XQViewModel(QObject* parent = nullptr);
virtual ~XQViewModel() = default;
2025-08-26 17:45:06 +02:00
QHash<int, QByteArray> roleNames() const override;
2025-08-22 22:57:06 +02:00
XQTreeTable* treeTable();
virtual void setTreeTable( XQTreeTable* mainView );
QUndoStack* undoStack();
void setUndoStack( QUndoStack* undoStack );
virtual void initModel( const QString& modelName);
2025-09-01 17:40:08 +02:00
void expandNewItem(const QModelIndex& index);
2025-09-05 21:42:40 +02:00
void toggleSection( const XQModelSection& section );
2025-09-01 17:40:08 +02:00
2025-08-22 22:57:06 +02:00
//little helpers
const XQItem& xqRootItem();
2025-09-04 14:56:18 +02:00
XQNodePtr contentRootNode();
2025-08-22 22:57:06 +02:00
XQItem& xqItemFromIndex(const QModelIndex& index) const;
XQItem& xqFirstItem(int row) const;
// undo-/redo-able stuff
2025-09-05 21:42:40 +02:00
virtual void cmdToggleSection( const XQCommand& command );
2025-08-26 19:41:28 +02:00
virtual void cmdCut( const XQCommand& command );
virtual void cmdCutUndo( const XQCommand& command );
virtual void cmdPaste( const XQCommand& command );
virtual void cmdPasteUndo( const XQCommand& command );
virtual void cmdDelete( const XQCommand& command );
virtual void cmdDeleteUndo( const XQCommand& command );
virtual void cmdNew( const XQCommand& command );
virtual void cmdNewUndo( const XQCommand& command );
2025-08-22 22:57:06 +02:00
2025-09-05 17:12:38 +02:00
// Derzeit wird die default-implementierung von data/setData genutzt. hier wäre dann die
// Stelle um setData & data an externe 'handler' umzubiegen, siehe giovannies 'model-injection'
2025-08-22 22:57:06 +02:00
2025-09-03 17:23:52 +02:00
signals:
2025-09-02 16:58:56 +02:00
2025-09-03 17:23:52 +02:00
void xqItemChanged( const XQItem& item );
2025-09-05 17:12:38 +02:00
void itemCreated( XQItem* newItem );
void sectionCreated( const XQModelSection& section );
void sectionToggled( const XQModelSection& section );
2025-09-02 16:58:56 +02:00
2025-08-22 22:57:06 +02:00
public slots:
virtual void onShowContextMenu(const QPoint& point);
virtual void onActionTriggered(QAction* action);
2025-09-01 17:40:08 +02:00
virtual void onToggleSection(const QString& sectionKey );
2025-08-22 22:57:06 +02:00
// handle XQCommands ( == UndoCommand )
2025-08-26 19:41:28 +02:00
virtual void onCommandRedo( const XQCommand& command );
virtual void onCommandUndo( const XQCommand& command );
2025-08-22 22:57:06 +02:00
protected:
void addSection(const XQItemList& list, const XQNodePtr& sheetNode );
2025-09-04 13:52:23 +02:00
virtual void initContextMenu() = 0;
2025-08-22 22:57:06 +02:00
// __fixme: should be created from xml
virtual void setupViewProperties();
protected:
2025-08-26 19:41:28 +02:00
using MemCall = void (XQViewModel::*)(const XQCommand&);
2025-08-22 22:57:06 +02:00
using MemCallMap = QMap<XQCommand::CmdType,MemCall>;
// das eine reference auf ein globales singleton
2025-09-05 11:49:36 +02:00
XQItemFactory& _itemFactory;
XQSimpleClipBoard _clipBoard;
XQSectionManager _sections;
2025-08-22 22:57:06 +02:00
2025-09-05 11:49:36 +02:00
XQTreeTable* _treeTable{};
2025-08-22 22:57:06 +02:00
//QAbstractItemView* _treeTable{};
QUndoStack* _undoStack{};
XQContextMenu* _contextMenu{};
//! Die Modelbeschreibung
XQNodePtr _modelSheet{};
//! Der eigentliche Inhalt
XQNodePtr _contentRoot{};
};
#endif // XQVIEWMODEL_H