re-merge.

This commit is contained in:
Christoph Holzheuer
2025-09-11 17:45:44 +02:00
parent fd41138175
commit d5c1f8925c
7 changed files with 88 additions and 147 deletions

View File

@@ -1,5 +1,14 @@
# XTree # XTree
## keys
- Widgetset für XML Daten
- experimenteller qml support
- docs erzeugen
-
experimenelle
## Also, noch mal von vorn: ## Also, noch mal von vorn:
- Es geht um das Editieren von XML Daten in einer baumartigen Darstellung am Bildschirm. - Es geht um das Editieren von XML Daten in einer baumartigen Darstellung am Bildschirm.

View File

@@ -101,19 +101,6 @@ void XQMainWindow::initMainWindow()
onTreeViewItemClicked( XQItem::xqItemFromIndex(index) ); 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 try
{ {
// hand over undostack // hand over undostack
@@ -125,7 +112,7 @@ void XQMainWindow::initMainWindow()
// #2. load demo data // #2. load demo data
loadDocument( c_DocumentFileName1 ); loadDocument( c_DocumentFileName1 );
//loadDocumentQML( c_DocumentFileName2 ); loadDocumentQML( c_DocumentFileName2 );
//loadDocument( c_DocumentFileName2 ); //loadDocument( c_DocumentFileName2 );
//loadDocument( c_DocumentFileName3 ); //loadDocument( c_DocumentFileName3 );

View File

@@ -28,51 +28,6 @@
#include <xqitemtype.h> #include <xqitemtype.h>
#include <xqviewmodel.h> #include <xqviewmodel.h>
/*
#include <QStyledItemDelegate>
#include <QPainter>
#include <QApplication>
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<int>(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. //! 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 void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
if( !index.isValid() ) if( index.isValid() )
qDebug() << " index DEAD!";
XQItem& item = xqItemFromIndex( index );
switch( item.renderStyle() )
{ {
case XQItem::HeaderStyle : XQItem& item = xqItemFromIndex( index );
return drawHeaderStyle( painter, option, item ); switch( item.renderStyle() )
{
case XQItem::HeaderStyle :
return drawHeaderStyle( painter, option, item );
case XQItem::ComboBoxStyle : case XQItem::ComboBoxStyle :
return drawComboBoxStyle( painter, option, item ); return drawComboBoxStyle( painter, option, item );
case XQItem::ColorBarStyle : case XQItem::ColorBarStyle :
return drawColorBarStyle( painter, option, item ); return drawColorBarStyle( painter, option, item );
/*
case XQItem::SpinBoxStyle :
return drawSpinBoxStyle( painter, option, item );
*/
case XQItem::HiddenStyle :
return;
default: // das funktioniert nicht unter windows11
break; //case XQItem::SpinBoxStyle :
} // switch // return drawSpinBoxStyle( painter, option, item );
case XQItem::HiddenStyle :
return;
default:
break;
} // switch
}
else
{
qDebug() << " ---- paint: INDEX DEAD!" ;
}
QStyledItemDelegate::paint(painter, option, index); QStyledItemDelegate::paint(painter, option, index);
} }
@@ -171,25 +129,18 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt
headerOption.textAlignment |= Qt::AlignVCenter; headerOption.textAlignment |= Qt::AlignVCenter;
headerOption.icon = item.icon(); headerOption.icon = item.icon();
if (srcWidget != nullptr) // save painter
{ painter->save();
// save painter
painter->save(); QStyle* widgetStyle = srcWidget->style();
//value = index.data(Qt::ForegroundRole); widgetStyle->drawControl(QStyle::CE_Header, &headerOption, painter, srcWidget);
//if (value.canConvert<QBrush>()) // restore painter
//headerOption.palette.setBrush(QPalette::Text, Qt::red ); painter->restore();
//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();
}
} }
//! firz //! Zeichnet prozent-werte als balken
void XQItemDelegate::drawColorBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const 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 void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const
{ {
QWidget* srcWidget = qobject_cast<QWidget*>(option.styleObject);
QStyleOptionComboBox comboOption; QStyleOptionComboBox comboOption;
QStyle* comboStyle = srcWidget->style();
QWidget* srcWidget = qobject_cast<QWidget*>(option.styleObject);
comboOption.initFrom(srcWidget); comboOption.initFrom(srcWidget);
// set options // set options
@@ -247,10 +197,11 @@ void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionView
// save painter // save painter
painter->save(); painter->save();
QStyle* widgetStyle = srcWidget->style();
// draw combo // draw combo
comboStyle->drawComplexControl(QStyle::CC_ComboBox, &comboOption, painter, srcWidget); widgetStyle->drawComplexControl(QStyle::CC_ComboBox, &comboOption, painter, srcWidget);
// and combobox label // and combobox label
comboStyle->drawControl(QStyle::CE_ComboBoxLabel, &comboOption, painter, srcWidget); widgetStyle->drawControl(QStyle::CE_ComboBoxLabel, &comboOption, painter, srcWidget);
// restore painter // restore painter
painter->restore(); 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 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) { qDebug() << " --- jawas +++? SPINBOX!";
// ----- 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;
// Zeichnet den "komplexen" Teil des Steuerelements (Rahmen, Hintergrund, Pfeile) QWidget* srcWidget = qobject_cast<QWidget*>(option.styleObject);
QApplication::style()->drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr); QStyleOptionViewItem viewOption(option);
QStyleOptionSpinBox spinBoxOption;
spinBoxOption.initFrom(srcWidget);
// ----- Schritt 2: Den Text an der richtigen Position zeichnen ----- // 1. Grundlegende Optionen initialisieren und Hintergrund zeichnen (wichtig für Selektion)
initStyleOption(&viewOption, item.index());
// Ermitteln, wo genau das Textfeld innerhalb des Widgets gezeichnet werden soll. if (option.state & QStyle::State_HasFocus)
QRect textRect = QApplication::style()->subControlRect( {
QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, nullptr viewOption.state = viewOption.state ^ QStyle::State_HasFocus; // Fokus nicht auf dem Hintergrund malen
);
// 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);
} }
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 void XQItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {

View File

@@ -19,6 +19,7 @@
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QUrl> #include <QUrl>
#include <QQmlContext> #include <QQmlContext>
#include <QStyleFactory>
#include <xqchildmodel.h> #include <xqchildmodel.h>
#include <xqquickwidget.h> #include <xqquickwidget.h>
@@ -26,9 +27,6 @@
#include <xqmainwindow.h> #include <xqmainwindow.h>
/* /*
TODO: TODO:
@@ -83,11 +81,14 @@ int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
//app.setStyle("WindowsVista"); //qDebug() << QStyleFactory::keys();
//QApplication::setStyle("fusion");
//QApplication::setStyle("windowsvista");
//QApplication::setStyle("windows");
XQMainWindow window; XQMainWindow window;
window.show(); window.show();
/* /*
QApplication app(argc, argv); QApplication app(argc, argv);

View File

@@ -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) 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) void XQTreeTable::mouseMoveEvent(QMouseEvent* event)
{ {
@@ -117,10 +117,9 @@ void XQTreeTable::mouseMoveEvent(QMouseEvent* event)
bool leftBtn = (event->buttons() & Qt::LeftButton); bool leftBtn = (event->buttons() & Qt::LeftButton);
QPoint eventPos = event->pos(); QPoint eventPos = event->pos();
// splitcursor ist active // splitcursor ist gesetzt
bool splitCursor = (cursor().shape() == Qt::SplitHCursor); bool splitCursor = (cursor().shape() == Qt::SplitHCursor);
// sind wir schon am 'draggen'? // sind wir schon am 'draggen'?
if (_indexToResize.isValid() && splitCursor && leftBtn) if (_indexToResize.isValid() && splitCursor && leftBtn)
{ {

View File

@@ -28,7 +28,7 @@
<Header> <Header>
<Entry Caption="Active Projects" ItemType="TreeParentType"/> <Entry Caption="Active Projects" ItemType="TreeParentType"/>
</Header> </Header>
<ModelSheet firz="running"> <ModelSheet>
<Project Caption="@ProjectName" ItemType="TreeChildType"> <Project Caption="@ProjectName" ItemType="TreeChildType">
<CurrentSection ItemType="TreeSectionType"/> <CurrentSection ItemType="TreeSectionType"/>
</Project> </Project>
@@ -38,7 +38,7 @@
<Header> <Header>
<Entry Caption="Planned Projects" ItemType="TreeParentType"/> <Entry Caption="Planned Projects" ItemType="TreeParentType"/>
</Header> </Header>
<ModelSheet firz="planned"> <ModelSheet>
<Project Caption="@ProjectName" ItemType="TreeChildType"> <Project Caption="@ProjectName" ItemType="TreeChildType">
<CurrentSection ItemType="TreeSectionType"/> <CurrentSection ItemType="TreeSectionType"/>
</Project> </Project>
@@ -48,7 +48,7 @@
<Header> <Header>
<Entry Caption="Finished Projects" ItemType="TreeParentType"/> <Entry Caption="Finished Projects" ItemType="TreeParentType"/>
</Header> </Header>
<ModelSheet firz="finished"> <ModelSheet>
<Project Caption="@ProjectName" ItemType="TreeChildType"> <Project Caption="@ProjectName" ItemType="TreeChildType">
<CurrentSection ItemType="TreeSectionType"/> <CurrentSection ItemType="TreeSectionType"/>
</Project> </Project>
@@ -129,4 +129,4 @@
</ModelSheet> </ModelSheet>
</Section> </Section>
</DocumentDetailsModel> </DocumentDetailsModel>

View File

@@ -7,8 +7,8 @@
<Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 5" MaxAmpere="11" MaxVolt="42" PanelID="#5 JA 05" PanelName="JA 05 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/> <Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 5" MaxAmpere="11" MaxVolt="42" PanelID="#5 JA 05" PanelName="JA 05 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/>
<Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 6" MaxAmpere="11" MaxVolt="42" PanelID="#6 JA 06" PanelName="JA 06 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/> <Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 6" MaxAmpere="11" MaxVolt="42" PanelID="#6 JA 06" PanelName="JA 06 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/>
<Inverter FriendlyName="@InverterName" InverterID="#1 HM600 01" InverterName="01 HM600 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="2000" MaxPowerInputChoice="2000;4000;6000" MaxPowerOutput="600" NumStrings="2" Weight="28"/> <Inverter FriendlyName="@InverterName" InverterID="#1 HM600 01" InverterName="01 HM600 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="2000" MaxPowerInputChoice="2000;4000;6000" MaxPowerOutput="600" NumStrings="2" Weight="28"/>
<Inverter FriendlyName="@InverterName" InverterID="#2 HM800 02" InverterName="02 HM800 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="4000" MaxPowerInputChoice="4000;6000;8000" MaxPowerOutput="800" NumStrings="2" Weight="29"/> <Inverter FriendlyName="@InverterName" InverterID="#2 HM800 02" InverterName="02 HM800 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="4000" MaxPowerInputChoice="4000;6000;8000" MaxPowerOutput="800" NumStrings="4" Weight="29"/>
<Inverter FriendlyName="@InverterName" InverterID="#3 HM1600 03" InverterName="03 HM1600 S4 TMax" Manufacturer="HoyMiles" MaxPowerInput="6000" MaxPowerInputChoice="6000;8000;10000" MaxPowerOutput="1600" NumStrings="4" Weight="32"/> <Inverter FriendlyName="@InverterName" InverterID="firz" InverterName="03 HM1600 S4 TMax" Manufacturer="HoyMiles" MaxPowerInput="6000" MaxPowerInputChoice="6000;8000;10000" MaxPowerOutput="1600" NumStrings="4" Weight="32"/>
<Inverter FriendlyName="@InverterName" InverterID="#4 D12K 04" InverterName="04 HM600 S2 TMax" Manufacturer="Deye" MaxPowerInput="8000" MaxPowerInputChoice="6000;8000;12000" MaxPowerOutput="600" NumStrings="2" Weight="28"/> <Inverter FriendlyName="@InverterName" InverterID="#4 D12K 04" InverterName="04 HM600 S2 TMax" Manufacturer="Deye" MaxPowerInput="8000" MaxPowerInputChoice="6000;8000;12000" MaxPowerOutput="600" NumStrings="2" Weight="28"/>
<Battery BatteryID="#1 BYD 01" BatteryName="01 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="90"> <Battery BatteryID="#1 BYD 01" BatteryName="01 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="90">
<AdditionalData DataItem="Image" DataValue="image.png"/> <AdditionalData DataItem="Image" DataValue="image.png"/>
@@ -17,8 +17,8 @@
</Battery> </Battery>
<Battery BatteryID="#2 BYD 02" BatteryName="02 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="94"/> <Battery BatteryID="#2 BYD 02" BatteryName="02 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="94"/>
<Battery BatteryID="#3 BYD 03" BatteryName="03 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="86"/> <Battery BatteryID="#3 BYD 03" BatteryName="03 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="86"/>
<Battery BatteryID="#4 BYD 04" BatteryName="04 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="98"/> <Battery BatteryID="#4 BYD 04" BatteryName="04 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="91"/>
<Battery BatteryID="#5 GroWatt 05 G2K" BatteryName="05 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="GroWatt" MaxCurrent="120" MaxVolt="48" Yield="94"/> <Battery BatteryID="#5 GroWatt 05 G2K" BatteryName="05 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="GroWatt" MaxCurrent="120" MaxVolt="48" Yield="94"/>
<Battery BatteryID="#6 GroWatt 06 G4K" BatteryName="06 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="GroWatt" MaxCurrent="120" MaxVolt="48" Yield="49"/> <Battery BatteryID="#6 GroWatt 06 G4K" BatteryName="06 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="GroWatt" MaxCurrent="120" MaxVolt="48" Yield="49"/>
<Battery BatteryID="#7 Pyne 07 G4K" BatteryName="07 Pyne K7 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="PyNe" MaxCurrent="120" MaxVolt="48" Yield="49"/> <Battery BatteryID="#7 Pyne 07 G4K" BatteryName="07 Pyne K7 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="PyNe" MaxCurrent="120" MaxVolt="48" Yield="68"/>
</Components> </Components>