/*************************************************************************** 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. ***************************************************************************/ #include #include #include void XQNodeStore::dumpList( const QString& title ) const { if( !title.isEmpty() ) qDebug() << " --- " << title; for( const auto& entry : *this ) qDebug() << " -- dumpList: itemPos: " << entry.itemPos << " nodePos: " << entry.nodePos << " id: " << ( entry.contentNode ? entry.contentNode->_id : 0 ) << " used: " << ( entry.contentNode ? entry.contentNode.use_count() : 0 ); } XQCommand::XQCommand(CmdType cmdType, XQModel* modelView ) : _cmdType{ cmdType }, _modelView(modelView) { } XQCommand::~XQCommand() { qDebug() << " --- command destructor: " << toString(); } XQCommand::CmdType XQCommand::commandType() const { return _cmdType; } void XQCommand::setCommandType( XQCommand::CmdType cmdType ) { _cmdType = cmdType; } void XQCommand::redo() { _modelView->onCommandRedo( *this ); } void XQCommand::undo() { _modelView->onCommandUndo( *this ); } const QModelIndex& XQCommand::originIndex() const { return _originIndex; } void XQCommand::setOriginIndex( const QModelIndex& origin ) { QString cmdText("%1: %2 (%3)"); QString name = origin.data().toString(); QString items("%1 item%2"); int mySize = size(); items = items.arg(mySize).arg(mySize > 1 ? "s" : ""); cmdText = cmdText.arg( toString(), name, items ); _originIndex = origin; setText(cmdText); } void XQCommand::saveNodes( const QModelIndexList& list ) { clear(); for( auto entry : list ) { XQNodePtr contentNode = XQItem::xqItemFromIndex( entry ).contentNode(); // im command speichern wir den original knoten, nicht eine kopie, wie im clipboard. push_back( {entry.row(), contentNode->own_pos(), contentNode } ); } } QString XQCommand::toString() { static QMap s_CmdTypeMap { { cmdTextEdit, "cmdTextEdit" }, { cmdInvalid, "cmdInvalid" }, { cmdCut, "cmdCut" }, { cmdPaste, "cmdPaste" }, { cmdPasteSelf, "cmdPasteSelf" }, { cmdNew, "cmdNew" }, { cmdUndo, "cmdUndo" }, { cmdRedo, "cmdRedo" }, { cmdCopy, "cmdCopy" }, { cmdMove, "cmdMove" }, { cmdDelete, "cmdDelete" }, { cmdToggleSection, "cmdToggleSection" }, { cmdExtern, "cmdExtern" } }; if( !s_CmdTypeMap.contains( _cmdType )) return QString(" cmdType missmatch"); return s_CmdTypeMap[_cmdType]; }