summaryrefslogtreecommitdiffstats
path: root/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/qtpropertybrowser/qttreepropertybrowser.cpp')
-rw-r--r--src/shared/qtpropertybrowser/qttreepropertybrowser.cpp132
1 files changed, 59 insertions, 73 deletions
diff --git a/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp b/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp
index fb77ee6eb..5142274c4 100644
--- a/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp
+++ b/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp
@@ -1,57 +1,33 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the tools applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qttreepropertybrowser.h"
-#include <QtCore/QSet>
+
+#include <QtCore/QOperatingSystemVersion>
+#include <QtCore/QHash>
+#include <QtGui/QFocusEvent>
#include <QtGui/QIcon>
-#include <QtWidgets/QTreeWidget>
-#include <QtWidgets/QItemDelegate>
-#include <QtWidgets/QHBoxLayout>
-#include <QtWidgets/QHeaderView>
#include <QtGui/QPainter>
+#include <QtGui/QPalette>
+#include <QtGui/QStyleHints>
#include <QtWidgets/QApplication>
-#include <QtGui/QFocusEvent>
+#include <QtWidgets/QHBoxLayout>
+#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QItemDelegate>
#include <QtWidgets/QStyle>
-#include <QtGui/QPalette>
+#include <QtWidgets/QTreeWidget>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
+static constexpr bool isWindows = QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows;
+
+static inline bool isLightTheme()
+{
+ return QGuiApplication::styleHints()->colorScheme() != Qt::ColorScheme::Dark;
+}
+
class QtPropertyEditorView;
class QtTreePropertyBrowserPrivate
@@ -96,10 +72,10 @@ public:
private:
void updateItem(QTreeWidgetItem *item);
- QMap<QtBrowserItem *, QTreeWidgetItem *> m_indexToItem;
- QMap<QTreeWidgetItem *, QtBrowserItem *> m_itemToIndex;
+ QHash<QtBrowserItem *, QTreeWidgetItem *> m_indexToItem;
+ QHash<QTreeWidgetItem *, QtBrowserItem *> m_itemToIndex;
- QMap<QtBrowserItem *, QColor> m_indexToBackgroundColor;
+ QHash<QtBrowserItem *, QColor> m_indexToBackgroundColor;
QtPropertyEditorView *m_treeWidget;
@@ -137,7 +113,7 @@ QtPropertyEditorView::QtPropertyEditorView(QWidget *parent) :
QTreeWidget(parent),
m_editorPrivate(0)
{
- connect(header(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(resizeColumnToContents(int)));
+ connect(header(), &QHeaderView::sectionDoubleClicked, this, &QTreeView::resizeColumnToContents);
}
void QtPropertyEditorView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
@@ -250,10 +226,10 @@ private slots:
private:
int indentation(const QModelIndex &index) const;
- typedef QMap<QWidget *, QtProperty *> EditorToPropertyMap;
+ using EditorToPropertyMap = QHash<QWidget *, QtProperty *>;
mutable EditorToPropertyMap m_editorToProperty;
- typedef QMap<QtProperty *, QWidget *> PropertyToEditorMap;
+ using PropertyToEditorMap = QHash<QtProperty *, QWidget *>;
mutable PropertyToEditorMap m_propertyToEditor;
QtTreePropertyBrowserPrivate *m_editorPrivate;
mutable QTreeWidgetItem *m_editedItem;
@@ -278,22 +254,22 @@ int QtPropertyEditorDelegate::indentation(const QModelIndex &index) const
void QtPropertyEditorDelegate::slotEditorDestroyed(QObject *object)
{
- if (QWidget *w = qobject_cast<QWidget *>(object)) {
- const EditorToPropertyMap::iterator it = m_editorToProperty.find(w);
+ if (auto *w = qobject_cast<QWidget *>(object)) {
+ const auto it = m_editorToProperty.find(w);
if (it != m_editorToProperty.end()) {
m_propertyToEditor.remove(it.value());
m_editorToProperty.erase(it);
}
if (m_editedWidget == w) {
- m_editedWidget = 0;
- m_editedItem = 0;
+ m_editedWidget = nullptr;
+ m_editedItem = nullptr;
}
}
}
void QtPropertyEditorDelegate::closeEditor(QtProperty *property)
{
- if (QWidget *w = m_propertyToEditor.value(property, 0))
+ if (QWidget *w = m_propertyToEditor.value(property, nullptr))
w->deleteLater();
}
@@ -308,7 +284,8 @@ QWidget *QtPropertyEditorDelegate::createEditor(QWidget *parent,
if (editor) {
editor->setAutoFillBackground(true);
editor->installEventFilter(const_cast<QtPropertyEditorDelegate *>(this));
- connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(slotEditorDestroyed(QObject*)));
+ connect(editor, &QObject::destroyed,
+ this, &QtPropertyEditorDelegate::slotEditorDestroyed);
m_propertyToEditor[property] = editor;
m_editorToProperty[editor] = property;
m_editedItem = item;
@@ -317,7 +294,7 @@ QWidget *QtPropertyEditorDelegate::createEditor(QWidget *parent,
return editor;
}
}
- return 0;
+ return nullptr;
}
void QtPropertyEditorDelegate::updateEditorGeometry(QWidget *editor,
@@ -347,7 +324,10 @@ void QtPropertyEditorDelegate::paint(QPainter *painter, const QStyleOptionViewIt
QColor c;
if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) {
c = opt.palette.color(QPalette::Dark);
- opt.palette.setColor(QPalette::Text, opt.palette.color(QPalette::BrightText));
+ // Hardcode "white" for Windows/light which is otherwise blue
+ const QColor textColor = isWindows && isLightTheme()
+ ? QColor(Qt::white) : opt.palette.color(QPalette::BrightText);
+ opt.palette.setColor(QPalette::Text, textColor);
} else {
c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index));
if (c.isValid() && (opt.features & QStyleOptionViewItem::Alternate))
@@ -427,7 +407,7 @@ static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
void QtTreePropertyBrowserPrivate::init(QWidget *parent)
{
- QHBoxLayout *layout = new QHBoxLayout(parent);
+ auto *layout = new QHBoxLayout(parent);
layout->setContentsMargins(QMargins());
m_treeWidget = new QtPropertyEditorView(parent);
m_treeWidget->setEditorPrivate(this);
@@ -449,23 +429,27 @@ void QtTreePropertyBrowserPrivate::init(QWidget *parent)
m_expandIcon = drawIndicatorIcon(q_ptr->palette(), q_ptr->style());
- QObject::connect(m_treeWidget, SIGNAL(collapsed(QModelIndex)), q_ptr, SLOT(slotCollapsed(QModelIndex)));
- QObject::connect(m_treeWidget, SIGNAL(expanded(QModelIndex)), q_ptr, SLOT(slotExpanded(QModelIndex)));
- QObject::connect(m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), q_ptr, SLOT(slotCurrentTreeItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
+ QObject::connect(m_treeWidget, &QTreeView::collapsed,
+ q_ptr, [this](const QModelIndex &index) { slotCollapsed(index); });
+ QObject::connect(m_treeWidget, &QTreeView::expanded,
+ q_ptr, [this](const QModelIndex &index) { slotExpanded(index); });
+ QObject::connect(m_treeWidget, &QTreeWidget::currentItemChanged,
+ q_ptr, [this](QTreeWidgetItem *current, QTreeWidgetItem *previous)
+ { slotCurrentTreeItemChanged(current, previous); });
}
QtBrowserItem *QtTreePropertyBrowserPrivate::currentItem() const
{
if (QTreeWidgetItem *treeItem = m_treeWidget->currentItem())
return m_itemToIndex.value(treeItem);
- return 0;
+ return nullptr;
}
void QtTreePropertyBrowserPrivate::setCurrentItem(QtBrowserItem *browserItem, bool block)
{
const bool blocked = block ? m_treeWidget->blockSignals(true) : false;
- if (browserItem == 0)
- m_treeWidget->setCurrentItem(0);
+ if (browserItem == nullptr)
+ m_treeWidget->setCurrentItem(nullptr);
else
m_treeWidget->setCurrentItem(m_indexToItem.value(browserItem));
if (block)
@@ -478,7 +462,7 @@ QtProperty *QtTreePropertyBrowserPrivate::indexToProperty(const QModelIndex &ind
QtBrowserItem *idx = m_itemToIndex.value(item);
if (idx)
return idx->property();
- return 0;
+ return nullptr;
}
QtBrowserItem *QtTreePropertyBrowserPrivate::indexToBrowserItem(const QModelIndex &index) const
@@ -540,7 +524,7 @@ void QtTreePropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrow
QTreeWidgetItem *afterItem = m_indexToItem.value(afterIndex);
QTreeWidgetItem *parentItem = m_indexToItem.value(index->parent());
- QTreeWidgetItem *newItem = 0;
+ QTreeWidgetItem *newItem = nullptr;
if (parentItem) {
newItem = new QTreeWidgetItem(parentItem, afterItem);
} else {
@@ -621,14 +605,14 @@ void QtTreePropertyBrowserPrivate::updateItem(QTreeWidgetItem *item)
QColor QtTreePropertyBrowserPrivate::calculatedBackgroundColor(QtBrowserItem *item) const
{
QtBrowserItem *i = item;
- const QMap<QtBrowserItem *, QColor>::const_iterator itEnd = m_indexToBackgroundColor.constEnd();
+ const auto itEnd = m_indexToBackgroundColor.constEnd();
while (i) {
- QMap<QtBrowserItem *, QColor>::const_iterator it = m_indexToBackgroundColor.constFind(i);
+ auto it = m_indexToBackgroundColor.constFind(i);
if (it != itEnd)
return it.value();
i = i->parent();
}
- return QColor();
+ return {};
}
void QtTreePropertyBrowserPrivate::slotCollapsed(const QModelIndex &index)
@@ -668,7 +652,7 @@ QTreeWidgetItem *QtTreePropertyBrowserPrivate::editedItem() const
void QtTreePropertyBrowserPrivate::editItem(QtBrowserItem *browserItem)
{
- if (QTreeWidgetItem *treeItem = m_indexToItem.value(browserItem, 0)) {
+ if (QTreeWidgetItem *treeItem = m_indexToItem.value(browserItem, nullptr)) {
m_treeWidget->setCurrentItem (treeItem, 1);
m_treeWidget->editItem(treeItem, 1);
}
@@ -729,7 +713,9 @@ QtTreePropertyBrowser::QtTreePropertyBrowser(QWidget *parent)
d_ptr->q_ptr = this;
d_ptr->init(this);
- connect(this, SIGNAL(currentItemChanged(QtBrowserItem*)), this, SLOT(slotCurrentBrowserItemChanged(QtBrowserItem*)));
+ QObject::connect(this, &QtAbstractPropertyBrowser::currentItemChanged,
+ this, [this](QtBrowserItem *current)
+ { d_ptr->slotCurrentBrowserItemChanged(current); });
}
/*!