This commit is contained in:
Christoph Holzheuer
2025-09-08 15:42:15 +02:00
parent 05bc5ad5d9
commit 95b7b026ff
8 changed files with 124 additions and 77 deletions

View File

@@ -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 )
{

View File

@@ -17,6 +17,7 @@
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QProgressBar>
#include <QSlider>
#include <QPainter>
#include <QHeaderView>
@@ -39,7 +40,8 @@ public:
registerEditor(XQItem::LineEditType, new QStandardItemEditorCreator<QLineEdit>());
registerEditor(XQItem::ComboBoxType, new QStandardItemEditorCreator<QComboBox>());
registerEditor(XQItem::PickerType, new QStandardItemEditorCreator<QLineEdit>());
registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QProgressBar>());
//registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QProgressBar>());
registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QSlider>());
registerEditor(XQItem::SpinBoxType, new QStandardItemEditorCreator<QSpinBox>());
registerEditor(XQItem::CustomEditorType, new QStandardItemEditorCreator<QLineEdit>());
}
@@ -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<QWidget*>(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<QIcon>(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
{

View File

@@ -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);

View File

@@ -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) };
}

View File

@@ -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);
}
}