added some comments.

This commit is contained in:
2025-08-06 16:44:08 +02:00
parent 87de9c1f33
commit f41b00d8ff
5 changed files with 90 additions and 44 deletions

View File

@@ -27,12 +27,11 @@ void XQNodeStore::dumpList( const QString& title ) const
XQCommand::XQCommand(CmdType cmdType, XQModel* modelView )
: _cmdType{ cmdType }, _modelView(modelView)
: _cmdType{ cmdType }, _model(modelView)
{
}
XQCommand::~XQCommand()
{
qDebug() << " --- command destructor: " << toString();
@@ -49,22 +48,34 @@ void XQCommand::setCommandType( XQCommand::CmdType cmdType )
_cmdType = cmdType;
}
//! ruft 'onCommandRedo' 'meines' models auf.
void XQCommand::redo()
{
_modelView->onCommandRedo( *this );
_model->onCommandRedo( *this );
}
//! ruft 'onCommandUndo' 'meines' models auf.
void XQCommand::undo()
{
_modelView->onCommandUndo( *this );
_model->onCommandUndo( *this );
}
//! gibt den urpsrungs-index dieses commands zurück.
const QModelIndex& XQCommand::originIndex() const
{
return _originIndex;
}
//! merkt sich den ersten QModelIndex der von diesem command
//! betroffenen items. zusätzlich wird der command-text erzeugt.
void XQCommand::setOriginIndex( const QModelIndex& origin )
{
QString cmdText("%1: %2 (%3)");
@@ -78,17 +89,24 @@ void XQCommand::setOriginIndex( const QModelIndex& origin )
}
//! erzeugt aus den 'selected indices' eine liste mit der jewiligen knotenposition,
//! der item-zeile und dem content-knoten.
void XQCommand::saveNodes( const QModelIndexList& list )
{
clear();
// über jede zeil
for( auto entry : list )
{
XQNodePtr contentNode = XQItem::xqItemFromIndex( entry ).contentNode();
// im command speichern wir den original knoten, nicht eine kopie, wie im clipboard.
// knoten holen
const XQNodePtr& contentNode = XQItem::xqItemFromIndex( entry ).contentNode();
// hier speichern wir den original knoten, nicht einen clone, wie im clipboard.
push_back( {entry.row(), contentNode->own_pos(), contentNode } );
}
}
//! erzeugt einen string aus dem command-type, fürs debuggen.
QString XQCommand::toString()
{

View File

@@ -85,7 +85,7 @@ public:
protected:
CmdType _cmdType{cmdInvalid};
XQModel* _modelView{}; // needed for redo() / undo()
XQModel* _model{}; // needed for redo() / undo()
QModelIndex _originIndex;
/*

View File

@@ -255,52 +255,47 @@ void XQModel::onCommandUndo( XQCommand& command )
// undo-/redo-able stuff
/**
* @brief XQModel::cmdCutRows Cut the rows whose positions have been store in the command.
* @param command
*/
//! markierte knoten entfernen, 'command' enthält die liste
void XQModel::cmdCut( XQCommand& command )
{
// wir gehen rückwärts über alle gemerkten knoten ...
for (auto it = command.rbegin(); it != command.rend(); ++it)
{
// ... holen das erste item, das auch den content node enthält
const XQNodeBackup& entry = *it;
XQItem& firstItem = xqFirstItem( (*it).itemPos );
qDebug() << " --- Cut: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id;
//const XQNodeBackup& entry = *it;
//XQItem& firstItem = xqFirstItem( (*it).itemPos );
//qDebug() << " --- Cut: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id;
// jetzt löschen, dabei wird die parent-verbindung entfernt
const XQNodeBackup& entry = *it;
entry.contentNode->unlink_self();
removeRow(entry.itemPos );
}
}
// clone to clipboard, remove items
//! entfernte knoten aus wieder einfügen , 'command' enthält die liste
void XQModel::cmdCutUndo( XQCommand& command )
{
command.dumpList("UNDO Cut");
_sections.dump();
int xx = command.first().itemPos;
const XQModelSection& section = _sections.sectionFromRow( xx );
// die anfangsposition
int itmPos = command.first().itemPos;
// die 'zuständige' section rausfinden
const XQModelSection& section = _sections.sectionFromRow( itmPos );
// über alle einträge ...
for (auto& entry : command )
{
XQNodePtr savedNode = entry.contentNode;
// __fix! should not bee _contentRoot!
savedNode->add_me_at( entry.nodePos, _contentRoot );
const XQNodePtr& savedNode = entry.contentNode;
// __fix! should not be _contentRoot!
savedNode->add_me_at( entry.nodePos, _contentRoot );
XQItemList list = _itemFactory.makeContentRow( savedNode, section.sheetRootNode );
XQItem& firstItem = *((XQItem*)list[0]);
qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id;
qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count();
insertRow( entry.itemPos, list );
}
}
//! clipboard inhalte einfügen
void XQModel::cmdPaste( XQCommand& command )
{
// selection holen ...
@@ -320,11 +315,19 @@ void XQModel::cmdPaste( XQCommand& command )
// wir pasten das clipboard
for (auto& entry : _clipBoard )
{
//
// siehe! und es war schrott!
//
// das ist ein clon
XQNodePtr savedNode = entry.contentNode;
// der wir hier rein gelinkt
XQItemList list = _itemFactory.makeContentRow( savedNode, section.sheetRootNode );
// wir klonen den knoten aus dem clipbord
savedNode->clone(section.contentRootNode )->add_me_at( nodePos );
insertRow( insRow, list );
const QModelIndex& selIdx = list[0]->index();
_treeView->selectionModel()->select(selIdx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
// zur nächsten zeile

View File

@@ -85,7 +85,7 @@ public:
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();
@@ -96,6 +96,7 @@ public:
{
return QStandardItemModel::data( index, role );
}
*/
public slots: