From 1e02d10ee35a38ba74159dd5d66350fdb2b40563 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 1 May 2015 07:59:22 +0200 Subject: [PATCH] Actions in toolbar editor are now correctly sorted in the same way as actions in keyboard shortcut editor. --- src/gui/basetoolbar.cpp | 10 ++++++++++ src/gui/basetoolbar.h | 5 ++++- src/gui/feedstoolbar.cpp | 19 +++++++------------ src/gui/feedstoolbar.h | 2 +- src/gui/messagestoolbar.cpp | 22 ++++++++++------------ src/gui/messagestoolbar.h | 2 +- src/gui/toolbareditor.cpp | 2 +- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/gui/basetoolbar.cpp b/src/gui/basetoolbar.cpp index 4c45304a9..46e226d87 100644 --- a/src/gui/basetoolbar.cpp +++ b/src/gui/basetoolbar.cpp @@ -35,3 +35,13 @@ BaseToolBar::BaseToolBar(const QString &title, QWidget *parent) BaseToolBar::~BaseToolBar() { qDebug("Destroying BaseToolBar instance."); } + +QAction *BaseToolBar::findMatchingAction(const QString &action, const QList actions) { + foreach (QAction *act, actions) { + if (act->objectName() == action) { + return act; + } + } + + return NULL; +} diff --git a/src/gui/basetoolbar.h b/src/gui/basetoolbar.h index c42a34944..e897a8059 100644 --- a/src/gui/basetoolbar.h +++ b/src/gui/basetoolbar.h @@ -30,7 +30,7 @@ class BaseToolBar : public QToolBar { virtual ~BaseToolBar(); // Returns all actions which can be added to the toolbar. - virtual QHash availableActions() const = 0; + virtual QList availableActions() const = 0; // Returns all changeable actions which are currently included // in the toolbar. @@ -42,6 +42,9 @@ class BaseToolBar : public QToolBar { // Loads the toolbar state from settings. virtual void loadChangeableActions() = 0; + + protected: + QAction *findMatchingAction(const QString &action, const QList actions); }; #endif // TOOLBAR_H diff --git a/src/gui/feedstoolbar.cpp b/src/gui/feedstoolbar.cpp index d19a6143b..6cd5fa625 100755 --- a/src/gui/feedstoolbar.cpp +++ b/src/gui/feedstoolbar.cpp @@ -32,15 +32,8 @@ FeedsToolBar::FeedsToolBar(const QString &title, QWidget *parent) : BaseToolBar( FeedsToolBar::~FeedsToolBar() { } -QHash FeedsToolBar::availableActions() const { - QList application_actions = qApp->userActions(); - QHash available_actions; - - foreach (QAction *application_action, application_actions) { - available_actions.insert(application_action->objectName(), application_action); - } - - return available_actions; +QList FeedsToolBar::availableActions() const { + return qApp->userActions(); } QList FeedsToolBar::changeableActions() const { @@ -60,15 +53,17 @@ void FeedsToolBar::loadChangeableActions() { } void FeedsToolBar::loadChangeableActions(const QStringList &actions) { - QHash available_actions = availableActions(); + QList available_actions = availableActions(); clear(); // Iterate action names and add respectable actions into the toolbar. foreach (const QString &action_name, actions) { - if (available_actions.contains(action_name)) { + QAction *matching_action = findMatchingAction(action_name, available_actions); + + if (matching_action != NULL) { // Add existing standard action. - addAction(available_actions.value(action_name)); + addAction(matching_action); } else if (action_name == SEPARATOR_ACTION_NAME) { // Add new separator. diff --git a/src/gui/feedstoolbar.h b/src/gui/feedstoolbar.h index 8cccd5f66..04b5ef557 100644 --- a/src/gui/feedstoolbar.h +++ b/src/gui/feedstoolbar.h @@ -29,7 +29,7 @@ class FeedsToolBar : public BaseToolBar { explicit FeedsToolBar(const QString &title, QWidget *parent = 0); virtual ~FeedsToolBar(); - QHash availableActions() const; + QList availableActions() const; QList changeableActions() const; void saveChangeableActions(const QStringList &actions); void loadChangeableActions(); diff --git a/src/gui/messagestoolbar.cpp b/src/gui/messagestoolbar.cpp index ace5097d6..73fa80a4e 100755 --- a/src/gui/messagestoolbar.cpp +++ b/src/gui/messagestoolbar.cpp @@ -38,16 +38,11 @@ MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent) MessagesToolBar::~MessagesToolBar() { } -QHash MessagesToolBar::availableActions() const { - QList application_actions = qApp->mainForm()->allActions(); - QHash available_actions; +QList MessagesToolBar::availableActions() const { + QList available_actions = qApp->mainForm()->allActions(); - foreach (QAction *application_action, application_actions) { - available_actions.insert(application_action->objectName(), application_action); - } - - available_actions.insert(SEACRH_MESSAGES_ACTION_NAME, m_actionSearchMessages); - available_actions.insert(HIGHLIGHTER_ACTION_NAME, m_actionMessageHighlighter); + available_actions.append(m_actionSearchMessages); + available_actions.append(m_actionMessageHighlighter); return available_actions; } @@ -67,20 +62,23 @@ void MessagesToolBar::saveChangeableActions(const QStringList& actions) { } void MessagesToolBar::loadChangeableActions(const QStringList& actions) { - QHash available_actions = availableActions(); + QList available_actions = availableActions(); clear(); // Iterate action names and add respectable actions into the toolbar. foreach (const QString &action_name, actions) { - if (available_actions.contains(action_name)) { + QAction *matching_action = findMatchingAction(action_name, available_actions); + + if (matching_action != NULL) { // Add existing standard action. - addAction(available_actions.value(action_name)); + addAction(matching_action); } else if (action_name == SEPARATOR_ACTION_NAME) { // Add new separator. addSeparator(); } + // TODO: tydle dve vetve asi vymazat. else if (action_name == SEACRH_MESSAGES_ACTION_NAME) { // Add search box. addAction(m_actionSearchMessages); diff --git a/src/gui/messagestoolbar.h b/src/gui/messagestoolbar.h index 0b38fa338..673df7a2f 100644 --- a/src/gui/messagestoolbar.h +++ b/src/gui/messagestoolbar.h @@ -42,7 +42,7 @@ class MessagesToolBar : public BaseToolBar { } // Implementation of BaseToolBar interface. - QHash availableActions() const; + QList availableActions() const; QList changeableActions() const; void saveChangeableActions(const QStringList &actions); void loadChangeableActions(); diff --git a/src/gui/toolbareditor.cpp b/src/gui/toolbareditor.cpp index 530f8f606..b5f4ffbf1 100755 --- a/src/gui/toolbareditor.cpp +++ b/src/gui/toolbareditor.cpp @@ -38,7 +38,7 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) { m_toolBar = tool_bar; QList activated_actions = m_toolBar->changeableActions(); - QList available_actions = m_toolBar->availableActions().values(); + QList available_actions = m_toolBar->availableActions(); foreach (QAction *action, activated_actions) { QListWidgetItem *action_item = new QListWidgetItem(action->icon(),