Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #869892 ยป 0037-Qt-Replace-deprecate-QSignalMapper-uses-with-lambdas.patch

Marko Lindqvist, 2020-04-29 03:55 PM

View differences:

client/gui-qt/dialogs.cpp
#include <QPainterPath>
#include <QRadioButton>
#include <QRect>
#include <QSignalMapper>
#include <QTableWidgetItem>
#include <QTextEdit>
#include <QVBoxLayout>
......
QLabel *l = new QLabel(text);
setProperty("themed_choice", true);
signal_mapper = new QSignalMapper(this);
layout = new QVBoxLayout(this);
run_on_close = run_on_close_in;
......
{
buttons_list.clear();
action_button_map.clear();
delete signal_mapper;
gui()->set_diplo_dialog(NULL);
if (run_on_close) {
......
***************************************************************************/
void choice_dialog::set_layout()
{
targeted_unit = game_unit_by_number(target_id[ATK_UNIT]);
if ((game_unit_by_number(unit_id)) && targeted_unit
......
connect(next, &QAbstractButton::clicked, this, &choice_dialog::next_unit);
}
connect(signal_mapper, SIGNAL(mapped(const int &)),
this, SLOT(execute_action(const int &)));
setLayout(layout);
}
......
{
Choice_dialog_button *button = new Choice_dialog_button(title, func,
data1, data2);
connect(button, SIGNAL(clicked()), signal_mapper, SLOT(map()));
signal_mapper->setMapping(button, buttons_list.count());
int action = buttons_list.count();
QObject::connect(button, &QPushButton::clicked, [=]() {
execute_action(action);
});
buttons_list.append(button);
if (!tool_tip.isEmpty()) {
......
* before unstack_all_buttons() is called. */
layout->removeWidget(button);
/* The old mappings may not be valid after reinsertion. */
signal_mapper->removeMappings(button);
/* Synchronize the list with the layout. */
buttons_list.removeAll(button);
}
......
while (!last_buttons_stack.isEmpty()) {
Choice_dialog_button *button = last_buttons_stack.takeLast();
/* Restore mapping. */
signal_mapper->setMapping(button, buttons_list.count());
/* Reinsert the button below the other buttons. */
buttons_list.append(button);
layout->addWidget(button);
client/gui-qt/dialogs.h
class QGroupBox;
class QItemSelection;
class QRadioButton;
class QSignalMapper;
class QTableView;
class QTableWidget;
class QTextEdit;
......
{
Q_OBJECT
QPushButton *target_unit_button;
QSignalMapper *signal_mapper;
QVBoxLayout *layout;
QHBoxLayout *unit_skip;
QList<Choice_dialog_button *> buttons_list;
client/gui-qt/fc_client.cpp
#include <QResizeEvent>
#include <QScrollBar>
#include <QSettings>
#include <QSignalMapper>
#include <QSocketNotifier>
#include <QSpinBox>
#include <QStackedLayout>
......
status_bar->addWidget(status_bar_label, 1);
set_status_bar(_("Welcome to Freeciv"));
create_cursors();
switch_page_mapper = new QSignalMapper(this);
// PAGE_MAIN
pages[PAGE_MAIN] = new QWidget(central_wdg);
page = PAGE_MAIN;
......
central_wdg->setLayout(central_layout);
setCentralWidget(central_wdg);
connect(switch_page_mapper, SIGNAL(mapped( int)),
this, SLOT(switch_page(int)));
resize(pages[PAGE_MAIN]->minimumSizeHint());
setVisible(true);
client/gui-qt/fc_client.h
QTimer *update_info_timer;
QStatusBar *status_bar;
QSignalMapper *switch_page_mapper;
QLabel *status_bar_label;
info_tile *info_tile_wdg;
choice_dialog *opened_dialog;
client/gui-qt/menu.cpp
#include <QMainWindow>
#include <QMessageBox>
#include <QScrollArea>
#include <QSignalMapper>
#include <QStandardPaths>
#include <QVBoxLayout>
......
Creates a new government menu.
**************************************************************************/
gov_menu::gov_menu(QWidget* parent) :
QMenu(_("Government"), parent),
gov_mapper(new QSignalMapper())
QMenu(_("Government"), parent)
{
// Register ourselves to get updates for free.
instances << this;
......
**************************************************************************/
gov_menu::~gov_menu()
{
delete gov_mapper;
qDeleteAll(actions);
instances.remove(this);
}
......
action->deleteLater();
}
actions.clear();
gov_mapper->deleteLater();
gov_mapper = new QSignalMapper();
gov_count = government_count();
actions.reserve(gov_count + 1);
......
// We need to keep track of the gov <-> action mapping to be able to
// set enabled/disabled depending on available govs.
actions.append(action);
connect(action, SIGNAL(triggered()), gov_mapper, SLOT(map()));
gov_mapper->setMapping(action, i);
QObject::connect(action, &QAction::triggered, [this,i]() {
change_gov(i);
});
}
}
connect(gov_mapper, SIGNAL(mapped(int)), this, SLOT(change_gov(int)));
}
/**********************************************************************//**
......
go_act_menu::go_act_menu(QWidget* parent)
: QMenu(_("Go to and..."), parent)
{
go_act_mapper = new QSignalMapper(this);
/* Will need auto updates etc. */
instances << this;
}
......
/* Clear menu item to action ID mapping. */
items.clear();
/* Reset the Qt signal mapper */
go_act_mapper->deleteLater();
go_act_mapper = new QSignalMapper(this);
}
/**********************************************************************//**
......
ADD_OLD_SHORTCUT(ACTION_JOIN_CITY, SC_GOJOINCITY);
ADD_OLD_SHORTCUT(ACTION_NUKE, SC_NUKE);
connect(item, SIGNAL(triggered()),
go_act_mapper, SLOT(map()));
go_act_mapper->setMapping(item, act_id);
QObject::connect(item, &QAction::triggered, [this,act_id]() {
start_go_act(act_id);
});
} action_iterate_end;
}
connect(go_act_mapper, SIGNAL(mapped(int)), this, SLOT(start_go_act(int)));
}
/**********************************************************************//**
......
act->setShortcut(QKeySequence(tr("shift+e")));
connect(act, &QAction::triggered, this, &mr_menu::slot_unit_airbase);
bases_menu = menu->addMenu(_("Build Base"));
build_bases_mapper = new QSignalMapper(this);
menu->addSeparator();
act = menu->addAction(_("Pillage"));
menu_list.insertMulti(PILLAGE, act);
......
fc_shortcuts::sc()->get_shortcut(SC_BUILDROAD))));
connect(act, &QAction::triggered, this, &mr_menu::slot_build_road);
roads_menu = menu->addMenu(_("Build Path"));
build_roads_mapper = new QSignalMapper(this);
act = menu->addAction(_("Build Irrigation"));
act->setShortcut(QKeySequence(shortcut_to_string(
fc_shortcuts::sc()->get_shortcut(SC_BUILDIRRIGATION))));
......
/* Help Menu */
menu = this->addMenu(_("Help"));
signal_help_mapper = new QSignalMapper(this);
connect(signal_help_mapper, SIGNAL(mapped(const QString &)),
this, SLOT(slot_help(const QString &)));
act = menu->addAction(Q_(HELP_OVERVIEW_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_OVERVIEW_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_OVERVIEW_ITEM);
});
act = menu->addAction(Q_(HELP_PLAYING_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_PLAYING_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_PLAYING_ITEM);
});
act = menu->addAction(Q_(HELP_TERRAIN_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_TERRAIN_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_TERRAIN_ITEM);
});
act = menu->addAction(Q_(HELP_ECONOMY_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_ECONOMY_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_ECONOMY_ITEM);
});
act = menu->addAction(Q_(HELP_CITIES_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_CITIES_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_CITIES_ITEM);
});
act = menu->addAction(Q_(HELP_IMPROVEMENTS_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_IMPROVEMENTS_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_IMPROVEMENTS_ITEM);
});
act = menu->addAction(Q_(HELP_WONDERS_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_WONDERS_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_WONDERS_ITEM);
});
act = menu->addAction(Q_(HELP_UNITS_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_UNITS_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_UNITS_ITEM);
});
act = menu->addAction(Q_(HELP_COMBAT_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_COMBAT_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_COMBAT_ITEM);
});
act = menu->addAction(Q_(HELP_ZOC_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_ZOC_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_ZOC_ITEM);
});
act = menu->addAction(Q_(HELP_GOVERNMENT_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_GOVERNMENT_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_GOVERNMENT_ITEM);
});
act = menu->addAction(Q_(HELP_ECONOMY_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_ECONOMY_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_ECONOMY_ITEM);
});
act = menu->addAction(Q_(HELP_DIPLOMACY_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_DIPLOMACY_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_DIPLOMACY_ITEM);
});
act = menu->addAction(Q_(HELP_TECHS_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_TECHS_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_TECHS_ITEM);
});
act = menu->addAction(Q_(HELP_SPACE_RACE_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_SPACE_RACE_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_SPACE_RACE_ITEM);
});
act = menu->addAction(Q_(HELP_IMPROVEMENTS_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_IMPROVEMENTS_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_IMPROVEMENTS_ITEM);
});
act = menu->addAction(Q_(HELP_RULESET_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_RULESET_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_RULESET_ITEM);
});
act = menu->addAction(Q_(HELP_NATIONS_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_NATIONS_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_NATIONS_ITEM);
});
menu->addSeparator();
act = menu->addAction(Q_(HELP_CONNECTING_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_CONNECTING_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_CONNECTING_ITEM);
});
act = menu->addAction(Q_(HELP_CONTROLS_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_CONTROLS_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_CONTROLS_ITEM);
});
act = menu->addAction(Q_(HELP_CMA_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_CMA_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_CMA_ITEM);
});
act = menu->addAction(Q_(HELP_CHATLINE_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_CHATLINE_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_CHATLINE_ITEM);
});
act = menu->addAction(Q_(HELP_WORKLIST_EDITOR_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_WORKLIST_EDITOR_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_WORKLIST_EDITOR_ITEM);
});
menu->addSeparator();
act = menu->addAction(Q_(HELP_LANGUAGES_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_LANGUAGES_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_LANGUAGES_ITEM);
});
act = menu->addAction(Q_(HELP_COPYING_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_COPYING_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_COPYING_ITEM);
});
act = menu->addAction(Q_(HELP_ABOUT_ITEM));
connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
signal_help_mapper->setMapping(act, HELP_ABOUT_ITEM);
QObject::connect(act, &QAction::triggered, [this]() {
slot_help(HELP_ABOUT_ITEM);
});
menus = this->findChildren<QMenu*>();
for (i = 0; i < menus.count(); i++) {
......
removeAction(act);
act->deleteLater();
}
build_roads_mapper->removeMappings(this);
roads_menu->clear();
roads_menu->setDisabled(true);
if (client_is_observer()) {
......
punits = get_units_in_focus();
extra_type_by_cause_iterate(EC_ROAD, pextra) {
if (pextra->buildable) {
int road_id;
// Defeat keyboard shortcut mnemonics
act = roads_menu->addAction(QString(extra_name_translation(pextra))
.replace("&", "&&"));
act->setData(pextra->id);
connect(act, SIGNAL(triggered()),
build_roads_mapper, SLOT(map()));
build_roads_mapper->setMapping(act, pextra->id);
road_id = pextra->id;
act->setData(road_id);
QObject::connect(act, &QAction::triggered, [this,road_id]() {
slot_build_path(road_id);
});
if (can_units_do_activity_targeted(punits,
ACTIVITY_GEN_ROAD, pextra)) {
act->setEnabled(true);
......
}
}
} extra_type_by_cause_iterate_end;
connect(build_roads_mapper, SIGNAL(mapped(int)), this,
SLOT(slot_build_path(int)));
if (enabled) {
roads_menu->setEnabled(true);
}
......
removeAction(act);
act->deleteLater();
}
build_bases_mapper->removeMappings(this);
bases_menu->clear();
bases_menu->setDisabled(true);
......
punits = get_units_in_focus();
extra_type_by_cause_iterate(EC_BASE, pextra) {
if (pextra->buildable) {
int base_id;
// Defeat keyboard shortcut mnemonics
act = bases_menu->addAction(QString(extra_name_translation(pextra))
.replace("&", "&&"));
act->setData(pextra->id);
connect(act, SIGNAL(triggered()),
build_bases_mapper, SLOT(map()));
build_bases_mapper->setMapping(act, pextra->id);
base_id = pextra->id;
act->setData(base_id);
QObject::connect(act, &QAction::triggered, [this,base_id]() {
slot_build_base(base_id);
});
if (can_units_do_activity_targeted(punits, ACTIVITY_BASE, pextra)) {
act->setEnabled(true);
enabled = true;
......
}
}
} extra_type_by_cause_iterate_end;
connect(build_bases_mapper, SIGNAL(mapped(int)), this,
SLOT(slot_build_base(int)));
if (enabled) {
bases_menu->setEnabled(true);
}
client/gui-qt/menu.h
class QLabel;
class QPushButton;
class QSignalMapper;
class QScrollArea;
struct fc_shortcut;
......
Q_OBJECT
static QSet<gov_menu *> instances;
QSignalMapper *gov_mapper;
QVector<QAction *> actions;
public:
......
Q_OBJECT
static QSet<go_act_menu *> instances;
QSignalMapper *go_act_mapper;
QMap<QAction *, int> items;
public:
......
private:
struct tile* find_last_unit_pos(struct unit* punit, int pos);
QSignalMapper *signal_help_mapper;
QSignalMapper *build_bases_mapper;
QSignalMapper *build_roads_mapper;
};
#endif /* FC__MENU_H */
client/gui-qt/optiondlg.cpp
#include <QPainter>
#include <QPushButton>
#include <QScrollArea>
#include <QSignalMapper>
#include <QSpinBox>
// utility
......
curr_options = options;
setWindowTitle(name);
tab_widget = new QTabWidget;
signal_map = new QSignalMapper;
button_box = new QDialogButtonBox();
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogCancelButton),
_("Cancel"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_CANCEL);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_CANCEL);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogResetButton),
_("Reset"));
button_box->addButton(but, QDialogButtonBox::ResetRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_RESET);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_RESET);
});
but = new QPushButton(QIcon::fromTheme("view-refresh"), _("Refresh"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_REFRESH);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_REFRESH);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton),
_("Apply"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_APPLY);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_APPLY);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
_("Save"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_SAVE);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_SAVE);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
_("Ok"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_OK);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_OK);
});
main_layout = new QVBoxLayout;
main_layout->addWidget(tab_widget);
......
main_layout->addWidget(button_box);
setLayout(main_layout);
connect(signal_map, SIGNAL(mapped(int)), this, SLOT(apply_option(int)));
setAttribute(Qt::WA_DeleteOnClose);
}
client/gui-qt/optiondlg.h
class QVBoxLayout;
class QTabWidget;
class QDialogButtonBox;
class QSignalMapper;
class QWidget;
class QString;
......
QDialogButtonBox *button_box;
QList <QString> categories;
QMap <QString, QWidget *> widget_map;
QSignalMapper *signal_map;
public:
option_dialog(const QString &name, const option_set *options,
client/gui-qt/pages.cpp
#include <QHeaderView>
#include <QLineEdit>
#include <QPainter>
#include <QSignalMapper>
#include <QSplitter>
#include <QStackedWidget>
#include <QTableWidget>
......
break;
case 1:
pages_layout[PAGE_MAIN]->addWidget(button, row + 2, 0);
connect(button, SIGNAL(clicked()), switch_page_mapper, SLOT(map()));
switch_page_mapper->setMapping(button, PAGE_SCENARIO);
QObject::connect(button, &QPushButton::clicked, [this]() {
switch_page(PAGE_SCENARIO);
});
break;
case 2:
pages_layout[PAGE_MAIN]->addWidget(button, row + 3, 0);
connect(button, SIGNAL(clicked()), switch_page_mapper, SLOT(map()));
switch_page_mapper->setMapping(button, PAGE_LOAD);
QObject::connect(button, &QPushButton::clicked, [this]() {
switch_page(PAGE_LOAD);
});
break;
case 3:
pages_layout[PAGE_MAIN]->addWidget(button, row + 1, 1);
connect(button, SIGNAL(clicked()), switch_page_mapper, SLOT(map()));
switch_page_mapper->setMapping(button, PAGE_NETWORK);
QObject::connect(button, &QPushButton::clicked, [this]() {
switch_page(PAGE_NETWORK);
});
break;
case 4:
pages_layout[PAGE_MAIN]->addWidget(button, row + 2, 1);
......
page_network_grid_layout->addWidget(network_button, 5, 0);
network_button = new QPushButton(_("Cancel"));
connect(network_button, SIGNAL(clicked()), switch_page_mapper,
SLOT(map()));
switch_page_mapper->setMapping(network_button, PAGE_MAIN);
QObject::connect(network_button, &QPushButton::clicked, [this]() {
switch_page(PAGE_MAIN);
});
page_network_grid_layout->addWidget(network_button, 5, 2, 1, 1);
network_button = new QPushButton(_("Connect"));
......
but->setText(_("Browse..."));
but->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon));
connect(but, &QAbstractButton::clicked, this, &fc_client::browse_saves);
pages_layout[PAGE_LOAD]->addWidget (but, 3, 0);
pages_layout[PAGE_LOAD]->addWidget(but, 3, 0);
but = new QPushButton;
but->setText(_("Cancel"));
but->setIcon(QApplication::style()->standardIcon(
QStyle::SP_DialogCancelButton));
connect(but, &QAbstractButton::clicked, this, &fc_client::slot_disconnect);
switch_page_mapper->setMapping(but, PAGE_MAIN);
pages_layout[PAGE_LOAD]->addWidget(but, 3, 2);
but = new QPushButton;
......
but->setIcon(QApplication::style()->standardIcon(
QStyle::SP_DialogCancelButton));
connect(but, &QAbstractButton::clicked, this, &fc_client::slot_disconnect);
switch_page_mapper->setMapping(but, PAGE_MAIN);
pages_layout[PAGE_SCENARIO]->addWidget(but, 4, 3);
pages_layout[PAGE_SCENARIO]->setColumnStretch(2, 10);
......
bool need_empty_team;
const char *level_cmd, *level_name;
int level, count;
QSignalMapper *player_menu_mapper;
player *selected_player;
QVariant qvar, qvar2;
......
if (qvar == 1) {
selected_player = (player *) qvar2.value < void *>();
}
player_menu_mapper = new QSignalMapper;
players_iterate(pplayer) {
if (selected_player && selected_player == pplayer) {
splayer = QString(pplayer->name);
......
str = QString(_("Observe"));
action = new QAction(str, start_players_tree);
str = "/observe " + sp;
connect(action, SIGNAL(triggered()), player_menu_mapper,
SLOT(map()));
player_menu_mapper->setMapping(action, str);
QObject::connect(action, &QAction::triggered, [this,str]() {
send_fake_chat_message(str);
});
menu->addAction(action);
if (ALLOW_CTRL <= client.conn.access_level) {
str = QString(_("Remove player"));
action = new QAction(str, start_players_tree);
str = "/remove " + sp;
connect(action, SIGNAL(triggered()), player_menu_mapper,
SLOT(map()));
player_menu_mapper->setMapping(action, str);
QObject::connect(action, &QAction::triggered, [this,str]() {
send_fake_chat_message(str);
});
menu->addAction(action);
}
str = QString(_("Take this player"));
action = new QAction(str, start_players_tree);
str = "/take " + sp;
connect(action, SIGNAL(triggered()), player_menu_mapper,
SLOT(map()));
player_menu_mapper->setMapping(action, str);
QObject::connect(action, &QAction::triggered, [this,str]() {
send_fake_chat_message(str);
});
menu->addAction(action);
}
......
str = QString(_("Pick nation"));
action = new QAction(str, start_players_tree);
str = "PICK:" + QString(player_name(pplayer)); /* PICK is a key */
connect(action, SIGNAL(triggered()), player_menu_mapper,
SLOT(map()));
player_menu_mapper->setMapping(action, str);
QObject::connect(action, &QAction::triggered, [this,str]() {
send_fake_chat_message(str);
});
menu->addAction(action);
}
......
level_cmd = ai_level_cmd(static_cast < ai_level > (level));
action = new QAction(QString(level_name), start_players_tree);
str = "/" + QString(level_cmd) + " " + sp;
connect(action, SIGNAL(triggered()), player_menu_mapper,
SLOT(map()));
player_menu_mapper->setMapping(action, str);
QObject::connect(action, &QAction::triggered, [this,str]() {
send_fake_chat_message(str);
});
submenu_AI->addAction(action);
}
}
......
action = new QAction(str, start_players_tree);
str = "/team" + sp + " \"" + QString(team_slot_rule_name(tslot))
+ "\"";
connect(action, SIGNAL(triggered()),
player_menu_mapper, SLOT(map()));
player_menu_mapper->setMapping(action, str);
QObject::connect(action, &QAction::triggered, [this,str]() {
send_fake_chat_message(str);
});
submenu_team->addAction(action);
} team_slots_iterate_end;
}
......
str = QString(_("Aitoggle player"));
action = new QAction(str, start_players_tree);
str = "/aitoggle " + sp;
connect(action, SIGNAL(triggered()), player_menu_mapper,
SLOT(map()));
player_menu_mapper->setMapping(action, str);
QObject::connect(action, &QAction::triggered, [this,str]() {
send_fake_chat_message(str);
});
menu->addAction(action);
}
connect(player_menu_mapper, SIGNAL(mapped(const QString &)),
this, SLOT(send_fake_chat_message(const QString &)));
menu->popup(global_pos);
return;
}
} players_iterate_end;
delete player_menu_mapper;
}
/**********************************************************************//**
client/gui-qt/pages.h
/**********************************************************************
/***********************************************************************
Freeciv - Copyright (C) 1996-2004 - The Freeciv Team
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
struct connection;
struct server_scan;
void create_conn_menu (player*, connection*);
void server_scan_error (server_scan*, const char*);
void create_conn_menu(player*, connection*);
void server_scan_error(server_scan*, const char*);
#endif /* FC__PAGES_H */
client/gui-qt/shortcuts.cpp
#include <QLineEdit>
#include <QScrollArea>
#include <QSettings>
#include <QSignalMapper>
#include <QVBoxLayout>
#include <QWidget>
......
scroll->setWidget(widget);
main_layout->addWidget(scroll);
signal_map = new QSignalMapper;
button_box = new QDialogButtonBox();
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogCancelButton),
_("Cancel"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_CANCEL);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_CANCEL);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogResetButton),
_("Reset"));
button_box->addButton(but, QDialogButtonBox::ResetRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_RESET);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_RESET);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton),
_("Apply"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_APPLY);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_APPLY);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
_("Save"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_SAVE);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_SAVE);
});
but = new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
_("Ok"));
button_box->addButton(but, QDialogButtonBox::ActionRole);
connect(but, SIGNAL(clicked()), signal_map, SLOT(map()));
signal_map->setMapping(but, RESPONSE_OK);
QObject::connect(but, &QPushButton::clicked, [this]() {
apply_option(RESPONSE_OK);
});
main_layout->addWidget(button_box);
setLayout(main_layout);
......
size.setWidth(size.width() + 10
+ style()->pixelMetric(QStyle::PM_ScrollBarExtent));
resize(size);
connect(signal_map, SIGNAL(mapped(int)), this, SLOT(apply_option(int)));
setAttribute(Qt::WA_DeleteOnClose);
}
client/gui-qt/shortcuts.h
#include <QPushButton>
class QDialogButtonBox;
class QSignalMapper;
class QVBoxLayout;
struct fc_shortcut;
......
Q_OBJECT
QVBoxLayout *main_layout;
QVBoxLayout *scroll_layout;
QSignalMapper *signal_map;
QDialogButtonBox *button_box;
QMap<shortcut_id, fc_shortcut*> *hashcopy;
void add_option(fc_shortcut *sc);
    (1-1/1)