stl: QMap 切换为 std::map

This commit is contained in:
Calcitem 2019-10-26 20:14:26 +08:00
parent 128bae35ec
commit 816883ca8e
3 changed files with 19 additions and 13 deletions

View File

@ -19,6 +19,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <map>
#include <QGraphicsView>
#include <QGraphicsSceneMouseEvent>
#include <QKeyEvent>
@ -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<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++) {
// 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<int, QStringList>::value_type(i, strlist));
}
return actions;

View File

@ -29,9 +29,10 @@
#ifndef GAMECONTROLLER_H
#define GAMECONTROLLER_H
#include <map>
#include <QTime>
#include <QPointF>
#include <QMap>
#include <QList>
#include <QTextStream>
#include <QStringListModel>
@ -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 <int, QStringList> getActions();
const map<int, QStringList> getActions();
int getRuleIndex()
{

View File

@ -20,7 +20,6 @@
*****************************************************************************/
#include <QDesktopServices>
#include <QMap>
#include <QMessageBox>
#include <QTimer>
#include <QDialog>
@ -161,16 +160,16 @@ void MillGameWindow::initialize()
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++) {
// 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);