Actions in toolbar editor are now correctly sorted in the same way as actions in keyboard shortcut editor.

This commit is contained in:
Martin Rotter 2015-05-01 07:59:22 +02:00
parent df75619a6d
commit 1e02d10ee3
7 changed files with 34 additions and 28 deletions

@ -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<QAction*> actions) {
foreach (QAction *act, actions) {
if (act->objectName() == action) {
return act;
}
}
return NULL;
}

@ -30,7 +30,7 @@ class BaseToolBar : public QToolBar {
virtual ~BaseToolBar();
// Returns all actions which can be added to the toolbar.
virtual QHash<QString, QAction*> availableActions() const = 0;
virtual QList<QAction*> 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<QAction*> actions);
};
#endif // TOOLBAR_H

@ -32,15 +32,8 @@ FeedsToolBar::FeedsToolBar(const QString &title, QWidget *parent) : BaseToolBar(
FeedsToolBar::~FeedsToolBar() {
}
QHash<QString, QAction*> FeedsToolBar::availableActions() const {
QList<QAction*> application_actions = qApp->userActions();
QHash<QString, QAction*> available_actions;
foreach (QAction *application_action, application_actions) {
available_actions.insert(application_action->objectName(), application_action);
}
return available_actions;
QList<QAction*> FeedsToolBar::availableActions() const {
return qApp->userActions();
}
QList<QAction*> FeedsToolBar::changeableActions() const {
@ -60,15 +53,17 @@ void FeedsToolBar::loadChangeableActions() {
}
void FeedsToolBar::loadChangeableActions(const QStringList &actions) {
QHash<QString, QAction*> available_actions = availableActions();
QList<QAction*> 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.

@ -29,7 +29,7 @@ class FeedsToolBar : public BaseToolBar {
explicit FeedsToolBar(const QString &title, QWidget *parent = 0);
virtual ~FeedsToolBar();
QHash<QString, QAction*> availableActions() const;
QList<QAction*> availableActions() const;
QList<QAction*> changeableActions() const;
void saveChangeableActions(const QStringList &actions);
void loadChangeableActions();

@ -38,16 +38,11 @@ MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
MessagesToolBar::~MessagesToolBar() {
}
QHash<QString, QAction*> MessagesToolBar::availableActions() const {
QList<QAction*> application_actions = qApp->mainForm()->allActions();
QHash<QString, QAction*> available_actions;
QList<QAction*> MessagesToolBar::availableActions() const {
QList<QAction*> 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<QString, QAction*> available_actions = availableActions();
QList<QAction*> 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);

@ -42,7 +42,7 @@ class MessagesToolBar : public BaseToolBar {
}
// Implementation of BaseToolBar interface.
QHash<QString, QAction*> availableActions() const;
QList<QAction*> availableActions() const;
QList<QAction*> changeableActions() const;
void saveChangeableActions(const QStringList &actions);
void loadChangeableActions();

@ -38,7 +38,7 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) {
m_toolBar = tool_bar;
QList<QAction*> activated_actions = m_toolBar->changeableActions();
QList<QAction*> available_actions = m_toolBar->availableActions().values();
QList<QAction*> available_actions = m_toolBar->availableActions();
foreach (QAction *action, activated_actions) {
QListWidgetItem *action_item = new QListWidgetItem(action->icon(),