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>
//! firz
class XQItemEditorFactory : public QItemEditorFactory
{
public:
@@ -60,6 +62,7 @@ public:
};
//! firz
XQItemDelegate::XQItemDelegate( XQViewModel& modelView)
: _modelView{modelView}
@@ -69,6 +72,8 @@ XQItemDelegate::XQItemDelegate( XQViewModel& modelView)
}
//! firz
XQTreeTable* XQItemDelegate::treeTable() const
{
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
{
if( !index.isValid() )
@@ -108,12 +115,11 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
break;
} // switch
QStyledItemDelegate::paint(painter, option, index);
}
//! einen section header im header-style zeichnen
void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
@@ -149,7 +155,10 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt
}
}
void XQItemDelegate::drawProgressBarStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
//! firz
void XQItemDelegate::drawProgressBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
int progress = index.data(XQItem::ContentRole ).toInt();
@@ -167,7 +176,10 @@ void XQItemDelegate::drawProgressBarStyle(QPainter *painter, const QStyleOptionV
}
void XQItemDelegate::drawComboBoxStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
//! firz
void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QWidget* srcWidget = qobject_cast<QWidget*>(option.styleObject);
@@ -196,6 +208,8 @@ void XQItemDelegate::drawComboBoxStyle(QPainter *painter, const QStyleOptionView
painter->restore();
}
//! firz
void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
@@ -213,7 +227,9 @@ void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewI
}
QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
//! firz
QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
return QStyledItemDelegate::sizeHint(option, index);
}
@@ -238,53 +254,55 @@ QWidget* XQItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte
}
//!
//! Füttert einen editor mit den model-daten
void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
XQItem& item = xqItemFromIndex( index );
XQItem::EditorType edType = item.editorType();
if( edType != XQItem::NoEditorType )
if( edType == XQItem::NoEditorType )
return;
switch( edType )
{
switch( edType )
case XQItemType::ComboBoxType :
{
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
comboBox->setModel( item.fixedChoices());
comboBox->setCurrentText( item.data().toString() );
comboBox->showPopup();
return;
}
default:
// wir benutzen hier die DisplayRole wenn der Inhalt schon formatiert ist.
int role = item.renderStyle() == XQItem::FormattedStyle ? Qt::DisplayRole : Qt::EditRole;
QVariant value = index.data(role);
QByteArray userProp = editor->metaObject()->userProperty().name();
if (!userProp.isEmpty())
{
case XQItemType::ComboBoxType :
{
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
comboBox->setModel( item.fixedChoices());
comboBox->setCurrentText( item.data().toString() );
comboBox->showPopup();
return;
}
default:
//QStyledItemDelegate::setEditorData(editor, index);
// wir benutzen hier die DisplayRole wenn der Inhalt schon formatiert ist.
int role = item.renderStyle() == XQItem::FormattedStyle ? Qt::DisplayRole : Qt::EditRole;
QVariant value = index.data(role);
QByteArray userProp = editor->metaObject()->userProperty().name();
if (!userProp.isEmpty())
{
if (!value.isValid())
value = QVariant(editor->property(userProp).metaType());
editor->setProperty(userProp, value);
}
if (!value.isValid())
value = QVariant(editor->property(userProp).metaType());
editor->setProperty(userProp, value);
}
}
}
void XQItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
//! Schreibt die daten aus dem editor ins model zurück
void XQItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{
XQItem& item = xqItemFromIndex( index );
switch( item.editorType() )
{
case XQItem::ComboBoxType :
{
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
@@ -299,6 +317,9 @@ void XQItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, co
QStyledItemDelegate::setModelData(editor, model, index);
}
//! firz
void XQItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
//qDebug() << " --- update Editor Geometry";

View File

@@ -37,19 +37,19 @@ public:
XQTreeTable* treeTable() const;
XQItem& xqItemFromIndex( const QModelIndex& index ) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void setEditorData(QWidget* editor, const QModelIndex& index) const override;
void setModelData(QWidget* editor, QAbstractItemModel *model, const QModelIndex& index) const override;
void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
protected:
void drawHeaderStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawProgressBarStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawComboBoxStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawSpinBoxStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void drawProgressBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
XQViewModel& _modelView;

View File

@@ -180,6 +180,28 @@ void XQViewModel::onToggleSection(const QString& 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
@@ -447,50 +469,33 @@ void XQViewModel::cmdNew( const XQCommand& command )
qDebug() << " --- node own pos: " << node->own_pos();
// 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()
newNode->add_me_at( node->own_pos(), node->parent() );
// store node also in 'command' to enable undo
//...
const XQModelSection& section = _sections.sectionFromIndex( origin );
// create new item row
// neue, leere zeile erzeugen ...
XQItemList list =_itemFactory.makeRow( section.sheetRootNode(), newNode );
// add it to the treeview ...
// ... zur treeview hinzufügen ...
insertRow( origin.row(), list );
// ... and make it ...
treeTable()->setCurrentIndex( list[0]->index() );
// ... editable
treeTable()->edit( list[0]->index() );
// ... editierbar machen ...
QModelIndex newIndex = list[0]->index();
treeTable()->setCurrentIndex( newIndex );
treeTable()->edit( newIndex );
// ,,, 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.
void XQViewModel::cmdNewUndo( const XQCommand& command )
{
cmdDelete( command );
}

View File

@@ -84,7 +84,7 @@ public:
Derzeit wird die default-implementierung von data/setData genutzt. hier wäre dann die
Stelle um setData & data an externe 'handler' umzubiegen, siehe giovannies 'model-injection'
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
{
return QStandardItemModel::data( index, role );
}

View File

@@ -78,6 +78,7 @@ namespace znode
zweak_node _parent;
znode_list _children;
// functor, der auf pointer gleichheit prüft.
struct match_node
{
match_node( zbasic_node* match )
@@ -95,9 +96,11 @@ namespace znode
public:
//! 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
@@ -136,7 +139,7 @@ namespace znode
zbasic_node(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& operator=(zbasic_node&&) noexcept = default;
@@ -178,29 +181,31 @@ namespace znode
return _parent.lock();
}
//! gibt den nachfolge-knoten oder 'end()' zurück.
zshared_node sibling()
{
if( parent() )
{
znode_list& childs = _parent->_children;
auto it = std::find( childs.begin(), childs.end(), this->shared_from_this() );
if( ++it != childs.end())
return *(it);
return *(it);
}
return zshared_node();
throw std::runtime_error("sibling(): no parent node");
}
//! gibt den vector mit kind-knoten zurück
inline const znode_list& children() const
{
return _children;
}
//! testet, ob kinder vorhanden sind.
bool has_children() const
{
return !children().empty();
}
//! gibt das erste kind zurück
zshared_node first_child()
{
if(!children().empty())
@@ -208,6 +213,7 @@ namespace znode
return nullptr;
}
//! gibt das letzte kind oder nullptr zurück
zshared_node last_child()
{
if(!children().empty())

View File

@@ -100,7 +100,7 @@ namespace znode
//parent->add_child( new_node );
//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 );
if( !xml_node.attributes().empty() )

View File

@@ -14,7 +14,7 @@
#include <xqquickwidget.h>
XQQuickWidget::XQQuickWidget(QWidget *parent)
XQQuickWidget::XQQuickWidget(QWidget* parent)
: QQuickWidget(parent)
{

View File

@@ -23,7 +23,7 @@ class XQQuickWidget : public QQuickWidget
public:
XQQuickWidget(QWidget *parent = nullptr);
XQQuickWidget(QWidget* parent = nullptr);
};
#endif // XQQUICKWIDGET_H