135 lines
3.1 KiB
C++
135 lines
3.1 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.
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
#include <xqcommand.h>
|
|
#include <xqmodel.h>
|
|
#include <xqtreeview.h>
|
|
|
|
void XQSavedNodesList::dumpSavedNodesList( const QString& title )
|
|
{
|
|
if( !title.isEmpty() )
|
|
qDebug() << " --- " << title;
|
|
for( const auto& entry : *this )
|
|
qDebug() << " -- dumpSavedNodesList: 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() << " : " << _posList.size();
|
|
clearSavedNodes();
|
|
}
|
|
|
|
|
|
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 );
|
|
}
|
|
|
|
|
|
XQSavedNodesList& XQCommand::savedNodesList()
|
|
{
|
|
return _posList;
|
|
}
|
|
|
|
void XQCommand::saveNodes( const QModelIndexList& list )
|
|
{
|
|
_posList.clear();
|
|
for( auto entry : list )
|
|
{
|
|
XQNodePtr contentNode = XQItem::xqItemFromIndex( entry ).contentNode();
|
|
_posList.push_back( {entry.row(), contentNode->own_pos(), contentNode } );
|
|
}
|
|
}
|
|
|
|
void XQCommand::clearSavedNodes()
|
|
{
|
|
_posList.clear();
|
|
}
|
|
|
|
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 size = _posList.size();
|
|
items = items.arg(size).arg(size > 1 ? "s" : "");
|
|
cmdText = cmdText.arg( toString(), name, items );
|
|
_originIndex = origin;
|
|
setText(cmdText);
|
|
|
|
}
|
|
|
|
/*
|
|
XQNodeList& XQCommand::nodeList()
|
|
{
|
|
return _nodeList;
|
|
}
|
|
*/
|
|
|
|
QString XQCommand::toString()
|
|
{
|
|
|
|
static QMap<CmdType,QString> 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];
|
|
|
|
}
|