# HG changeset patch # User unc0rr # Date 1339956669 -14400 # Node ID c3584a3ab730fb6ff3f20cb3afbc7512eebe30ff # Parent 722e8a0d89dc71d0d708beb937ac69ee166bedd0 BindsModel diff -r 722e8a0d89dc -r c3584a3ab730 QTfrontend/ui/page/pageeditteam.cpp --- a/QTfrontend/ui/page/pageeditteam.cpp Sun Jun 17 21:45:49 2012 +0400 +++ b/QTfrontend/ui/page/pageeditteam.cpp Sun Jun 17 22:11:09 2012 +0400 @@ -26,8 +26,8 @@ #include #include #include - -#include "sdlkeys.h" +#include +#include #include "SquareLabel.h" #include "HWApplication.h" @@ -197,9 +197,9 @@ l->setText(HWApplication::translate("binds", cbinds[i].name)); l->setAlignment(Qt::AlignRight); pagelayout->addWidget(l, num, 0); + CBBind[i] = new QComboBox(curW); - for(int j = 0; sdlkeys[j][1][0] != '\0'; j++) - CBBind[i]->addItem(HWApplication::translate("binds (keys)", sdlkeys[j][1]).contains(": ") ? HWApplication::translate("binds (keys)", sdlkeys[j][1]) : HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + HWApplication::translate("binds (keys)", sdlkeys[j][1]), sdlkeys[j][0]); + CBBind[i]->setModel(DataManager::instance().bindsModel()); pagelayout->addWidget(CBBind[i++], num++, 1); } @@ -423,9 +423,15 @@ CBFort->setCurrentIndex(CBFort->findText(team.fort())); CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack())); + QStandardItemModel * binds = DataManager::instance().bindsModel(); for(int i = 0; i < BINDS_NUMBER; i++) { - CBBind[i]->setCurrentIndex(CBBind[i]->findData(team.keyBind(i))); + QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, team.keyBind(i), 1, Qt::MatchExactly); + + if(mdl.size() == 1) + CBBind[i]->setCurrentIndex(mdl[0].row()); + else + qDebug() << "Binds: cannot find" << team.keyBind(i); } } @@ -451,9 +457,10 @@ team.setVoicepack(CBVoicepack->currentText()); team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString()); + QStandardItemModel * binds = DataManager::instance().bindsModel(); for(int i = 0; i < BINDS_NUMBER; i++) { - team.bindKey(i,CBBind[i]->itemData(CBBind[i]->currentIndex()).toString()); + team.bindKey(i, binds->index(CBBind[i]->currentIndex(), 0).data(Qt::UserRole + 1).toString()); } return team; diff -r 722e8a0d89dc -r c3584a3ab730 QTfrontend/util/DataManager.cpp --- a/QTfrontend/util/DataManager.cpp Sun Jun 17 21:45:49 2012 +0400 +++ b/QTfrontend/util/DataManager.cpp Sun Jun 17 22:11:09 2012 +0400 @@ -27,6 +27,8 @@ #include #include "hwconsts.h" +#include "HWApplication.h" +#include "sdlkeys.h" #include "DataManager.h" @@ -47,6 +49,7 @@ m_mapModel = NULL; m_themeModel = NULL; m_colorsModel = NULL; + m_bindsModel = NULL; } @@ -178,6 +181,24 @@ return m_colorsModel; } +QStandardItemModel * DataManager::bindsModel() +{ + if(m_bindsModel == NULL) + { + m_bindsModel = new QStandardItemModel(); + + for(int j = 0; sdlkeys[j][1][0] != '\0'; j++) + { + QStandardItem * item = new QStandardItem(); + item->setData(HWApplication::translate("binds (keys)", sdlkeys[j][1]).contains(": ") ? HWApplication::translate("binds (keys)", sdlkeys[j][1]) : HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + HWApplication::translate("binds (keys)", sdlkeys[j][1]), Qt::DisplayRole); + item->setData(sdlkeys[j][0], Qt::UserRole + 1); + m_bindsModel->appendRow(item); + } + } + + return m_bindsModel; +} + void DataManager::reload() { m_gameStyleModel->loadGameStyles(); diff -r 722e8a0d89dc -r c3584a3ab730 QTfrontend/util/DataManager.h --- a/QTfrontend/util/DataManager.h Sun Jun 17 21:45:49 2012 +0400 +++ b/QTfrontend/util/DataManager.h Sun Jun 17 22:11:09 2012 +0400 @@ -128,6 +128,7 @@ ThemeModel * themeModel(); QStandardItemModel * colorsModel(); + QStandardItemModel * bindsModel(); public slots: /// Reloads data from storage. @@ -158,6 +159,7 @@ MapModel * m_mapModel; ///< map model instance ThemeModel * m_themeModel; ///< theme model instance QStandardItemModel * m_colorsModel; + QStandardItemModel * m_bindsModel; }; #endif // HEDGEWARS_DATAMANAGER_H