Added new-undo == delete

This commit is contained in:
2025-09-04 17:01:01 +02:00
parent 89c5fd21f1
commit 5d2fb1b378
8 changed files with 116 additions and 84 deletions

View File

@@ -28,6 +28,8 @@
#include <xqviewmodel.h> #include <xqviewmodel.h>
//! firz
class XQItemEditorFactory : public QItemEditorFactory class XQItemEditorFactory : public QItemEditorFactory
{ {
public: public:
@@ -60,6 +62,7 @@ public:
}; };
//! firz
XQItemDelegate::XQItemDelegate( XQViewModel& modelView) XQItemDelegate::XQItemDelegate( XQViewModel& modelView)
: _modelView{modelView} : _modelView{modelView}
@@ -69,6 +72,8 @@ XQItemDelegate::XQItemDelegate( XQViewModel& modelView)
} }
//! firz
XQTreeTable* XQItemDelegate::treeTable() const XQTreeTable* XQItemDelegate::treeTable() const
{ {
return _modelView.treeTable(); return _modelView.treeTable();
@@ -81,6 +86,8 @@ XQItem& XQItemDelegate::xqItemFromIndex( const QModelIndex& index ) const
} }
//! firz
void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
if( !index.isValid() ) if( !index.isValid() )
@@ -108,12 +115,11 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
break; break;
} // switch } // switch
QStyledItemDelegate::paint(painter, option, index); QStyledItemDelegate::paint(painter, option, index);
} }
//! einen section header im header-style zeichnen //! einen section header im header-style zeichnen
void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
@@ -149,6 +155,9 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt
} }
} }
//! firz
void XQItemDelegate::drawProgressBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void XQItemDelegate::drawProgressBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
@@ -167,6 +176,9 @@ void XQItemDelegate::drawProgressBarStyle(QPainter *painter, const QStyleOptionV
} }
//! firz
void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
@@ -196,6 +208,8 @@ void XQItemDelegate::drawComboBoxStyle(QPainter *painter, const QStyleOptionView
painter->restore(); painter->restore();
} }
//! firz
void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
@@ -213,6 +227,8 @@ void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewI
} }
//! firz
QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
return QStyledItemDelegate::sizeHint(option, index); return QStyledItemDelegate::sizeHint(option, index);
@@ -238,14 +254,16 @@ QWidget* XQItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte
} }
//! //! Füttert einen editor mit den model-daten
void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{ {
XQItem& item = xqItemFromIndex( index ); XQItem& item = xqItemFromIndex( index );
XQItem::EditorType edType = item.editorType(); XQItem::EditorType edType = item.editorType();
if( edType != XQItem::NoEditorType ) if( edType == XQItem::NoEditorType )
{ return;
switch( edType ) switch( edType )
{ {
case XQItemType::ComboBoxType : case XQItemType::ComboBoxType :
@@ -258,7 +276,7 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co
} }
default: default:
//QStyledItemDelegate::setEditorData(editor, index);
// wir benutzen hier die DisplayRole wenn der Inhalt schon formatiert ist. // wir benutzen hier die DisplayRole wenn der Inhalt schon formatiert ist.
int role = item.renderStyle() == XQItem::FormattedStyle ? Qt::DisplayRole : Qt::EditRole; int role = item.renderStyle() == XQItem::FormattedStyle ? Qt::DisplayRole : Qt::EditRole;
QVariant value = index.data(role); QVariant value = index.data(role);
@@ -275,7 +293,8 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co
} }
}
//! Schreibt die daten aus dem editor ins model zurück
void XQItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const void XQItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{ {
@@ -284,7 +303,6 @@ void XQItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, co
switch( item.editorType() ) switch( item.editorType() )
{ {
case XQItem::ComboBoxType : case XQItem::ComboBoxType :
{ {
QComboBox* comboBox = qobject_cast<QComboBox*>(editor); QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
@@ -299,6 +317,9 @@ void XQItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, co
QStyledItemDelegate::setModelData(editor, model, index); QStyledItemDelegate::setModelData(editor, model, index);
} }
//! firz
void XQItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const void XQItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
//qDebug() << " --- update Editor Geometry"; //qDebug() << " --- update Editor Geometry";

View File

@@ -180,6 +180,28 @@ void XQViewModel::onToggleSection(const QString& sectionKey )
qDebug() << " --- onToggleSection: " << sectionKey; qDebug() << " --- onToggleSection: " << sectionKey;
} }
void XQViewModel::toggleSection( const XQModelSection& section )
{
if(_treeTable)
{
const QModelIndex& index = section.persistentModelIndex();
qDebug() << " ---- toggle section: FIRZ: " << index.isValid() << " : " << index.data().toString() << " : " << section.contentType();//_sections.keyOf( sec );
int fstRow = _sections.firstRow( index );
int lstRow = _sections.lastRow( index );
_treeTable->toggleRowsHidden(fstRow, lstRow );
emit sectionToggled( section );
}
emit sectionToggled( section );
}
void XQViewModel::toggleSection( const QString& sectionKey )
{
}
/* /*
//! SLOT als weiterleitung vom SIGNAL itemchanged //! SLOT als weiterleitung vom SIGNAL itemchanged
@@ -447,50 +469,33 @@ void XQViewModel::cmdNew( const XQCommand& command )
qDebug() << " --- node own pos: " << node->own_pos(); qDebug() << " --- node own pos: " << node->own_pos();
// we create a new data node // we create a new data node
XQNodePtr newNode = XQNode::make_node( node->tag_name(), node->tag_value(), node->parent() ); XQNodePtr newNode = XQNode::make_node( node->tag_name(), node->tag_value() );
// store node in node->parent() // store node in node->parent()
newNode->add_me_at( node->own_pos(), node->parent() ); newNode->add_me_at( node->own_pos(), node->parent() );
// store node also in 'command' to enable undo
//...
const XQModelSection& section = _sections.sectionFromIndex( origin ); const XQModelSection& section = _sections.sectionFromIndex( origin );
// create new item row // neue, leere zeile erzeugen ...
XQItemList list =_itemFactory.makeRow( section.sheetRootNode(), newNode ); XQItemList list =_itemFactory.makeRow( section.sheetRootNode(), newNode );
// ... zur treeview hinzufügen ...
// add it to the treeview ...
insertRow( origin.row(), list ); insertRow( origin.row(), list );
// ... editierbar machen ...
// ... and make it ... QModelIndex newIndex = list[0]->index();
treeTable()->setCurrentIndex( list[0]->index() ); treeTable()->setCurrentIndex( newIndex );
// ... editable treeTable()->edit( newIndex );
treeTable()->edit( list[0]->index() ); // ,,, und fürs undo speichern
const_cast<XQCommand&>(command).saveNodes( {newIndex} );
} }
void XQViewModel::toggleSection( const XQModelSection& section )
{
if(_treeTable)
{
const QModelIndex& index = section.persistentModelIndex();
qDebug() << " ---- toggle section: FIRZ: " << index.isValid() << " : " << index.data().toString() << " : " << section.contentType();//_sections.keyOf( sec );
int fstRow = _sections.firstRow( index );
int lstRow = _sections.lastRow( index );
_treeTable->toggleRowsHidden(fstRow, lstRow );
emit sectionToggled( section );
}
emit sectionToggled( section );
}
void XQViewModel::toggleSection( const QString& sectionKey )
{
}
//! entfernt die neu angelegte zeile. //! entfernt die neu angelegte zeile.
void XQViewModel::cmdNewUndo( const XQCommand& command ) void XQViewModel::cmdNewUndo( const XQCommand& command )
{ {
cmdDelete( command );
} }

View File

@@ -78,6 +78,7 @@ namespace znode
zweak_node _parent; zweak_node _parent;
znode_list _children; znode_list _children;
// functor, der auf pointer gleichheit prüft.
struct match_node struct match_node
{ {
match_node( zbasic_node* match ) match_node( zbasic_node* match )
@@ -95,9 +96,11 @@ namespace znode
public: public:
//! shortcut auf std::make_shared... //! shortcut auf std::make_shared...
static zshared_node make_node( str_cref arg1, str_cref arg2 = "" , zshared_cref parent = nullptr ) //! beachte: der eltern-knoten wird hier nicht gesetzt, der neue knoten
//! wird nirgends eingefügt.
static zshared_node make_node( str_cref arg1, str_cref arg2 = "" )
{ {
return std::make_shared<zbasic_node>( arg1, arg2, parent ); return std::make_shared<zbasic_node>( arg1, arg2 );
} }
//! leerer konstruktor //! leerer konstruktor
@@ -136,7 +139,7 @@ namespace znode
zbasic_node(const zbasic_node&) = delete; zbasic_node(const zbasic_node&) = delete;
zbasic_node& operator=(const zbasic_node&) = delete; zbasic_node& operator=(const zbasic_node&) = delete;
// 'move' geht (shared_from_this bleibt gültig) //! 'move' geht (shared_from_this bleibt gültig)
zbasic_node(zbasic_node&&) noexcept = default; zbasic_node(zbasic_node&&) noexcept = default;
zbasic_node& operator=(zbasic_node&&) noexcept = default; zbasic_node& operator=(zbasic_node&&) noexcept = default;
@@ -178,29 +181,31 @@ namespace znode
return _parent.lock(); return _parent.lock();
} }
//! gibt den nachfolge-knoten oder 'end()' zurück.
zshared_node sibling() zshared_node sibling()
{ {
if( parent() ) if( parent() )
{ {
znode_list& childs = _parent->_children; znode_list& childs = _parent->_children;
auto it = std::find( childs.begin(), childs.end(), this->shared_from_this() ); auto it = std::find( childs.begin(), childs.end(), this->shared_from_this() );
if( ++it != childs.end())
return *(it); return *(it);
} }
throw std::runtime_error("sibling(): no parent node");
return zshared_node();
} }
//! gibt den vector mit kind-knoten zurück
inline const znode_list& children() const inline const znode_list& children() const
{ {
return _children; return _children;
} }
//! testet, ob kinder vorhanden sind.
bool has_children() const bool has_children() const
{ {
return !children().empty(); return !children().empty();
} }
//! gibt das erste kind zurück
zshared_node first_child() zshared_node first_child()
{ {
if(!children().empty()) if(!children().empty())
@@ -208,6 +213,7 @@ namespace znode
return nullptr; return nullptr;
} }
//! gibt das letzte kind oder nullptr zurück
zshared_node last_child() zshared_node last_child()
{ {
if(!children().empty()) if(!children().empty())

View File

@@ -100,7 +100,7 @@ namespace znode
//parent->add_child( new_node ); //parent->add_child( new_node );
//zbasic_node<str_t>* new_node = new zbasic_node<str_t>( node.name(), node.child_value(), parent ); //zbasic_node<str_t>* new_node = new zbasic_node<str_t>( node.name(), node.child_value(), parent );
zshared_node new_node = zbasic_node<str_t>::make_node( xml_node.name(), xml_node.child_value(), parent ); zshared_node new_node = zbasic_node<str_t>::make_node( xml_node.name(), xml_node.child_value() );
parent->add_child( new_node ); parent->add_child( new_node );
if( !xml_node.attributes().empty() ) if( !xml_node.attributes().empty() )