first commit, again.
This commit is contained in:
136
src/model/xqviewmodel.h
Normal file
136
src/model/xqviewmodel.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/***************************************************************************
|
||||
|
||||
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>
|
||||
|
||||
#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
|
||||
|
||||
public:
|
||||
|
||||
XQViewModel(QObject* parent = nullptr);
|
||||
virtual ~XQViewModel() = default;
|
||||
|
||||
XQTreeTable* treeTable();
|
||||
virtual void setTreeTable( XQTreeTable* mainView );
|
||||
|
||||
QUndoStack* undoStack();
|
||||
void setUndoStack( QUndoStack* undoStack );
|
||||
|
||||
virtual void initModel( const QString& modelName);
|
||||
|
||||
//little helpers
|
||||
const XQItem& xqRootItem();
|
||||
|
||||
XQItem& xqItemFromIndex(const QModelIndex& index) const;
|
||||
XQItem& xqFirstItem(int row) const;
|
||||
|
||||
// undo-/redo-able stuff
|
||||
|
||||
virtual void cmdToggleSection( XQCommand& command );
|
||||
virtual void cmdCut( XQCommand& command );
|
||||
virtual void cmdCutUndo( XQCommand& command );
|
||||
virtual void cmdPaste( XQCommand& command );
|
||||
virtual void cmdPasteUndo( XQCommand& command );
|
||||
virtual void cmdDelete( XQCommand& command );
|
||||
virtual void cmdDeleteUndo( XQCommand& command );
|
||||
virtual void cmdNew( XQCommand& command );
|
||||
virtual void cmdNewUndo( XQCommand& command );
|
||||
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
/*!
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void onShowContextMenu(const QPoint& point);
|
||||
virtual void onActionTriggered(QAction* action);
|
||||
|
||||
// handle XQCommands ( == UndoCommand )
|
||||
virtual void onCommandRedo( XQCommand& command );
|
||||
virtual void onCommandUndo( XQCommand& command );
|
||||
|
||||
signals:
|
||||
|
||||
void itemCreated( XQItem* newItem );
|
||||
void sectionCreated( const XQModelSection& section );
|
||||
void sectionToggled( const XQModelSection& section );
|
||||
|
||||
protected:
|
||||
|
||||
void addSection(const XQItemList& list, const XQNodePtr& sheetNode );
|
||||
virtual void initContextMenu() = 0;
|
||||
|
||||
// __fixme: should be created from xml
|
||||
virtual void setupViewProperties();
|
||||
|
||||
protected:
|
||||
|
||||
using MemCall = void (XQViewModel::*)(XQCommand&);
|
||||
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
|
Reference in New Issue
Block a user