From d5c1f8925c7a65cb7b5558d011d2fa5b705675af Mon Sep 17 00:00:00 2001 From: Christoph Holzheuer Date: Thu, 11 Sep 2025 17:45:44 +0200 Subject: [PATCH] re-merge. --- README.md | 9 ++ src/application/xqmainwindow.cpp | 15 +-- src/items/xqitemdelegate.cpp | 177 +++++++++++-------------------- src/main.cpp | 11 +- src/widgets/xqtreetable.cpp | 7 +- xml/modelsheets.xml | 8 +- xml/saved_testfile.xtr | 8 +- 7 files changed, 88 insertions(+), 147 deletions(-) diff --git a/README.md b/README.md index c3d922d..7b3df92 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,14 @@ # XTree +## keys + + - Widgetset für XML Daten + - experimenteller qml support + - docs erzeugen + - + + experimenelle + ## Also, noch mal von vorn: - Es geht um das Editieren von XML Daten in einer baumartigen Darstellung am Bildschirm. diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index e61a127..c7f8cee 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -101,19 +101,6 @@ void XQMainWindow::initMainWindow() onTreeViewItemClicked( XQItem::xqItemFromIndex(index) ); }); - - /* - connect( &_mainModel, &XQViewModel::itemCreated, this, [=, this](XQItem* item) - { - // when a new main tree item has been created ... - QString pID = item.contentNode()->attribute(c_ProjectID); - _mainTreeView->setCurrentIndex( item.index() ); - // ... we set the current view to this node - if( _documentStore.contains( pID ) ) - _tabWidget->setCurrentWidget( _documentStore[pID].viewModel->treeTable() ); - } ); - */ - try { // hand over undostack @@ -125,7 +112,7 @@ void XQMainWindow::initMainWindow() // #2. load demo data loadDocument( c_DocumentFileName1 ); - //loadDocumentQML( c_DocumentFileName2 ); + loadDocumentQML( c_DocumentFileName2 ); //loadDocument( c_DocumentFileName2 ); //loadDocument( c_DocumentFileName3 ); diff --git a/src/items/xqitemdelegate.cpp b/src/items/xqitemdelegate.cpp index 59e9974..0b5c0e3 100644 --- a/src/items/xqitemdelegate.cpp +++ b/src/items/xqitemdelegate.cpp @@ -28,51 +28,6 @@ #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. @@ -124,32 +79,35 @@ XQItem& XQItemDelegate::xqItemFromIndex( const QModelIndex& index ) const void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - if( !index.isValid() ) - qDebug() << " index DEAD!"; - - XQItem& item = xqItemFromIndex( index ); - - switch( item.renderStyle() ) + if( index.isValid() ) { - case XQItem::HeaderStyle : - return drawHeaderStyle( painter, option, item ); + XQItem& item = xqItemFromIndex( index ); + switch( item.renderStyle() ) + { + case XQItem::HeaderStyle : + return drawHeaderStyle( painter, option, item ); - case XQItem::ComboBoxStyle : - return drawComboBoxStyle( painter, option, item ); + case XQItem::ComboBoxStyle : + return drawComboBoxStyle( painter, option, item ); - case XQItem::ColorBarStyle : - return drawColorBarStyle( painter, option, item ); -/* - case XQItem::SpinBoxStyle : - return drawSpinBoxStyle( painter, option, item ); -*/ - case XQItem::HiddenStyle : - return; + case XQItem::ColorBarStyle : + return drawColorBarStyle( painter, option, item ); - default: - break; - } // switch + // das funktioniert nicht unter windows11 + //case XQItem::SpinBoxStyle : + // return drawSpinBoxStyle( painter, option, item ); + case XQItem::HiddenStyle : + return; + + default: + break; + } // switch + } + else + { + qDebug() << " ---- paint: INDEX DEAD!" ; + } QStyledItemDelegate::paint(painter, option, index); } @@ -171,25 +129,18 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt headerOption.textAlignment |= Qt::AlignVCenter; headerOption.icon = item.icon(); - if (srcWidget != nullptr) - { - // save painter - painter->save(); - //value = index.data(Qt::ForegroundRole); - //if (value.canConvert()) - //headerOption.palette.setBrush(QPalette::Text, Qt::red ); - //headerOption.palette.setBrush(QPalette::Window, Qt::red ); - QCommonStyle itemStyle; - //headerOption.backgroundBrush() - //srcWidget->style()->drawControl(QStyle::CE_Header, &headerOption, painter, srcWidget); - itemStyle.drawControl(QStyle::CE_Header, &headerOption, painter, srcWidget); - // restore painter - painter->restore(); - } + // save painter + painter->save(); + + QStyle* widgetStyle = srcWidget->style(); + widgetStyle->drawControl(QStyle::CE_Header, &headerOption, painter, srcWidget); + // restore painter + painter->restore(); + } -//! firz +//! Zeichnet prozent-werte als balken void XQItemDelegate::drawColorBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const { @@ -229,10 +180,9 @@ void XQItemDelegate::drawColorBarStyle(QPainter* painter, const QStyleOptionView void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const { - QWidget* srcWidget = qobject_cast(option.styleObject); QStyleOptionComboBox comboOption; - QStyle* comboStyle = srcWidget->style(); + QWidget* srcWidget = qobject_cast(option.styleObject); comboOption.initFrom(srcWidget); // set options @@ -247,10 +197,11 @@ void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionView // save painter painter->save(); + QStyle* widgetStyle = srcWidget->style(); // draw combo - comboStyle->drawComplexControl(QStyle::CC_ComboBox, &comboOption, painter, srcWidget); + widgetStyle->drawComplexControl(QStyle::CC_ComboBox, &comboOption, painter, srcWidget); // and combobox label - comboStyle->drawControl(QStyle::CE_ComboBoxLabel, &comboOption, painter, srcWidget); + widgetStyle->drawControl(QStyle::CE_ComboBoxLabel, &comboOption, painter, srcWidget); // restore painter painter->restore(); } @@ -260,40 +211,34 @@ void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionView void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const { - qDebug() << " --- jawas? SPINBOX!"; - bool isInt = false; - // Den Wert aus dem Modell holen. - QString textToShow = item.data(Qt::DisplayRole).toString(); - textToShow.toInt(&isInt); - 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; + qDebug() << " --- jawas +++? SPINBOX!"; - // Zeichnet den "komplexen" Teil des Steuerelements (Rahmen, Hintergrund, Pfeile) - QApplication::style()->drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr); + QWidget* srcWidget = qobject_cast(option.styleObject); + QStyleOptionViewItem viewOption(option); + QStyleOptionSpinBox spinBoxOption; + spinBoxOption.initFrom(srcWidget); - // ----- 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); - + // 1. Grundlegende Optionen initialisieren und Hintergrund zeichnen (wichtig für Selektion) + initStyleOption(&viewOption, item.index()); + if (option.state & QStyle::State_HasFocus) + { + viewOption.state = viewOption.state ^ QStyle::State_HasFocus; // Fokus nicht auf dem Hintergrund malen } + QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewOption, painter); + + spinBoxOption.rect = option.rect; + spinBoxOption.state = option.state | QStyle::State_Sunken; // Sunken-State für den "LineEdit"-Look + spinBoxOption.buttonSymbols = QAbstractSpinBox::UpDownArrows; + spinBoxOption.stepEnabled = QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled; + spinBoxOption.frame = true; + + QStyle* widgetStyle = srcWidget->style(); + widgetStyle->drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr); + QRect editRect = widgetStyle->subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, nullptr); + painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignCenter, item.text()); + } @@ -389,7 +334,7 @@ void XQItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, co } -//! firz +//! Überschreibt QItemDelegate::updateEditorGeometry. Nicht implementiert. void XQItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const { diff --git a/src/main.cpp b/src/main.cpp index 18c6541..e5dd01e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -26,9 +27,6 @@ #include - - - /* TODO: @@ -83,11 +81,14 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - //app.setStyle("WindowsVista"); + //qDebug() << QStyleFactory::keys(); + //QApplication::setStyle("fusion"); + //QApplication::setStyle("windowsvista"); + //QApplication::setStyle("windows"); + XQMainWindow window; window.show(); - /* QApplication app(argc, argv); diff --git a/src/widgets/xqtreetable.cpp b/src/widgets/xqtreetable.cpp index 5943370..89272db 100644 --- a/src/widgets/xqtreetable.cpp +++ b/src/widgets/xqtreetable.cpp @@ -82,7 +82,7 @@ void XQTreeTable::currentChanged(const QModelIndex& current, const QModelIndex& } -//! firz +//! ändert die breite eines header-feldes anhand der maus-position void XQTreeTable::mouseResizeHeaderEntry(int xpos) { @@ -107,7 +107,7 @@ void XQTreeTable::mouseResizeHeaderEntry(int xpos) } -//! firz +//! behandelt den mouse-drag zur grössenänderung der header-felder. void XQTreeTable::mouseMoveEvent(QMouseEvent* event) { @@ -117,10 +117,9 @@ void XQTreeTable::mouseMoveEvent(QMouseEvent* event) bool leftBtn = (event->buttons() & Qt::LeftButton); QPoint eventPos = event->pos(); - // splitcursor ist active + // splitcursor ist gesetzt bool splitCursor = (cursor().shape() == Qt::SplitHCursor); - // sind wir schon am 'draggen'? if (_indexToResize.isValid() && splitCursor && leftBtn) { diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 3f10178..ec9a8d6 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -28,7 +28,7 @@
- + @@ -38,7 +38,7 @@
- + @@ -48,7 +48,7 @@
- + @@ -129,4 +129,4 @@ - \ No newline at end of file + diff --git a/xml/saved_testfile.xtr b/xml/saved_testfile.xtr index fa2eff1..096a2f3 100644 --- a/xml/saved_testfile.xtr +++ b/xml/saved_testfile.xtr @@ -7,8 +7,8 @@ - - + + @@ -17,8 +17,8 @@ - + - +