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

149 lines
4.0 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>
#include <xqmodelsectionlist.h>
#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);
void toggleSection( const XQModelSection& section );
2025-08-22 22:57:06 +02:00
//little helpers
const XQItem& xqRootItem();
XQItem& xqItemFromIndex(const QModelIndex& index) const;
XQItem& xqFirstItem(int row) const;
// undo-/redo-able stuff
2025-08-26 19:41:28 +02:00
virtual void cmdToggleSection( const XQCommand& command );
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-08-26 17:45:06 +02:00
2025-08-22 22:57:06 +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'
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
{
return QStandardItemModel::data( index, role );
}
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override
{
qDebug() << " --- setData: " << value.toString();
return QStandardItemModel::setData( index, value, role );
}
*/
2025-09-02 16:58:56 +02:00
virtual void onItemChanged( XQItem& item ) = 0;
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
2025-09-02 16:58:56 +02:00
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
signals:
void itemCreated( XQItem* newItem );
void sectionCreated( const XQModelSection& section );
void sectionToggled( const XQModelSection& section );
protected:
void addSection(const XQItemList& list, const XQNodePtr& sheetNode );
2025-08-26 17:45:06 +02:00
virtual void initContextMenu(){}
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
XQItemFactory& _itemFactory;
XQSimpleClipBoard _clipBoard;
XQModelSectionList _sections;
XQTreeTable* _treeTable{};
//QAbstractItemView* _treeTable{};
QUndoStack* _undoStack{};
XQContextMenu* _contextMenu{};
//! Die Modelbeschreibung
XQNodePtr _modelSheet{};
//! Der eigentliche Inhalt
XQNodePtr _contentRoot{};
};
#endif // XQVIEWMODEL_H