From f8bf8c1807c521f74b549795214fbf2d967e724c Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 13 Oct 2025 13:21:05 +0200 Subject: [PATCH] Use QtPropertyBrowser for Qt5/6 --- 3rdparty/QtPropertyBrowser/CMakeLists.txt | 8 ------- 3rdparty/QtPropertyBrowser/src/CMakeLists.txt | 15 ++++++++++--- 3rdparty/QtPropertyBrowser/src/qt5compat.h | 12 ++++++++++ .../QtPropertyBrowser/src/qteditorfactory.cpp | 22 +++++++++++++++++++ .../QtPropertyBrowser/src/qtpropertybrowser.h | 2 ++ .../src/qtpropertybrowserutils.cpp | 16 ++++++++++++++ .../src/qtpropertymanager.cpp | 15 ++++++++++++- .../src/qttreepropertybrowser.cpp | 16 +++++++++----- .../src/qtvariantproperty.cpp | 5 +++++ 9 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 3rdparty/QtPropertyBrowser/src/qt5compat.h diff --git a/3rdparty/QtPropertyBrowser/CMakeLists.txt b/3rdparty/QtPropertyBrowser/CMakeLists.txt index a86b5c6b..65101760 100644 --- a/3rdparty/QtPropertyBrowser/CMakeLists.txt +++ b/3rdparty/QtPropertyBrowser/CMakeLists.txt @@ -1,11 +1,3 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.13) - PROJECT(QtPropertyBrowser) - -##################### Look for required libraries ###################### - -# Add QT dependencies -FIND_PACKAGE(Qt5Widgets REQUIRED) - -######################### Add Primary Targets ########################## ADD_SUBDIRECTORY(src) diff --git a/3rdparty/QtPropertyBrowser/src/CMakeLists.txt b/3rdparty/QtPropertyBrowser/src/CMakeLists.txt index 9d02d58d..276b6f9d 100644 --- a/3rdparty/QtPropertyBrowser/src/CMakeLists.txt +++ b/3rdparty/QtPropertyBrowser/src/CMakeLists.txt @@ -23,8 +23,13 @@ set(_RESOURCES qtpropertybrowser.qrc ) -QT5_WRAP_UI(_UI_SRCS ${_UI_FORMS}) -QT5_ADD_RESOURCES(_QRC_SRCS ${_RESOURCES}) +if (Qt6_FOUND) + QT6_WRAP_UI(_UI_SRCS ${_UI_FORMS}) + QT6_ADD_RESOURCES(_QRC_SRCS ${_RESOURCES}) +else() + QT5_WRAP_UI(_UI_SRCS ${_UI_FORMS}) + QT5_ADD_RESOURCES(_QRC_SRCS ${_RESOURCES}) +endif() set(TARGET_NAME ${PROJECT_NAME}) @@ -38,4 +43,8 @@ if (MSVC) target_compile_options(${TARGET_NAME} PRIVATE /wd4457 /wd4718) endif() -target_link_libraries(${TARGET_NAME} Qt5::Widgets) +if (Qt6_FOUND) + target_link_libraries(${TARGET_NAME} Qt6::Widgets) +else() + target_link_libraries(${TARGET_NAME} Qt5::Widgets) +endif() diff --git a/3rdparty/QtPropertyBrowser/src/qt5compat.h b/3rdparty/QtPropertyBrowser/src/qt5compat.h new file mode 100644 index 00000000..969e7445 --- /dev/null +++ b/3rdparty/QtPropertyBrowser/src/qt5compat.h @@ -0,0 +1,12 @@ +#pragma once +#include + +#if QT_VERSION_MAJOR >= 6 +#include +#include + +// QRegExp / QRegExpValidator aliases +using QRegExp = QRegularExpression; +using QRegExpValidator = QRegularExpressionValidator; + +#endif diff --git a/3rdparty/QtPropertyBrowser/src/qteditorfactory.cpp b/3rdparty/QtPropertyBrowser/src/qteditorfactory.cpp index 4920f472..d3a0b1ef 100644 --- a/3rdparty/QtPropertyBrowser/src/qteditorfactory.cpp +++ b/3rdparty/QtPropertyBrowser/src/qteditorfactory.cpp @@ -1545,7 +1545,11 @@ QtCharEdit::QtCharEdit(QWidget *parent) { QHBoxLayout *layout = new QHBoxLayout(this); layout->addWidget(m_lineEdit); +#if QT_VERSION_MAJOR >= 6 + layout->setContentsMargins(0,0,0,0); +#else layout->setMargin(0); +#endif m_lineEdit->installEventFilter(this); m_lineEdit->setReadOnly(true); m_lineEdit->setFocusProxy(this); @@ -1669,7 +1673,13 @@ void QtCharEdit::keyReleaseEvent(QKeyEvent *e) void QtCharEdit::paintEvent(QPaintEvent *) { QStyleOption opt; +#if QT_VERSION_MAJOR >= 6 + opt.rect = this->rect(); + opt.state = isEnabled() ? QStyle::State_Enabled : QStyle::State_None; + opt.palette = this->palette(); +#else opt.init(this); +#endif QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } @@ -2240,7 +2250,13 @@ bool QtColorEditWidget::eventFilter(QObject *obj, QEvent *ev) void QtColorEditWidget::paintEvent(QPaintEvent *) { QStyleOption opt; +#if QT_VERSION_MAJOR >= 6 + opt.rect = this->rect(); + opt.state = isEnabled() ? QStyle::State_Enabled : QStyle::State_None; + opt.palette = this->palette(); +#else opt.init(this); +#endif QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } @@ -2462,7 +2478,13 @@ bool QtFontEditWidget::eventFilter(QObject *obj, QEvent *ev) void QtFontEditWidget::paintEvent(QPaintEvent *) { QStyleOption opt; +#if QT_VERSION_MAJOR >= 6 + opt.rect = this->rect(); + opt.state = isEnabled() ? QStyle::State_Enabled : QStyle::State_None; + opt.palette = this->palette(); +#else opt.init(this); +#endif QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } diff --git a/3rdparty/QtPropertyBrowser/src/qtpropertybrowser.h b/3rdparty/QtPropertyBrowser/src/qtpropertybrowser.h index 1ca87830..17e012cf 100644 --- a/3rdparty/QtPropertyBrowser/src/qtpropertybrowser.h +++ b/3rdparty/QtPropertyBrowser/src/qtpropertybrowser.h @@ -41,6 +41,8 @@ #ifndef QTPROPERTYBROWSER_H #define QTPROPERTYBROWSER_H +#include "qt5compat.h" + #include #include diff --git a/3rdparty/QtPropertyBrowser/src/qtpropertybrowserutils.cpp b/3rdparty/QtPropertyBrowser/src/qtpropertybrowserutils.cpp index cd195835..6f28fcd2 100644 --- a/3rdparty/QtPropertyBrowser/src/qtpropertybrowserutils.cpp +++ b/3rdparty/QtPropertyBrowser/src/qtpropertybrowserutils.cpp @@ -262,7 +262,13 @@ void QtBoolEdit::mousePressEvent(QMouseEvent *event) void QtBoolEdit::paintEvent(QPaintEvent *) { QStyleOption opt; +#if QT_VERSION_MAJOR >= 6 + opt.rect = this->rect(); + opt.state = isEnabled() ? QStyle::State_Enabled : QStyle::State_None; + opt.palette = this->palette(); +#else opt.init(this); +#endif QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } @@ -274,7 +280,11 @@ QtKeySequenceEdit::QtKeySequenceEdit(QWidget *parent) { QHBoxLayout *layout = new QHBoxLayout(this); layout->addWidget(m_lineEdit); +#if QT_VERSION_MAJOR >= 6 + layout->setContentsMargins(0,0,0,0); +#else layout->setMargin(0); +#endif m_lineEdit->installEventFilter(this); m_lineEdit->setReadOnly(true); m_lineEdit->setFocusProxy(this); @@ -408,7 +418,13 @@ void QtKeySequenceEdit::keyReleaseEvent(QKeyEvent *e) void QtKeySequenceEdit::paintEvent(QPaintEvent *) { QStyleOption opt; +#if QT_VERSION_MAJOR >= 6 + opt.rect = this->rect(); + opt.state = isEnabled() ? QStyle::State_Enabled : QStyle::State_None; + opt.palette = this->palette(); +#else opt.init(this); +#endif QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } diff --git a/3rdparty/QtPropertyBrowser/src/qtpropertymanager.cpp b/3rdparty/QtPropertyBrowser/src/qtpropertymanager.cpp index ef627e9c..2626af93 100644 --- a/3rdparty/QtPropertyBrowser/src/qtpropertymanager.cpp +++ b/3rdparty/QtPropertyBrowser/src/qtpropertymanager.cpp @@ -1229,7 +1229,11 @@ public: struct Data { - Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard) +#if QT_VERSION_MAJOR >= 6 + Data() : regExp(QRegularExpression(QStringLiteral(".*"))) +#else + Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard) +#endif { } QString val; @@ -1357,7 +1361,11 @@ void QtStringPropertyManager::setValue(QtProperty *property, const QString &val) if (data.val == val) return; +#if QT_VERSION_MAJOR >= 6 + if (data.regExp.isValid() && !data.regExp.match(val).hasMatch()) +#else if (data.regExp.isValid() && !data.regExp.exactMatch(val)) +#endif return; data.val = val; @@ -5854,8 +5862,13 @@ void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val) return; const QFont oldVal = it.value(); +#if QT_VERSION_MAJOR >= 6 + if (oldVal == val && oldVal.resolve(val) == val) + return; +#else if (oldVal == val && oldVal.resolve() == val.resolve()) return; +#endif it.value() = val; diff --git a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp index 1ed0c983..765a0c55 100644 --- a/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp +++ b/3rdparty/QtPropertyBrowser/src/qttreepropertybrowser.cpp @@ -132,9 +132,9 @@ public: protected: void mouseMoveEvent(QMouseEvent *event) override; void leaveEvent(QEvent *event) override; - void keyPressEvent(QKeyEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void keyPressEvent(QKeyEvent *event); + void mousePressEvent(QMouseEvent *event); + void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; Q_SIGNALS: void hoverPropertyChanged(QtBrowserItem *item); @@ -160,7 +160,8 @@ void QtPropertyEditorView::drawRow(QPainter *painter, const QStyleOptionViewItem hasValue = property->hasValue(); } if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) { - const QColor c = option.palette.color(QPalette::Dark); + QColor c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index)); + if (!c.isValid()) c = option.palette.color(QPalette::Dark); painter->fillRect(option.rect, c); opt.palette.setColor(QPalette::AlternateBase, c); } else { @@ -379,7 +380,8 @@ void QtPropertyEditorDelegate::paint(QPainter *painter, const QStyleOptionViewIt } QColor c; if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) { - c = opt.palette.color(QPalette::Dark); + c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index)); + if (!c.isValid()) c = opt.palette.color(QPalette::Dark); opt.palette.setColor(QPalette::Text, opt.palette.color(QPalette::BrightText)); } else { c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index)); @@ -486,7 +488,11 @@ static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style) void QtTreePropertyBrowserPrivate::init(QWidget *parent) { QHBoxLayout *layout = new QHBoxLayout(parent); +#if QT_VERSION_MAJOR >= 6 + layout->setContentsMargins(0,0,0,0); +#else layout->setMargin(0); +#endif m_treeWidget = new QtPropertyEditorView(parent); m_treeWidget->setEditorPrivate(this); m_treeWidget->setIconSize(QSize(18, 18)); diff --git a/3rdparty/QtPropertyBrowser/src/qtvariantproperty.cpp b/3rdparty/QtPropertyBrowser/src/qtvariantproperty.cpp index c003f3e4..a03f7a42 100644 --- a/3rdparty/QtPropertyBrowser/src/qtvariantproperty.cpp +++ b/3rdparty/QtPropertyBrowser/src/qtvariantproperty.cpp @@ -986,8 +986,13 @@ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent) QtStringPropertyManager *stringPropertyManager = new QtStringPropertyManager(this); d_ptr->m_typeToPropertyManager[QVariant::String] = stringPropertyManager; d_ptr->m_typeToValueType[QVariant::String] = QVariant::String; +#if QT_VERSION_MAJOR >= 6 + d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] = + QMetaType::QRegularExpression; // int value for the type +#else d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] = QVariant::RegExp; +#endif connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty *, const QString &)), this, SLOT(slotValueChanged(QtProperty *, const QString &))); connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),