From 95b7b026ff6915b29c4b055c9dd8e62272924153 Mon Sep 17 00:00:00 2001 From: Christoph Holzheuer Date: Mon, 8 Sep 2025 15:42:15 +0200 Subject: [PATCH] --- mess --- src/application/xqmainwindow.cpp | 25 ++++++++- src/items/xqitemdelegate.cpp | 95 ++++++++++++++++++++++---------- src/items/xqitemfactory.cpp | 2 - src/model/xqsectionmanager.cpp | 1 - src/model/xqviewmodel.cpp | 8 +-- xml/modeldata1.xtr | 2 +- xml/modelsheets.xml | 20 +++---- xml/saved_testfile.xtr | 48 ++++++++-------- 8 files changed, 124 insertions(+), 77 deletions(-) diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index 987e420..b2ae636 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -127,6 +127,7 @@ void XQMainWindow::initMainWindow() loadDocument( c_DocumentFileName1 ); //loadDocumentQML( c_DocumentFileName2 ); //loadDocument( c_DocumentFileName2 ); + //loadDocument( c_DocumentFileName3 ); qDebug() << " --- all here: " << XQNode::s_Count; @@ -299,7 +300,6 @@ void XQMainWindow::onChildViewTabClicked( int idx ) void XQMainWindow::onSectionCreated( const XQModelSection& section ) { - //qDebug() << " --- XXX section created: " << section.contentType() << ":" << section.sheetRootNode()->to_string(); if( _currentProjectItem ) { _mainModel.addSectionItem( section, _currentProjectItem ); @@ -312,10 +312,31 @@ void XQMainWindow::onSectionCreated( const XQModelSection& section ) void XQMainWindow::onSectionToggled( const XQModelSection& section ) { qDebug() << " --- XXX section toggled: " << section.contentType() << ":" << section.sheetRootNode()->to_string(); + if( _currentProjectItem ) + { + + qDebug() << " --- XXX section toggled 2: " << _currentProjectItem->text(); + for (int row = 0; row < _currentProjectItem->rowCount(); ++row) + { + QStandardItem* child = _currentProjectItem->child(row); + qDebug() << " --- XXX section toggled 3: " << child->text(); + if (child->text() == section.contentType() ) + { + // rekursion vermeiden + _currentProjectItem->model()->blockSignals( true ); + bool checked = (child->checkState() == Qt::Checked); + qDebug() << " --- XXX section toggled 4: " << child->text() << " ->" << checked; + child->setCheckState( checked ? Qt::Unchecked :Qt::Checked ); + _currentProjectItem->model()->blockSignals( false ); + _mainTreeView->repaint(); + break; + } + } + } } -//! firz +//! aktiviert das tab, das zum dokument mit dem schlüssel 'key' gehört. void XQMainWindow::setChildTabByName( const QString& key ) { diff --git a/src/items/xqitemdelegate.cpp b/src/items/xqitemdelegate.cpp index a88d9bf..fbc15d4 100644 --- a/src/items/xqitemdelegate.cpp +++ b/src/items/xqitemdelegate.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -39,7 +40,8 @@ public: registerEditor(XQItem::LineEditType, new QStandardItemEditorCreator()); registerEditor(XQItem::ComboBoxType, new QStandardItemEditorCreator()); registerEditor(XQItem::PickerType, new QStandardItemEditorCreator()); - registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator()); + //registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator()); + registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator()); registerEditor(XQItem::SpinBoxType, new QStandardItemEditorCreator()); registerEditor(XQItem::CustomEditorType, new QStandardItemEditorCreator()); } @@ -91,11 +93,15 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option case XQItem::ComboBoxStyle : return drawComboBoxStyle( painter, option, index ); + case XQItem::SpinBoxStyle : + return drawSpinBoxStyle( painter, option, index ); + + case XQItem::ProgressBarStyle : + return drawProgressBarStyle( painter, option, index ); + case XQItem::HiddenStyle : return; - //case XQItem::ProgressBarStyle : - // return drawProgressBarStyle( painter, option, index ); default: @@ -113,8 +119,7 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt { QStyleOptionHeader headerOption; - XQItem& item = xqItemFromIndex( index ); - + XQItem& item = xqItemFromIndex( index ); // use the header as "parent" for style init QWidget* srcWidget = treeTable();//->header(); headerOption.initFrom(srcWidget); @@ -147,40 +152,44 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt void XQItemDelegate::drawProgressBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + QStyleOptionProgressBar progressBarOption; + progressBarOption.rect = option.rect; + progressBarOption.state = option.state; + progressBarOption.direction = option.direction; + progressBarOption.fontMetrics = option.fontMetrics; + progressBarOption.palette = option.palette; + progressBarOption.styleObject = option.styleObject; + progressBarOption.minimum = 0; + progressBarOption.maximum = 100; + progressBarOption.progress = 67; // Fester Wert + progressBarOption.text = QStringLiteral("67%"); + progressBarOption.textVisible = true; + progressBarOption.textAlignment = Qt::AlignCenter; - int progress = index.data(XQItem::ContentRole ).toInt(); + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter); - QStyleOptionProgressBar progressBarOption; - progressBarOption.rect = option.rect; - progressBarOption.minimum = 0; - progressBarOption.maximum = 100; - progressBarOption.progress = progress; - progressBarOption.text = QString::number(progress) + "%"; - progressBarOption.textAlignment = Qt::AlignCenter; - progressBarOption.textVisible = true; - QApplication::style()->drawControl(QStyle::CE_ProgressBar,&progressBarOption, painter); } -//! firz +//! Zeichnet das Item als combo box. void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - QWidget* srcWidget = qobject_cast(option.styleObject); QStyleOptionComboBox comboOption; QStyle* comboStyle = srcWidget->style(); comboOption.initFrom(srcWidget); + XQItem& item = xqItemFromIndex( index ); // set options comboOption.rect = option.rect; comboOption.state = option.state | QStyle::State_Selected | QStyle::State_Enabled; // not editable => only visual, but painter needs to know it comboOption.editable = false; - comboOption.currentText = index.data(Qt::DisplayRole).toString(); + comboOption.currentText = item.text();//index.data(Qt::DisplayRole).toString(); // decoration (if any) comboOption.currentIcon = qvariant_cast(index.data(Qt::DecorationRole)); comboOption.iconSize = comboOption.currentIcon.actualSize(QSize(option.rect.height() - 3, option.rect.height() - 3)); @@ -195,26 +204,52 @@ void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionView painter->restore(); } -//! firz + +//! Zeichnet das Item als spin box. void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + qDebug() << " --- jawas? SPINBOX!"; + bool isInt = false; + // Den Wert aus dem Modell holen. + QString textToShow = index.data(Qt::DisplayRole).toString(); + textToShow.toInt(&isInt); - // xx_fix! - //int value = index.data(XQItem::ContentRole ).toInt(); - QStyleOptionSpinBox spinBoxOption; - spinBoxOption.rect = option.rect; - /* - spinBoxOption.text = QString::number(value); - spinBoxOption.textAlignment = Qt::AlignCenter; - spinBoxOption.textVisible = true; - */ + if (isInt) { + // ----- Schritt 1: Den Rahmen und die Pfeile der SpinBox zeichnen ----- + QStyleOptionSpinBox spinBoxOption; + spinBoxOption.rect = option.rect; + spinBoxOption.state = option.state; + spinBoxOption.buttonSymbols = QAbstractSpinBox::UpDownArrows; + spinBoxOption.stepEnabled = QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled; + spinBoxOption.frame = true; - QApplication::style()->drawComplexControl(QStyle::CC_SpinBox,&spinBoxOption, painter); + // Zeichnet den "komplexen" Teil des Steuerelements (Rahmen, Hintergrund, Pfeile) + QApplication::style()->drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr); + + + // ----- Schritt 2: Den Text an der richtigen Position zeichnen ----- + + // Ermitteln, wo genau das Textfeld innerhalb des Widgets gezeichnet werden soll. + QRect textRect = QApplication::style()->subControlRect( + QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, nullptr + ); + + // Einen kleinen Innenabstand für den Text hinzufügen für besseres Aussehen. + textRect.adjust(2, 0, -2, 0); + + // Den Text aus dem Modell in das ermittelte Rechteck zeichnen. + // Die Flags sorgen für die korrekte Ausrichtung (rechtsbündig, vertikal zentriert). + painter->drawText(textRect, Qt::AlignRight | Qt::AlignVCenter, textToShow); + + } else { + // Fallback für alle anderen Datentypen. + QStyledItemDelegate::paint(painter, option, index); + } } -//! firz +//! Überschreibt QStyledItemDelegate::sizeHint(option, index); QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index f1d74e0..fcfc7ee 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -215,7 +215,6 @@ QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const case XQItem::FixedChoicesRole: { - qDebug() << " --- DREKC: " << source; const QStringList choices = source.split( '|' ); QStandardItemModel* fixedChoices = new QStandardItemModel(); @@ -226,7 +225,6 @@ QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const } /* - case XQItem::ContentNodeRole: { value = QVariant::fromValue(&source); diff --git a/src/model/xqsectionmanager.cpp b/src/model/xqsectionmanager.cpp index d52aad0..637f118 100644 --- a/src/model/xqsectionmanager.cpp +++ b/src/model/xqsectionmanager.cpp @@ -179,7 +179,6 @@ int XQSectionManager::lastRow(const XQModelSection& section ) const XQSectionRange XQSectionManager::sectionRange(const XQModelSection& section ) const { - qDebug() << " ---- Section RANGE: " << section.startIndex().row() << " -> " << lastRow(section); return XQSectionRange{ section.startIndex().row(), lastRow(section) }; } diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 14ee0c2..1281d43 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -193,15 +193,9 @@ void XQViewModel::toggleSection( const XQModelSection& section ) { if( section.isValid() && _treeTable ) { - qDebug() << " --- toggleSection: " << section.contentType(); XQSectionRange pos = _sections.sectionRange(section); _treeTable->toggleRowsHidden(pos.firstRow, pos.lastRow ); - // hier nicht!? - //emit sectionToggled(section); - } - else - { - qDebug() << " --- toggleSection: FAIL!"; + emit sectionToggled(section); } } diff --git a/xml/modeldata1.xtr b/xml/modeldata1.xtr index 1dd2ee6..fb4b4af 100644 --- a/xml/modeldata1.xtr +++ b/xml/modeldata1.xtr @@ -13,7 +13,7 @@ - + diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 1640921..7c1c79b 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -6,6 +6,8 @@ --> + + @@ -16,12 +18,11 @@ - - - + + + -
@@ -86,8 +87,7 @@
- -
+
@@ -101,9 +101,9 @@ - - - + + +
@@ -123,7 +123,7 @@ - + diff --git a/xml/saved_testfile.xtr b/xml/saved_testfile.xtr index ac8e3ef..fa2eff1 100644 --- a/xml/saved_testfile.xtr +++ b/xml/saved_testfile.xtr @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +