major 'firzifikation'

This commit is contained in:
2025-08-07 10:39:42 +02:00
parent e7213c60b8
commit d70df0cbaa
21 changed files with 208 additions and 80 deletions

View File

@@ -17,6 +17,8 @@
#include <xqtreetable.h>
//! firz
void XQNodeStore::dumpList( const QString& title ) const
{
if( !title.isEmpty() )
@@ -26,23 +28,34 @@ void XQNodeStore::dumpList( const QString& title ) const
}
//! firz
XQCommand::XQCommand(CmdType cmdType, XQViewModel* modelView )
: _cmdType{ cmdType }, _model(modelView)
{
}
//! firz
XQCommand::~XQCommand()
{
qDebug() << " --- command destructor: " << toString();
}
//! firz
XQCommand::CmdType XQCommand::commandType() const
{
return _cmdType;
}
//! firz
void XQCommand::setCommandType( XQCommand::CmdType cmdType )
{
_cmdType = cmdType;
@@ -105,6 +118,7 @@ void XQCommand::saveNodes( const QModelIndexList& list )
}
}
//! erzeugt einen string aus dem command-type, fürs debuggen.
QString XQCommand::toString()

View File

@@ -16,6 +16,8 @@
#include <xqitem.h>
//! firz
XQModelSection::XQModelSection(const QModelIndex& aModelIndex, XQNodePtr aSheetNode)
: modelIndex{ aModelIndex }, sheetRootNode{ aSheetNode }
{
@@ -23,24 +25,32 @@ XQModelSection::XQModelSection(const QModelIndex& aModelIndex, XQNodePtr aSheetN
}
//! firz
bool XQModelSection::operator==(const XQModelSection& other) const
{
return modelIndex == other.modelIndex && sheetRootNode == other.sheetRootNode;
}
//! firz
bool XQModelSection::isValid() const
{
return modelIndex.isValid() && sheetRootNode;
}
//! firz
int XQModelSection::XQModelSection::row() const
{
return modelIndex.row();
}
//! firz
XQItem& XQModelSection::XQModelSection::headerItem() const
{
return XQItem::xqItemFromIndex( modelIndex );

View File

@@ -17,6 +17,9 @@
//! firz
void inspect( const XQNodePtr& node, int indent )
{
qDebug() << std::string(indent * 2, ' ').c_str() << node.use_count() << ": " << node->to_string();
@@ -31,6 +34,10 @@ void inspect( const XQNodePtr& node, int indent )
}
//! firz
// Overload the operator<< for MyClass and std::ostream
std::ostream& operator<<(std::ostream& os, const QString& obj)
{
@@ -40,8 +47,7 @@ std::ostream& operator<<(std::ostream& os, const QString& obj)
}
//! firz
template<>
bool znode::zpayload<QString>::xstr_split_by(const QString& entry, const QString& sep, QString& key, QString& value )
{
@@ -53,12 +59,18 @@ bool znode::zpayload<QString>::xstr_split_by(const QString& entry, const QString
return true;
}
//! firz
template<>
QString znode::zpayload<QString>::xstr_sub_str( const QString& entry, int pos ) const
{
return entry.mid(pos);
}
//! firz
template<>
bool znode::zpayload<QString>::xstr_is_empty(const QString& entry ) const
{
@@ -66,6 +78,8 @@ bool znode::zpayload<QString>::xstr_is_empty(const QString& entry ) const
}
//! firz
template<>
const QString znode::zpayload<QString>::cType = "Type";

View File

@@ -20,6 +20,10 @@
#include <xqnode.h>
//! firz
void XQNodeWriter::dumpTree( XQNodePtr rootNode, const QString& fileName ) const
{
QFile treeFile( fileName );
@@ -36,6 +40,7 @@ void XQNodeWriter::dumpTree( XQNodePtr rootNode, const QString& fileName ) const
treeFile.close();
}
//! firz
void XQNodeWriter::dumpNode( QXmlStreamWriter& writer, XQNodePtr node ) const
{

View File

@@ -15,12 +15,19 @@
#include <xqselectionmodel.h>
#include <xqitem.h>
//! firz
XQSelectionModel::XQSelectionModel(QAbstractItemModel* model)
: QItemSelectionModel(model)
{
}
//! firz
XQSelectionModel::XQSelectionModel(QAbstractItemModel* model, QObject* parent)
: QItemSelectionModel(model, parent)
{
@@ -28,6 +35,7 @@ XQSelectionModel::XQSelectionModel(QAbstractItemModel* model, QObject* parent)
}
//! firz
void XQSelectionModel::select(const QItemSelection& selection, QItemSelectionModel::SelectionFlags command)
{
@@ -58,8 +66,5 @@ void XQSelectionModel::select(const QItemSelection& selection, QItemSelectionMod
}
return QItemSelectionModel::select(newSelection, command);
}
QItemSelectionModel::select(selection, command);
}

View File

@@ -16,6 +16,8 @@
#include <xqviewmodel.h>
//! firz
bool XQSimpleClipBoard::canPaste( const QModelIndex& curIdx ) const
{
bool pasteOk = false;
@@ -36,6 +38,8 @@ bool XQSimpleClipBoard::canPaste( const QModelIndex& curIdx ) const
}
//! firz
void XQSimpleClipBoard::saveNodes( const QModelIndexList& list )
{
clear();

View File

@@ -30,6 +30,8 @@
//Q_GLOBAL_STATIC(XQItem,s_dummyItem)
//! firz
void showItemList( const XQItemList& list)
{
for(const auto& entry : list )
@@ -38,11 +40,15 @@ void showItemList( const XQItemList& list)
}
//! firz
XQViewModel::~XQViewModel()
{
}
//! firz
XQViewModel::XQViewModel( QObject* parent )
: QStandardItemModel{ parent }, _itemFactory{ XQItemFactory::instance() }
{
@@ -51,6 +57,8 @@ XQViewModel::XQViewModel( QObject* parent )
}
//! firz
const XQItem& XQViewModel::xqRootItem()
{
// das ist ein hack, denn 'invisibleRootItem()' ist und bleibt ein
@@ -62,6 +70,8 @@ const XQItem& XQViewModel::xqRootItem()
}
//! firz
XQItem& XQViewModel::xqItemFromIndex(const QModelIndex& index) const
{
if( index.isValid() )
@@ -73,17 +83,21 @@ XQItem& XQViewModel::xqItemFromIndex(const QModelIndex& index) const
return XQItem::fallBackDummyItem();
}
//! firz
XQItem& XQViewModel::xqFirstItem(int row) const
{
return *static_cast<XQItem*>( QStandardItemModel::item(row) );
}
//! firz
void XQViewModel::onActionTriggered(QAction* action)
{
qDebug() << " --- onActionTriggered: count:" << XQNode::s_Count;
// all selected indices
QModelIndexList selectionList = treeView()->selectionModel()->selectedRows();
QModelIndexList selectionList = treeTable()->selectionModel()->selectedRows();
// extract command type
XQCommand::CmdType cmdType = action->data().value<XQCommand::CmdType>();
@@ -115,7 +129,7 @@ void XQViewModel::onActionTriggered(QAction* action)
XQCommand* command = new XQCommand( cmdType, this );
// store the row positions of the selected indices
command->saveNodes( selectionList );
command->setOriginIndex( treeView()->currentIndex() );
command->setOriginIndex( treeTable()->currentIndex() );
// execute command
_undoStack->push( command );
@@ -129,6 +143,8 @@ void XQViewModel::onActionTriggered(QAction* action)
* @param command the current command
*/
//! firz
void XQViewModel::onCommandRedo( XQCommand& command )
{
try
@@ -171,6 +187,8 @@ void XQViewModel::onCommandRedo( XQCommand& command )
* @param command the command to be undone.
*/
//! firz
void XQViewModel::onCommandUndo( XQCommand& command )
{
qDebug() << " --- onCommandUndo: count: " << XQNode::s_Count;
@@ -220,6 +238,7 @@ void XQViewModel::onCommandUndo( XQCommand& command )
// undo-/redo-able stuff
//! markierte knoten entfernen, 'command' enthält die liste
void XQViewModel::cmdCut( XQCommand& command )
{
// wir gehen rückwärts über alle gemerkten knoten ...
@@ -265,7 +284,7 @@ void XQViewModel::cmdCutUndo( XQCommand& command )
void XQViewModel::cmdPaste( XQCommand& command )
{
// selection holen ...
QItemSelectionModel* selectionModel = treeView()->selectionModel();
QItemSelectionModel* selectionModel = treeTable()->selectionModel();
// ... und löschen
selectionModel->clearSelection();
@@ -289,7 +308,7 @@ void XQViewModel::cmdPaste( XQCommand& command )
insertRow( insRow, list );
// die neue item-row selektieren
const QModelIndex& selIdx = list[0]->index();
_treeView->selectionModel()->select(selIdx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
_treeTable->selectionModel()->select(selIdx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
// zur nächsten zeile
insRow++;
nodePos++;
@@ -322,6 +341,8 @@ void XQViewModel::cmdPasteUndo( XQCommand& command )
// don't clone into clipboard, remove items
//! firz
void XQViewModel::cmdDelete( XQCommand& command )
{
// wir gehen rückwärts über alle markieren knoten ...
@@ -337,6 +358,8 @@ void XQViewModel::cmdDelete( XQCommand& command )
}
}
//! firz
void XQViewModel::cmdDeleteUndo( XQCommand& command )
{
@@ -348,6 +371,8 @@ void XQViewModel::cmdDeleteUndo( XQCommand& command )
* @param command the command
*/
//! firz
void XQViewModel::cmdNew( XQCommand& command )
{
@@ -376,17 +401,21 @@ void XQViewModel::cmdNew( XQCommand& command )
insertRow( origin.row(), list );
// ... and make it ...
treeView()->setCurrentIndex( list[0]->index() );
treeTable()->setCurrentIndex( list[0]->index() );
// ... editable
treeView()->edit( list[0]->index() );
treeTable()->edit( list[0]->index() );
*/
}
//! firz
void XQViewModel::cmdNewUndo( XQCommand& command )
{
}
//! firz
void XQViewModel::cmdToggleSection( const QModelIndex& index )
{
Q_ASSERT(index.isValid());
@@ -394,31 +423,35 @@ void XQViewModel::cmdToggleSection( const QModelIndex& index )
int fstRow = _sections.firstRow( index );
int lstRow = _sections.lastRow( index );
bool hidden =_treeView->isRowHidden( fstRow, _treeView->rootIndex() );
bool hidden =_treeTable->isRowHidden( fstRow, _treeTable->rootIndex() );
for (int row = fstRow; row < lstRow; ++row )
_treeView->setRowHidden( row, _treeView->rootIndex(), !hidden );
_treeTable->setRowHidden( row, _treeTable->rootIndex(), !hidden );
}
XQTreeTable* XQViewModel::treeView()
//! firz
XQTreeTable* XQViewModel::treeTable()
{
return _treeView;
return _treeTable;
}
void XQViewModel::setTreeView(XQTreeTable* mainView )
//! firz
void XQViewModel::setTreeTable(XQTreeTable* mainView )
{
// store view for direct access: the maintree
_treeView = mainView;
_treeTable = mainView;
// connect myself as model to the mainview
_treeView->setModel(this);
_treeTable->setModel(this);
XQItemDelegate* delegate = new XQItemDelegate( *this );
_treeView->setItemDelegate( delegate );
_treeTable->setItemDelegate( delegate );
_contextMenu = new XQContextMenu( mainView );
connect( _treeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onShowContextMenu(QPoint)));
//connect( _treeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClicked(QModelIndex)) );
connect( _treeTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onShowContextMenu(QPoint)));
//connect( _treeTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClicked(QModelIndex)) );
connect(_contextMenu, SIGNAL(triggered(QAction*)), this, SLOT(onActionTriggered(QAction*)));
// __fixme, die view soll über das modelsheet konfiguriert werden!
@@ -430,17 +463,21 @@ void XQViewModel::setTreeView(XQTreeTable* mainView )
* edit triggers and so on.
*/
//! firz
void XQViewModel::setupViewProperties()
{
_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
_treeView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
_treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
//_treeView->setSelectionMode(QAbstractItemView::ContiguousSelection);
_treeView->setSelectionModel( new XQSelectionModel(this) );
_treeTable->setContextMenuPolicy(Qt::CustomContextMenu);
_treeTable->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
_treeTable->setSelectionBehavior(QAbstractItemView::SelectRows);
_treeTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
//_treeTable->setSelectionMode(QAbstractItemView::ContiguousSelection);
_treeTable->setSelectionModel( new XQSelectionModel(this) );
}
//! firz
void XQViewModel::addSection( const XQItemList& list, const XQNodePtr& sheetNode )
{
appendRow(list);
@@ -448,25 +485,32 @@ void XQViewModel::addSection( const XQItemList& list, const XQNodePtr& sheetNode
}
//! firz
QUndoStack* XQViewModel::undoStack()
{
return _undoStack;
}
//! firz
void XQViewModel::setUndoStack( QUndoStack* undoStack )
{
_undoStack = undoStack;
}
//! firz
void XQViewModel::onShowContextMenu(const QPoint& point)
{
initContextMenu();
_contextMenu->popup(_treeView->mapToGlobal(point));
_contextMenu->popup(_treeTable->mapToGlobal(point));
}
//! firz
QHash<int, QByteArray> XQViewModel::roleNames() const
{

View File

@@ -52,8 +52,8 @@ public:
XQViewModel(QObject* parent = nullptr);
virtual ~XQViewModel();
XQTreeTable* treeView();
virtual void setTreeView( XQTreeTable* mainView );
XQTreeTable* treeTable();
virtual void setTreeTable( XQTreeTable* mainView );
QUndoStack* undoStack();
void setUndoStack( QUndoStack* undoStack );
@@ -125,7 +125,7 @@ protected:
XQSimpleClipBoard _clipBoard;
XQModelSections _sections;
XQTreeTable* _treeView{};
XQTreeTable* _treeTable{};
QUndoStack* _undoStack{};
XQContextMenu* _contextMenu{};