4 * Author: Petr Kubizňák
8 /* -------------------------------------------------------------------------- */
10 #include "ScoresForm.h"
11 #include "../../asserts.h"
14 /* -------------------------------------------------------------------------- */
16 /* vytvori novy formular; parametry jsou pointery na seznamy nejlepsich hracu */
17 ScoresForm::ScoresForm(std::list
<ScoreRecord
> *rookieList
, std::list
<ScoreRecord
> *advancedList
,
18 std::list
<ScoreRecord
> *suicideList
, std::list
<ScoreRecord
> *customList
) {
22 ui
.difficultnessCbx
->addItem("Rookie");
23 ui
.difficultnessCbx
->addItem("Advanced");
24 ui
.difficultnessCbx
->addItem("Suicide");
25 ui
.difficultnessCbx
->addItem("Custom");
27 //vytvorime modely z listu
28 rookieModel
= createModel(*rookieList
);
29 advancedModel
= createModel(*advancedList
);
30 suicideModel
= createModel(*suicideList
);
31 customModel
= createModel(*customList
);
33 ui
.scoresView
->setSortingEnabled(true);
35 QObject::connect(ui
.difficultnessCbx
, SIGNAL(activated(int)), this, SLOT(difficultnessCbx_Activated(int)));
38 /* -------------------------------------------------------------------------- */
40 ScoresForm::~ScoresForm() {
47 /* -------------------------------------------------------------------------- */
49 /* zadany list zaznamu prevede na nove alokovany model, jehoz adresu vraci */
50 QStandardItemModel
*ScoresForm::createModel(std::list
<ScoreRecord
> &source
) const {
51 QStandardItemModel
*model
= new QStandardItemModel(0, 2, ui
.scoresView
);
52 model
->setHeaderData(0, Qt::Horizontal
, "Name");
53 model
->setHeaderData(1, Qt::Horizontal
, "Time");
54 for(std::list
<ScoreRecord
>::iterator it
= source
.begin(); it
!= source
.end(); it
++) {
56 sprintf(time
, "%d:%02d", (*it
).time
/ 60, (*it
).time
% 60);
58 model
->setData(model
->index(0, 0), QString((*it
).name
));
59 model
->setData(model
->index(0, 1), time
);
64 /* -------------------------------------------------------------------------- */
66 /* provede aktualizaci (nahradu) modelu daneho modem daty v listu */
67 void ScoresForm::replaceModel(Board::GameMode mode
, std::list
<ScoreRecord
> *scoreList
) {
69 case Board::ModeRookie
:
71 rookieModel
= createModel(*scoreList
);
74 case Board::ModeAdvanced
:
76 advancedModel
= createModel(*scoreList
);
79 case Board::ModeSuicide
:
81 suicideModel
= createModel(*scoreList
);
84 case Board::ModeCustom
:
86 customModel
= createModel(*scoreList
);
91 /* -------------------------------------------------------------------------- */
93 /* zobrazi modalne tento dialog s modelem daneho indexu */
94 int ScoresForm::exec(int displayIndex
) {
95 assert(displayIndex
>=0 && displayIndex
<=3);
97 ui
.difficultnessCbx
->setCurrentIndex(displayIndex
);
98 difficultnessCbx_Activated(displayIndex
);
99 ui
.scoresView
->setColumnWidth(0, 200);
100 ui
.scoresView
->setColumnWidth(1, 100);
102 return QDialog::exec();
105 /* -------------------------------------------------------------------------- */
107 /* udalost vyberu obtiznosti v ComboBoxu - nastavi prislusny model dat */
108 void ScoresForm::difficultnessCbx_Activated(int itemIndex
) {
110 case 0: ui
.scoresView
->setModel(rookieModel
); break;
111 case 1: ui
.scoresView
->setModel(advancedModel
); break;
112 case 2: ui
.scoresView
->setModel(suicideModel
); break;
113 default: ui
.scoresView
->setModel(customModel
); break;
115 ui
.scoresView
->sortByColumn(1, Qt::AscendingOrder
); //seradime podle casu
118 /* -------------------------------------------------------------------------- */