Improve the keypadnavigation manual test
- No need to use QSignalMapper here, replace its uses with lambdas. - Replace index 'for' loop with iterator loop, to simplify the code. Change-Id: Ide3d2db99a074c0233eb5c2fd7a9b217d804973f Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
b6688a4d49
commit
bd2c8353b4
@ -33,7 +33,6 @@
|
|||||||
#include <QFontDialog>
|
#include <QFontDialog>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSignalMapper>
|
|
||||||
#include "ui_keypadnavigation.h"
|
#include "ui_keypadnavigation.h"
|
||||||
|
|
||||||
class KeypadNavigation : public QMainWindow
|
class KeypadNavigation : public QMainWindow
|
||||||
@ -48,7 +47,7 @@ public:
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
QObject *action;
|
QAction *action;
|
||||||
QWidget *page;
|
QWidget *page;
|
||||||
} layoutMappings[] = {
|
} layoutMappings[] = {
|
||||||
{ui->m_actionLayoutVerticalSimple, ui->m_pageVerticalSimple},
|
{ui->m_actionLayoutVerticalSimple, ui->m_pageVerticalSimple},
|
||||||
@ -58,15 +57,16 @@ public:
|
|||||||
{ui->m_actionLayoutChaos, ui->m_pageChaos},
|
{ui->m_actionLayoutChaos, ui->m_pageChaos},
|
||||||
{ui->m_actionLayoutDialogs, ui->m_pageDialogs}
|
{ui->m_actionLayoutDialogs, ui->m_pageDialogs}
|
||||||
};
|
};
|
||||||
for (int i = 0; i < int(sizeof layoutMappings / sizeof layoutMappings[0]); ++i) {
|
for (auto layoutMapping : layoutMappings) {
|
||||||
connect(layoutMappings[i].action, SIGNAL(triggered()), &m_layoutSignalMapper, SLOT(map()));
|
const auto page = layoutMapping.page;
|
||||||
m_layoutSignalMapper.setMapping(layoutMappings[i].action, layoutMappings[i].page);
|
connect(layoutMapping.action, &QAction::triggered, ui->m_stackWidget,
|
||||||
|
[this, page]()
|
||||||
|
{ ui->m_stackWidget->setCurrentWidget(page); });
|
||||||
}
|
}
|
||||||
connect(&m_layoutSignalMapper, SIGNAL(mapped(QWidget*)), ui->m_stackWidget, SLOT(setCurrentWidget(QWidget*)));
|
|
||||||
|
|
||||||
#ifdef QT_KEYPAD_NAVIGATION
|
#ifdef QT_KEYPAD_NAVIGATION
|
||||||
const struct {
|
const struct {
|
||||||
QObject *action;
|
QAction *action;
|
||||||
Qt::NavigationMode mode;
|
Qt::NavigationMode mode;
|
||||||
} modeMappings[] = {
|
} modeMappings[] = {
|
||||||
{ui->m_actionModeNone, Qt::NavigationModeNone},
|
{ui->m_actionModeNone, Qt::NavigationModeNone},
|
||||||
@ -75,17 +75,17 @@ public:
|
|||||||
{ui->m_actionModeCursorAuto, Qt::NavigationModeCursorAuto},
|
{ui->m_actionModeCursorAuto, Qt::NavigationModeCursorAuto},
|
||||||
{ui->m_actionModeCursorForceVisible, Qt::NavigationModeCursorForceVisible}
|
{ui->m_actionModeCursorForceVisible, Qt::NavigationModeCursorForceVisible}
|
||||||
};
|
};
|
||||||
for (int i = 0; i < int(sizeof modeMappings / sizeof modeMappings[0]); ++i) {
|
for (auto modeMapping : modeMappings) {
|
||||||
connect(modeMappings[i].action, SIGNAL(triggered()), &m_modeSignalMapper, SLOT(map()));
|
const auto mode = modeMapping.mode;
|
||||||
m_modeSignalMapper.setMapping(modeMappings[i].action, int(modeMappings[i].mode));
|
connect(modeMapping.action, &QAction::triggered, this,
|
||||||
|
[this, mode]() { setNavigationMode(mode); });
|
||||||
}
|
}
|
||||||
connect(&m_modeSignalMapper, SIGNAL(mapped(int)), SLOT(setNavigationMode(int)));
|
|
||||||
#else // QT_KEYPAD_NAVIGATION
|
#else // QT_KEYPAD_NAVIGATION
|
||||||
ui->m_menuNavigation_mode->deleteLater();
|
ui->m_menuNavigation_mode->deleteLater();
|
||||||
#endif // QT_KEYPAD_NAVIGATION
|
#endif // QT_KEYPAD_NAVIGATION
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
QObject *button;
|
QPushButton *button;
|
||||||
Dialog dialog;
|
Dialog dialog;
|
||||||
} openDialogMappings[] = {
|
} openDialogMappings[] = {
|
||||||
{ui->m_buttonGetOpenFileName, DialogGetOpenFileName},
|
{ui->m_buttonGetOpenFileName, DialogGetOpenFileName},
|
||||||
@ -97,11 +97,11 @@ public:
|
|||||||
{ui->m_buttonAboutQt, DialogAboutQt},
|
{ui->m_buttonAboutQt, DialogAboutQt},
|
||||||
{ui->m_buttonGetItem, DialogGetItem}
|
{ui->m_buttonGetItem, DialogGetItem}
|
||||||
};
|
};
|
||||||
for (int i = 0; i < int(sizeof openDialogMappings / sizeof openDialogMappings[0]); ++i) {
|
for (auto openDialogMapping : openDialogMappings) {
|
||||||
connect(openDialogMappings[i].button, SIGNAL(clicked()), &m_dialogSignalMapper, SLOT(map()));
|
const auto dialog = openDialogMapping.dialog;
|
||||||
m_dialogSignalMapper.setMapping(openDialogMappings[i].button, int(openDialogMappings[i].dialog));
|
connect(openDialogMapping.button, &QPushButton::clicked, this,
|
||||||
|
[this, dialog]() { openDialog(dialog); });
|
||||||
}
|
}
|
||||||
connect(&m_dialogSignalMapper, SIGNAL(mapped(int)), SLOT(openDialog(int)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~KeypadNavigation()
|
~KeypadNavigation()
|
||||||
@ -162,11 +162,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ui_KeypadNavigation *ui;
|
Ui_KeypadNavigation *ui;
|
||||||
QSignalMapper m_layoutSignalMapper;
|
|
||||||
#ifdef QT_KEYPAD_NAVIGATION
|
|
||||||
QSignalMapper m_modeSignalMapper;
|
|
||||||
#endif // QT_KEYPAD_NAVIGATION
|
|
||||||
QSignalMapper m_dialogSignalMapper;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user