146 lines
3.7 KiB
C++
146 lines
3.7 KiB
C++
/***************************************************************************
|
|
|
|
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 XQMODEL_H
|
|
#define XQMODEL_H
|
|
|
|
#include <QUndoStack>
|
|
#include <QMenu>
|
|
#include <QStandardItemModel>
|
|
|
|
#include <xqsimpleclipboard.h>
|
|
#include <xqmodelsections.h>
|
|
#include <xqitemfactory.h>
|
|
#include <xqcontextmenu.h>
|
|
|
|
|
|
class XQTreeView;
|
|
class XQItem;
|
|
class XQCommand;
|
|
|
|
|
|
/**
|
|
* @brief Abstract baseclass of all modelviews: Extends QStandardItemModel with a treeview.
|
|
*/
|
|
|
|
// might be own implementation of QAbstractItemModel, not done yet.
|
|
//using QStandardItemModel = XQSimpleItemModel;
|
|
using QStandardItemModel = QStandardItemModel;
|
|
|
|
/**
|
|
* @brief The XQModel class: An extendend QStandardItem model
|
|
* containing its own view.
|
|
*/
|
|
|
|
class XQModel : public QStandardItemModel
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
XQModel(QObject* parent = nullptr);
|
|
virtual ~XQModel();
|
|
|
|
XQTreeView* treeView();
|
|
virtual void setTreeView( XQTreeView* mainView );
|
|
|
|
QUndoStack* undoStack();
|
|
void setUndoStack( QUndoStack* undoStack );
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
//! create the own model structure
|
|
virtual void initModel( const QString& modelName) = 0;
|
|
|
|
//little helpers
|
|
const XQItem& xqRootItem();
|
|
|
|
XQItem& xqItemFromIndex(const QModelIndex& index) const;
|
|
const XQItem& xqConstItemFromIndex(const QModelIndex& index) const;
|
|
|
|
XQItem& xqItemFromRow(int row) const;
|
|
const XQItem& xqConstItemFromRow(int row) const;
|
|
|
|
// was ist das?
|
|
QString fetchNodeAttribute(int row, const QString& key );
|
|
QString fetchNodeTagName(int row );
|
|
|
|
// undo-/redo-able stuff
|
|
|
|
virtual void cmdToggleSection( const QModelIndex& index );
|
|
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 );
|
|
|
|
// wtf!?
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override
|
|
{
|
|
qDebug() << " --- setData: " << value.toString();
|
|
return QStandardItemModel::setData( index, value, role );
|
|
}
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
|
|
{
|
|
return QStandardItemModel::data( index, 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 xqItemCreated( XQItem* newItem );
|
|
|
|
protected:
|
|
|
|
void addSection(const XQItemList& list, const XQNodePtr& sheetNode );
|
|
|
|
protected:
|
|
|
|
virtual void initContextMenu() = 0;
|
|
|
|
// __fixme: should be created from xml
|
|
virtual void setupViewProperties();
|
|
|
|
protected:
|
|
|
|
// das eine reference auf ein globales singleton
|
|
XQItemFactory& _itemFactory;
|
|
XQSimpleClipBoard _clipBoard;
|
|
XQModelSections _sections;
|
|
|
|
XQTreeView* _treeView{};
|
|
QUndoStack* _undoStack{};
|
|
XQContextMenu* _contextMenu{};
|
|
|
|
//! Die Modelbeschreibung
|
|
XQNodePtr _modelSheet{};
|
|
//! Der eigentliche Inhalt
|
|
XQNodePtr _contentRoot{};
|
|
|
|
};
|
|
|
|
#endif // XQMODEL_H
|