-
Notifications
You must be signed in to change notification settings - Fork 2
/
qtconceptmapclassifyexamplesdialog.cpp
203 lines (179 loc) · 6.28 KB
/
qtconceptmapclassifyexamplesdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "qtconceptmapclassifyexamplesdialog.h"
#include <QDesktopWidget>
#include <QKeyEvent>
#include "conceptmaphelper.h"
#include "qtconceptmapcompetency.h"
#include "ui_qtconceptmapclassifyexamplesdialog.h"
struct QtConceptMapListWidgetItem : public QListWidgetItem
{
QtConceptMapListWidgetItem(const ribi::cmap::Example& example)
{
//Wordwrap text
const std::string s = example.GetText();
const std::vector<std::string> v { ribi::cmap::Wordwrap(s,40) };
//Display multi-line
std::string t;
for (const std::string& i: v) { t += i + "\n"; }
if (!t.empty()) t.resize(t.size() - 1);
this->setText(t.c_str());
//Icon
this->setIcon(ribi::cmap::QtCompetency().CompetencyToIcon(example.GetCompetency()));
}
};
ribi::cmap::QtClassifyExamplesDialog::QtClassifyExamplesDialog(
const Concept& concept,
QWidget* parent)
: QDialog(parent),
ui(new Ui::QtClassifyExamplesDialog)
{
if (CountExamples(concept) == 0)
{
throw std::invalid_argument("concept must have at least one example");
}
ui->setupUi(this);
//Ensure that the dialog does not resize beyond the screen's size
{
this->setMaximumWidth( QApplication::desktop()->width() );
}
//Convert the Concept to GUI elements
{
ui->label_concept_name->setText(concept.GetName().c_str());
ui->list->clear();
const auto v = concept.GetExamples().Get();
const std::size_t sz = v.size();
for (std::size_t i=0; i!=sz; ++i)
{
const Example& example = v[i];
QtConceptMapListWidgetItem * const item
= new QtConceptMapListWidgetItem(example);
ui->list->addItem(item);
ui->list->setCurrentItem(item);
}
}
assert(ui->list->currentItem());
//Align the button icons and texts to the left
{
const std::vector<QPushButton*> v
=
{
ui->button_misc,
ui->button_organisations,
ui->button_prof,
ui->button_prof_development,
ui->button_social,
ui->button_target_audience,
ui->button_ti_knowledge
};
for(QPushButton* button: v) button->setStyleSheet("text-align: left;");
}
//Put the dialog in the screen its center
{
const QRect screen = QApplication::desktop()->screenGeometry();
this->move( screen.center() - this->rect().center() );
}
}
ribi::cmap::QtClassifyExamplesDialog::~QtClassifyExamplesDialog() noexcept
{
delete ui;
}
ribi::cmap::Examples ribi::cmap::QtClassifyExamplesDialog::GetRatedExamples() const
{
std::vector<Example> v;
const int sz = ui->list->count();
for (int i=0; i!=sz; ++i)
{
const QListWidgetItem* const qtitem = ui->list->item(i);
assert(qtitem);
const QtConceptMapListWidgetItem* const item
= dynamic_cast<const QtConceptMapListWidgetItem*>(qtitem);
assert(item);
const Example example{
item->text().toStdString(),
QtCompetency().IconToCompetency(item->icon())
};
v.push_back(example);
}
return Examples(v);
}
void ribi::cmap::QtClassifyExamplesDialog::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape) { close(); return; }
if ( (e->modifiers() & Qt::ControlModifier)
&& (e->modifiers() & Qt::ShiftModifier)
&& e->key() == Qt::Key_T)
{
//Translate
this->setWindowTitle("Classification screen");
ui->button_misc->setText("Other knowledge");
ui->button_ok->setText("OK");
ui->button_organisations->setText("Organisational knowledge");
ui->button_prof->setText("Vocational domain knowledge");
ui->button_prof_development->setText("Knowledge relevant for personal development");
ui->button_social->setText("Knowledge of ones own social environment");
ui->button_target_audience->setText("Target group knowledge");
ui->button_ti_knowledge->setText("Technical-instrumental knowledge");
ui->label_above_list->setText("Illustrations");
//ui->label_concept_name->setText(""); Read from concept map
ui->groupBox->setTitle("Mark text");
return;
}
QDialog::keyPressEvent(e);
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_prof_clicked()
{
assert(ui->list->currentItem());
QtConceptMapListWidgetItem* const item
= dynamic_cast<QtConceptMapListWidgetItem*>(ui->list->currentItem());
item->setIcon(cmap::QtCompetency().CompetencyToIcon(cmap::Competency::profession));
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_organisations_clicked()
{
assert(ui->list->currentItem());
QtConceptMapListWidgetItem* const item
= dynamic_cast<QtConceptMapListWidgetItem*>(ui->list->currentItem());
item->setIcon(cmap::QtCompetency().CompetencyToIcon(cmap::Competency::organisations));
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_social_clicked()
{
assert(ui->list->currentItem());
QtConceptMapListWidgetItem* const item
= dynamic_cast<QtConceptMapListWidgetItem*>(ui->list->currentItem());
item->setIcon(cmap::QtCompetency().CompetencyToIcon(cmap::Competency::social_surroundings));
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_target_audience_clicked()
{
assert(ui->list->currentItem());
QtConceptMapListWidgetItem* const item
= dynamic_cast<QtConceptMapListWidgetItem*>(ui->list->currentItem());
item->setIcon(cmap::QtCompetency().CompetencyToIcon(cmap::Competency::target_audience));
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_prof_development_clicked()
{
assert(ui->list->currentItem());
QtConceptMapListWidgetItem* const item
= dynamic_cast<QtConceptMapListWidgetItem*>(ui->list->currentItem());
item->setIcon(cmap::QtCompetency().CompetencyToIcon(cmap::Competency::prof_growth));
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_misc_clicked()
{
assert(ui->list->currentItem());
QtConceptMapListWidgetItem* const item
= dynamic_cast<QtConceptMapListWidgetItem*>(ui->list->currentItem());
item->setIcon(cmap::QtCompetency().CompetencyToIcon(cmap::Competency::misc));
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_ti_knowledge_clicked()
{
assert(ui->list->currentItem());
QtConceptMapListWidgetItem* const item
= dynamic_cast<QtConceptMapListWidgetItem*>(ui->list->currentItem());
item->setIcon(cmap::QtCompetency().CompetencyToIcon(cmap::Competency::ti_knowledge));
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_ok_clicked()
{
m_clicked_ok = true;
close();
}
void ribi::cmap::QtClassifyExamplesDialog::on_button_cancel_clicked()
{
close();
}