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: Move more button to the end WB TabBar #13721

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions src/Gui/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
}
}

QString title, tooltip;

Check warning on line 258 in src/Gui/Action.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

multiple declarations in a single statement reduces readability [readability-isolate-declaration]
if (dynamic_cast<const MacroCommand*>(cmd)) {
if (auto txt = cmd->getMenuText()) {
title = QString::fromUtf8(txt);
Expand Down Expand Up @@ -306,7 +306,7 @@
return title;
}

QString Action::createToolTip(QString helpText,

Check warning on line 309 in src/Gui/Action.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

function 'createToolTip' has cognitive complexity of 34 (threshold 25) [readability-function-cognitive-complexity]
const QString & title,
const QFont &font,
const QString &shortCut,
Expand Down Expand Up @@ -627,20 +627,29 @@
this, &WorkbenchGroup::onWorkbenchActivated);
}

QAction* WorkbenchGroup::getOrCreateAction(const QString& wbName) {
if (!actionByWorkbenchName.contains(wbName)) {
actionByWorkbenchName[wbName] = new QAction;
}

return actionByWorkbenchName[wbName];
}

void WorkbenchGroup::addTo(QWidget *widget)
{
if (widget->inherits("QToolBar")) {
ParameterGrp::handle hGrp;
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Workbenches");
QWidget* wbSel;

QWidget* workbenchSelectorWidget;
if (hGrp->GetInt("WorkbenchSelectorType", 0) == 0) {
wbSel = new WorkbenchComboBox(this, widget);
workbenchSelectorWidget = new WorkbenchComboBox(this, widget);
}
else {
wbSel = new WorkbenchTabWidget(this, widget);
workbenchSelectorWidget = new WorkbenchTabWidget(this, widget);
}

static_cast<QToolBar*>(widget)->addWidget(wbSel);
static_cast<QToolBar*>(widget)->addWidget(workbenchSelectorWidget);
}
else if (widget->inherits("QMenu")) {
auto menu = qobject_cast<QMenu*>(widget);
Expand All @@ -656,26 +665,30 @@

void WorkbenchGroup::refreshWorkbenchList()
{
QStringList enabled_wbs_list = DlgSettingsWorkbenchesImp::getEnabledWorkbenches();
QStringList enabledWbNames = DlgSettingsWorkbenchesImp::getEnabledWorkbenches();

// Clear the actions.
for (QAction* action : actions()) {
groupAction()->removeAction(action);
delete action;
}

enabledWbsActions.clear();
disabledWbsActions.clear();

std::string activeWbName = WorkbenchManager::instance()->activeName();

// Create action list of enabled wb
int index = 0;
for (const auto& wbName : enabled_wbs_list) {
for (const auto& wbName : enabledWbNames) {
QString name = Application::Instance->workbenchMenuText(wbName);
QPixmap px = Application::Instance->workbenchIcon(wbName);
QString tip = Application::Instance->workbenchToolTip(wbName);

QAction* action = groupAction()->addAction(name);
QAction* action = getOrCreateAction(wbName);

groupAction()->addAction(action);

action->setText(name);
action->setCheckable(true);
action->setData(QVariant(index)); // set the index
action->setObjectName(wbName);
Expand All @@ -693,13 +706,17 @@
}

// Also create action list of disabled wbs
QStringList disabled_wbs_list = DlgSettingsWorkbenchesImp::getDisabledWorkbenches();
for (const auto& wbName : disabled_wbs_list) {
QStringList disabledWbNames = DlgSettingsWorkbenchesImp::getDisabledWorkbenches();
for (const auto& wbName : disabledWbNames) {
QString name = Application::Instance->workbenchMenuText(wbName);
QPixmap px = Application::Instance->workbenchIcon(wbName);
QString tip = Application::Instance->workbenchToolTip(wbName);

QAction* action = groupAction()->addAction(name);
QAction* action = getOrCreateAction(wbName);

groupAction()->addAction(action);

action->setText(name);
action->setCheckable(true);
action->setData(QVariant(index)); // set the index
action->setObjectName(wbName);
Expand Down Expand Up @@ -1360,4 +1377,4 @@
}
}

#include "moc_Action.cpp"

Check failure on line 1380 in src/Gui/Action.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'moc_Action.cpp' file not found [clang-diagnostic-error]
10 changes: 8 additions & 2 deletions src/Gui/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QAction>
#include <QComboBox>
#include <QKeySequence>
#include <QMap>
#include <FCGlobal.h>

namespace Gui
Expand Down Expand Up @@ -188,13 +189,16 @@ class GuiExport WorkbenchGroup : public ActionGroup
{
Q_OBJECT

QAction* getOrCreateAction(const QString& wbName);

public:
/**
* Creates an action for the command \a pcCmd to load the workbench \a name
* when it gets activated.
*/
WorkbenchGroup (Command* pcCmd, QObject * parent);
void addTo (QWidget * widget) override;
WorkbenchGroup(Command* pcCmd, QObject* parent);

void addTo(QWidget * widget) override;
void refreshWorkbenchList();

void slotActivateWorkbench(const char*);
Expand All @@ -212,6 +216,8 @@ protected Q_SLOTS:
QList<QAction*> enabledWbsActions;
QList<QAction*> disabledWbsActions;

QMap<QString, QAction*> actionByWorkbenchName;

Q_DISABLE_COPY(WorkbenchGroup)
};

Expand Down
Loading
Loading