From 816883ca8ec9580d9fde3538faeeeb2773bc2131 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 26 Oct 2019 20:14:26 +0800 Subject: [PATCH] =?UTF-8?q?stl:=20QMap=20=E5=88=87=E6=8D=A2=E4=B8=BA=20std?= =?UTF-8?q?::map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/qt/gamecontroller.cpp | 12 ++++++++---- src/ui/qt/gamecontroller.h | 7 +++++-- src/ui/qt/gamewindow.cpp | 13 ++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/ui/qt/gamecontroller.cpp b/src/ui/qt/gamecontroller.cpp index 6cd31fdf..65b2ea27 100644 --- a/src/ui/qt/gamecontroller.cpp +++ b/src/ui/qt/gamecontroller.cpp @@ -19,6 +19,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#include + #include #include #include @@ -36,6 +38,8 @@ #include "client.h" #include "option.h" +using namespace std; + GameController::GameController(GameScene & scene, QObject * parent) : QObject(parent), scene(scene), @@ -106,18 +110,18 @@ GameController::~GameController() #endif /* ENDGAME_LEARNING */ } -const QMap GameController::getActions() +const map GameController::getActions() { // 主窗口更新菜单栏 // 之所以不用信号和槽的模式,是因为发信号的时候槽还来不及关联 - QMap actions; + map actions; for (int i = 0; i < N_RULES; i++) { - // QMap的key存放int索引值,value存放规则名称和规则提示 + // map的key存放int索引值,value存放规则名称和规则提示 QStringList strlist; strlist.append(tr(RULES[i].name)); strlist.append(tr(RULES[i].description)); - actions.insert(i, strlist); + actions.insert(map::value_type(i, strlist)); } return actions; diff --git a/src/ui/qt/gamecontroller.h b/src/ui/qt/gamecontroller.h index 48324100..5f9ffba1 100644 --- a/src/ui/qt/gamecontroller.h +++ b/src/ui/qt/gamecontroller.h @@ -29,9 +29,10 @@ #ifndef GAMECONTROLLER_H #define GAMECONTROLLER_H +#include + #include #include -#include #include #include #include @@ -44,6 +45,8 @@ #include "server.h" #include "client.h" +using namespace std; + class GameController : public QObject { Q_OBJECT @@ -53,7 +56,7 @@ public: ~GameController() override; //主窗口菜单栏明细 - const QMap getActions(); + const map getActions(); int getRuleIndex() { diff --git a/src/ui/qt/gamewindow.cpp b/src/ui/qt/gamewindow.cpp index a19057eb..c91d9b52 100644 --- a/src/ui/qt/gamewindow.cpp +++ b/src/ui/qt/gamewindow.cpp @@ -20,7 +20,6 @@ *****************************************************************************/ #include -#include #include #include #include @@ -161,16 +160,16 @@ void MillGameWindow::initialize() gameController = new GameController(*scene, this); // 添加新菜单栏动作 - QMap actions = gameController->getActions(); + map actions = gameController->getActions(); - for (auto i = actions.constBegin(); i != actions.constEnd(); i++) { - // QMap的key存放int索引值,value存放规则名称和规则提示 - auto *ruleAction = new QAction(i.value().at(0), this); - ruleAction->setToolTip(i.value().at(1)); + for (auto i = actions.begin(); i != actions.end(); i++) { + // map的key存放int索引值,value存放规则名称和规则提示 + auto *ruleAction = new QAction(i->second.at(0), this); + ruleAction->setToolTip(i->second.at(1)); ruleAction->setCheckable(true); // 索引值放在QAction的Data里 - ruleAction->setData(i.key()); + ruleAction->setData(i->first); // 添加到动作列表 ruleActionList.append(ruleAction);