From cbe8b92582e81db9174b66a1f48a16b54c656e65 Mon Sep 17 00:00:00 2001 From: Christoph Holzheuer Date: Tue, 9 Sep 2025 16:22:59 +0200 Subject: [PATCH] --- fy --- src/application/xqchildmodel.cpp | 4 ++- src/items/xqitem.cpp | 11 ++++--- src/items/xqitem.h | 4 +-- src/items/xqitemdelegate.cpp | 52 ++++++++++++++++++++++++++++++-- src/main.cpp | 3 ++ src/model/xqsectionmanager.cpp | 20 +++++------- src/model/xqviewmodel.cpp | 14 +++++++-- src/widgets/xqtreetable.cpp | 7 ++++- xml/modelsheets.xml | 36 +++++++++++----------- 9 files changed, 107 insertions(+), 44 deletions(-) diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index 0da5f4b..0b16fc9 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -63,7 +63,9 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot ) // als Baum? //section.headerItem().appendRow( list ); - insertRow( newRow, list); + + // _hinter_ der letzen zeile einfügen + insertRow( newRow+1, list); } // for diff --git a/src/items/xqitem.cpp b/src/items/xqitem.cpp index f2e865d..a1cbfdb 100644 --- a/src/items/xqitem.cpp +++ b/src/items/xqitem.cpp @@ -64,7 +64,7 @@ XQItem::XQRenderStyleMap XQItem::s_RenderStyleMap { "CustomRenderStyle", CustomRenderStyle }, { "PickerStyle", PickerStyle }, { "SpinBoxStyle", SpinBoxStyle }, - { "ProgressBarStyle", ProgressBarStyle}, + { "ColorBarStyle", ColorBarStyle}, { "FormattedStyle", FormattedStyle}, }; @@ -74,7 +74,7 @@ XQItem::XQEditorTypeMap XQItem::s_EditorTypeMap { "LineEditType", LineEditType }, { "ComboBoxType", ComboBoxType }, { "PickerType", PickerType }, - { "ProgressBarType", ProgressBarType }, + { "ColorBarType", ColorBarType }, { "SpinBoxType", SpinBoxType}, { "CustomEditorType", CustomEditorType} }; @@ -501,7 +501,8 @@ QVariant XQItem::data(int role ) const case Qt::DisplayRole : { QString plainText = contentFallBackText(); - if( renderStyle() == XQItem::FormattedStyle) + //if( renderStyle() == XQItem::FormattedStyle) + if( unitType() != XQItem::NoUnitType) return XQItemType::formatToSI( plainText, unitType() ); return plainText; } @@ -614,7 +615,9 @@ void XQItem::setData(const QVariant& value, int role ) case XQItem::ContentRole: { QVariant newValue; - if( itemType().renderStyle() == XQItem::FormattedStyle) + + //if( itemType().renderStyle() == XQItem::FormattedStyle) + if( unitType() != XQItem::NoUnitType) newValue = XQItemType::unFormatFromSI( value.toString() ); else newValue = value; diff --git a/src/items/xqitem.h b/src/items/xqitem.h index 444c3c6..8abcb36 100644 --- a/src/items/xqitem.h +++ b/src/items/xqitem.h @@ -84,7 +84,7 @@ public: ComboBoxStyle, PickerStyle, SpinBoxStyle, - ProgressBarStyle, + ColorBarStyle, FormattedStyle, TreeHeaderStyle, CustomRenderStyle, @@ -99,7 +99,7 @@ public: LineEditType, ComboBoxType, PickerType, - ProgressBarType, + ColorBarType, SpinBoxType, CustomEditorType, EditorTypeEnd diff --git a/src/items/xqitemdelegate.cpp b/src/items/xqitemdelegate.cpp index 276cc29..a9c791b 100644 --- a/src/items/xqitemdelegate.cpp +++ b/src/items/xqitemdelegate.cpp @@ -28,6 +28,51 @@ #include #include +/* +#include +#include +#include + +class BarDelegate : public QStyledItemDelegate { +public: + BarDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {} + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override { + // Standard-Zellenhintergrund zeichnen + QStyledItemDelegate::paint(painter, option, index); + + // Wert aus dem Modell holen + bool ok; + int value = index.data().toInt(&ok); + if (!ok || value < 0 || value > 100) + return; + + // Balkenbereich berechnen + QRect rect = option.rect.adjusted(4, 4, -4, -4); // etwas Padding + int barWidth = static_cast(rect.width() * (value / 100.0)); + + // Balken zeichnen + painter->save(); + painter->setRenderHint(QPainter::Antialiasing); + + QRect barRect(rect.left(), rect.top(), barWidth, rect.height()); + QColor barColor = QColor(100, 180, 255); // z. B. hellblau + painter->setBrush(barColor); + painter->setPen(Qt::NoPen); + painter->drawRect(barRect); + + // Text (Zahl) zentriert zeichnen + painter->setPen(Qt::black); + painter->drawText(rect, Qt::AlignCenter, QString::number(value)); + + painter->restore(); + } +}; + +*/ + + //! erzeugt eine editorfactory mit den hauseigenen editortypen. @@ -40,8 +85,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::ColorBarType, new QStandardItemEditorCreator()); + registerEditor(XQItem::ColorBarType, new QStandardItemEditorCreator()); registerEditor(XQItem::SpinBoxType, new QStandardItemEditorCreator()); registerEditor(XQItem::CustomEditorType, new QStandardItemEditorCreator()); } @@ -96,7 +141,7 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option case XQItem::SpinBoxStyle : return drawSpinBoxStyle( painter, option, index ); - case XQItem::ProgressBarStyle : + case XQItem::ColorBarStyle : return drawProgressBarStyle( painter, option, index ); */ case XQItem::HiddenStyle : @@ -289,6 +334,7 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co case XQItemType::ComboBoxType : { QComboBox* comboBox = qobject_cast(editor); + // wir erwarten hier ein gültiges model? comboBox->setModel( item.fixedChoices()); comboBox->setCurrentText( item.data().toString() ); comboBox->showPopup(); diff --git a/src/main.cpp b/src/main.cpp index 68b724f..18c6541 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,9 @@ #include + + + /* TODO: diff --git a/src/model/xqsectionmanager.cpp b/src/model/xqsectionmanager.cpp index 637f118..437e91f 100644 --- a/src/model/xqsectionmanager.cpp +++ b/src/model/xqsectionmanager.cpp @@ -128,17 +128,13 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const { - if( _sections.size() > 0) - { - // wir gehen rückwärts, weil wir da nur einen vergleich brauchen - // und uns den test mit lastRow() sparen können. - int i = _sections.size() - 1; - for (; i >= 0; --i) - { - if ( _sections.at(i).startIndex().row() < itemRow ) - return _sections.at(i); - } + for (const auto& section : _sections) + { + qDebug() << " ---- SEC: " << itemRow << " -> " << section.firstRow() << " : " << lastRow( section ); + XQSectionRange range = sectionRange(section); + if( itemRow >= range.firstRow && itemRow <= range.lastRow) + return section; } throw XQException( "No section for item row: ", QString::number(itemRow)); @@ -169,9 +165,9 @@ int XQSectionManager::lastRow(const XQModelSection& section ) const { // last section? return last row of model if (index == _sections.size() - 1) - return section.startIndex().model()->rowCount();// - 1; + return section.startIndex().model()->rowCount() - 1; // return row above the row of the next section -> last row of given section - return _sections.at(index+1).firstRow();// - 1; + return _sections.at(index+1).firstRow() - 1; } return -1; } diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 6e0cfcb..6e90636 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -61,8 +61,7 @@ XQViewModel::XQViewModel( QObject* parent ) XQItem* xqItem = static_cast(item); emit xqItemChanged( *xqItem ); }); - - + // not needed //qRegisterMetaType("XQItem"); } @@ -192,8 +191,10 @@ void XQViewModel::onToggleSection(const QString& sectionKey ) void XQViewModel::toggleSection( const XQModelSection& section ) { if( section.isValid() && _treeTable ) - { + { XQSectionRange pos = _sections.sectionRange(section); + qDebug() << " --- Section RANGE: " << pos.firstRow << " -> " << pos.lastRow; + _treeTable->toggleRowsHidden(pos.firstRow, pos.lastRow ); } } @@ -521,8 +522,15 @@ void XQViewModel::cmdToggleSection( const XQCommand& command ) const QModelIndex& index = command.originIndex(); Q_ASSERT(index.isValid()); const XQModelSection& section = _sections.sectionByRow(index.row()); + + // Obacht! Das ist hier etwas unsauber, 'toogleSection'' ändert den check-State + // im document-tree, was wiederum die 'toggleSection' auslöst, das gibt also + // einen doppelten Aufruf und wir sind dann wieder im Anfangszustand. + //toggleSection( section ); + emit sectionToggled(section); + } diff --git a/src/widgets/xqtreetable.cpp b/src/widgets/xqtreetable.cpp index ae6f599..5943370 100644 --- a/src/widgets/xqtreetable.cpp +++ b/src/widgets/xqtreetable.cpp @@ -51,13 +51,18 @@ XQItem& XQTreeTable::xqItemFromIndex(const QModelIndex& index ) return viewModel()->xqItemFromIndex( index ); } + +//! rows sichtbar/unsichtbar schalten, von 'fstRow' bis _einschliesslich_ +//! 'lstRow' + void XQTreeTable::toggleRowsHidden( int fstRow, int lstRow ) { bool hidden = isRowHidden( fstRow, rootIndex() ); - for (int row = fstRow; row < lstRow; ++row ) + for (int row = fstRow; row <= lstRow; ++row ) setRowHidden( row, rootIndex(), !hidden ); } + //! override von 'currentChanged' (noch nicht implementiert) void XQTreeTable::currentChanged(const QModelIndex& current, const QModelIndex& previous) diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 9ffa8d3..3338b16 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -17,9 +17,9 @@ - - - + + + @@ -79,7 +79,7 @@ - + @@ -98,13 +98,13 @@ - - - - - - - + + + + + + + @@ -119,13 +119,13 @@ - - - - - - - + + + + + + +