Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gui: Fix black tooltip #13649

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Gui/DlgPreferencesImp.cpp
Expand Up @@ -48,7 +48,7 @@
#include <Base/Tools.h>

#include "DlgPreferencesImp.h"
#include "ui_DlgPreferences.h"

Check failure on line 51 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'ui_DlgPreferences.h' file not found [clang-diagnostic-error]
#include "BitmapFactory.h"
#include "MainWindow.h"
#include "Tools.h"
Expand All @@ -56,7 +56,7 @@

using namespace Gui::Dialog;

bool isParentOf(const QModelIndex& parent, const QModelIndex& child)

Check warning on line 59 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

2 adjacent parameters of 'isParentOf' of similar type ('const QModelIndex &') are easily swapped by mistake [bugprone-easily-swappable-parameters]
{
for (auto it = child; it.isValid(); it = it.parent()) {
if (it == parent) {
Expand All @@ -78,6 +78,29 @@
return root;
}

// ----------------------------------------------------------------------------

PreferencesDelegate::PreferencesDelegate(QObject* parent)
: QStyledItemDelegate(parent)
{}

bool PreferencesDelegate::helpEvent(QHelpEvent *event,
QAbstractItemView *view,
const QStyleOptionViewItem &option,
const QModelIndex &index)
{
if (event->type() == QEvent::ToolTip) {
QHelpEvent* he = static_cast<QHelpEvent*>(event);

Check warning on line 93 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
QString tooltip = index.isValid() ? index.data(Qt::ToolTipRole).toString() : QString();
QToolTip::showText(he->globalPos(), tooltip);
event->setAccepted(!tooltip.isEmpty());
return true;
}
return QStyledItemDelegate::helpEvent(event, view, option, index);
}

// ----------------------------------------------------------------------------

QWidget* PreferencesPageItem::getWidget() const
{
return _widget;
Expand Down Expand Up @@ -136,6 +159,7 @@
setupConnections();

ui->groupsTreeView->setModel(&_model);
ui->groupsTreeView->setItemDelegate(new PreferencesDelegate(this));

setupPages();

Expand Down Expand Up @@ -203,7 +227,7 @@
updatePageDependentWidgets();
}

QPixmap DlgPreferencesImp::loadIconForGroup(const std::string &name) const

Check warning on line 230 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

method 'loadIconForGroup' can be made static [readability-convert-member-functions-to-static]
{
// normalize file name
auto normalizeName = [](std::string str) {
Expand Down Expand Up @@ -248,7 +272,7 @@
QString tooltip;
getGroupData(groupName, iconName, tooltip);

auto groupPages = new QStackedWidget;

Check warning on line 275 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

initializing non-owner 'QStackedWidget *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]
groupPages->setProperty(GroupNameProperty, QVariant(groupNameQString));

connect(groupPages,
Expand All @@ -262,7 +286,7 @@
}
ui->groupWidgetStack->addWidget(groupPages);

auto item = new PreferencesPageItem;

Check warning on line 289 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

initializing non-owner 'Gui::Dialog::PreferencesPageItem *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]

item->setData(QVariant(groupNameQString), GroupNameRole);
item->setText(QObject::tr(groupNameQString.toLatin1()));
Expand Down Expand Up @@ -310,7 +334,7 @@
return;
}

auto pageItem = new PreferencesPageItem;

Check warning on line 337 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

initializing non-owner 'Gui::Dialog::PreferencesPageItem *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]

pageItem->setText(page->windowTitle());
pageItem->setEditable(false);
Expand Down Expand Up @@ -382,7 +406,7 @@
* @see WidgetFactory
* @see PrefPageProducer
*/
void DlgPreferencesImp::addPage(const std::string& className, const std::string& group)

Check warning on line 409 in src/Gui/DlgPreferencesImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

2 adjacent parameters of 'addPage' of similar type ('const std::string &') are easily swapped by mistake [bugprone-easily-swappable-parameters]
{
auto groupToAddTo = _pages.end();
for (auto it = _pages.begin(); it != _pages.end(); ++it) {
Expand Down
14 changes: 14 additions & 0 deletions src/Gui/DlgPreferencesImp.h
Expand Up @@ -27,6 +27,7 @@
#define GUI_DIALOG_DLGPREFERENCESIMP_H

#include <QDialog>
#include <QStyledItemDelegate>
#include <QStandardItemModel>
#include <QStackedWidget>
#include <memory>
Expand Down Expand Up @@ -56,6 +57,19 @@ class PreferencesPageItem : public QStandardItem
bool _expanded = false;
};

class PreferencesDelegate : public QStyledItemDelegate
{
Q_OBJECT

public:
explicit PreferencesDelegate(QObject *parent = nullptr);

bool helpEvent(QHelpEvent *event,
QAbstractItemView *view,
const QStyleOptionViewItem &option,
const QModelIndex &index) override;
};

/**
* This class implements a dialog containing several preference pages.
*
Expand Down