stl: QMap 切换为 std::map
This commit is contained in:
parent
128bae35ec
commit
816883ca8e
|
@ -19,6 +19,8 @@
|
||||||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
@ -36,6 +38,8 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "option.h"
|
#include "option.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
GameController::GameController(GameScene & scene, QObject * parent) :
|
GameController::GameController(GameScene & scene, QObject * parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
scene(scene),
|
scene(scene),
|
||||||
|
@ -106,18 +110,18 @@ GameController::~GameController()
|
||||||
#endif /* ENDGAME_LEARNING */
|
#endif /* ENDGAME_LEARNING */
|
||||||
}
|
}
|
||||||
|
|
||||||
const QMap<int, QStringList> GameController::getActions()
|
const map<int, QStringList> GameController::getActions()
|
||||||
{
|
{
|
||||||
// 主窗口更新菜单栏
|
// 主窗口更新菜单栏
|
||||||
// 之所以不用信号和槽的模式,是因为发信号的时候槽还来不及关联
|
// 之所以不用信号和槽的模式,是因为发信号的时候槽还来不及关联
|
||||||
QMap<int, QStringList> actions;
|
map<int, QStringList> actions;
|
||||||
|
|
||||||
for (int i = 0; i < N_RULES; i++) {
|
for (int i = 0; i < N_RULES; i++) {
|
||||||
// QMap的key存放int索引值,value存放规则名称和规则提示
|
// map的key存放int索引值,value存放规则名称和规则提示
|
||||||
QStringList strlist;
|
QStringList strlist;
|
||||||
strlist.append(tr(RULES[i].name));
|
strlist.append(tr(RULES[i].name));
|
||||||
strlist.append(tr(RULES[i].description));
|
strlist.append(tr(RULES[i].description));
|
||||||
actions.insert(i, strlist);
|
actions.insert(map<int, QStringList>::value_type(i, strlist));
|
||||||
}
|
}
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
|
|
|
@ -29,9 +29,10 @@
|
||||||
#ifndef GAMECONTROLLER_H
|
#ifndef GAMECONTROLLER_H
|
||||||
#define GAMECONTROLLER_H
|
#define GAMECONTROLLER_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QMap>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
@ -44,6 +45,8 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class GameController : public QObject
|
class GameController : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -53,7 +56,7 @@ public:
|
||||||
~GameController() override;
|
~GameController() override;
|
||||||
|
|
||||||
//主窗口菜单栏明细
|
//主窗口菜单栏明细
|
||||||
const QMap <int, QStringList> getActions();
|
const map<int, QStringList> getActions();
|
||||||
|
|
||||||
int getRuleIndex()
|
int getRuleIndex()
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMap>
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
@ -161,16 +160,16 @@ void MillGameWindow::initialize()
|
||||||
gameController = new GameController(*scene, this);
|
gameController = new GameController(*scene, this);
|
||||||
|
|
||||||
// 添加新菜单栏动作
|
// 添加新菜单栏动作
|
||||||
QMap <int, QStringList> actions = gameController->getActions();
|
map<int, QStringList> actions = gameController->getActions();
|
||||||
|
|
||||||
for (auto i = actions.constBegin(); i != actions.constEnd(); i++) {
|
for (auto i = actions.begin(); i != actions.end(); i++) {
|
||||||
// QMap的key存放int索引值,value存放规则名称和规则提示
|
// map的key存放int索引值,value存放规则名称和规则提示
|
||||||
auto *ruleAction = new QAction(i.value().at(0), this);
|
auto *ruleAction = new QAction(i->second.at(0), this);
|
||||||
ruleAction->setToolTip(i.value().at(1));
|
ruleAction->setToolTip(i->second.at(1));
|
||||||
ruleAction->setCheckable(true);
|
ruleAction->setCheckable(true);
|
||||||
|
|
||||||
// 索引值放在QAction的Data里
|
// 索引值放在QAction的Data里
|
||||||
ruleAction->setData(i.key());
|
ruleAction->setData(i->first);
|
||||||
|
|
||||||
// 添加到动作列表
|
// 添加到动作列表
|
||||||
ruleActionList.append(ruleAction);
|
ruleActionList.append(ruleAction);
|
||||||
|
|
Loading…
Reference in New Issue