Changeset View
Changeset View
Standalone View
Standalone View
src/statistics/lessonstatisticsview.cpp
Show All 28 Lines | |||||
29 | #include <QAction> | 29 | #include <QAction> | ||
30 | #include <KActionCollection> | 30 | #include <KActionCollection> | ||
31 | 31 | | |||
32 | // Parley | 32 | // Parley | ||
33 | #include "statisticslegendwidget.h" | 33 | #include "statisticslegendwidget.h" | ||
34 | #include "statisticsmodel.h" | 34 | #include "statisticsmodel.h" | ||
35 | #include "keduvoclesson.h" | 35 | #include "keduvoclesson.h" | ||
36 | #include "utils.h" | 36 | #include "utils.h" | ||
37 | #include "documentsettings.h" | ||||
37 | 38 | | |||
38 | 39 | | |||
39 | // GradeDelegate shows the graphic colored bar in the statistics, | 40 | // GradeDelegate shows the graphic colored bar in the statistics, | ||
40 | // showing how far the student has come on the way to enlightenment. | 41 | // showing how far the student has come on the way to enlightenment. | ||
41 | 42 | | |||
42 | class GradeDelegate: public QItemDelegate | 43 | class GradeDelegate: public QItemDelegate | ||
43 | { | 44 | { | ||
44 | public: | 45 | public: | ||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 87 | { | |||
110 | addAction(removeGradesChildrenAction); | 111 | addAction(removeGradesChildrenAction); | ||
111 | 112 | | |||
112 | connect(header(), &QHeaderView::geometriesChanged, | 113 | connect(header(), &QHeaderView::geometriesChanged, | ||
113 | this, &LessonStatisticsView::adjustColumnWidths); | 114 | this, &LessonStatisticsView::adjustColumnWidths); | ||
114 | connect(header(), &QHeaderView::sectionResized, | 115 | connect(header(), &QHeaderView::sectionResized, | ||
115 | this, &LessonStatisticsView::sectionResized); | 116 | this, &LessonStatisticsView::sectionResized); | ||
116 | } | 117 | } | ||
117 | 118 | | |||
119 | LessonStatisticsView::~LessonStatisticsView() | ||||
120 | { | ||||
121 | saveExpandedStatus(); | ||||
122 | } | ||||
123 | | ||||
118 | void LessonStatisticsView::setModel(ContainerModel *model) | 124 | void LessonStatisticsView::setModel(ContainerModel *model) | ||
119 | { | 125 | { | ||
120 | ContainerView::setModel(model); | 126 | ContainerView::setModel(model); | ||
121 | 127 | | |||
122 | GradeDelegate *delegate = new GradeDelegate(this); | 128 | GradeDelegate *delegate = new GradeDelegate(this); | ||
123 | for (int i = ContainerModel::FirstDataColumn; i < model->columnCount(QModelIndex()); i++) { | 129 | for (int i = ContainerModel::FirstDataColumn; i < model->columnCount(QModelIndex()); i++) { | ||
124 | setItemDelegateForColumn(i, delegate); | 130 | setItemDelegateForColumn(i, delegate); | ||
125 | } | 131 | } | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
168 | } | 174 | } | ||
169 | 175 | | |||
170 | void LessonStatisticsView::removeGradesChildren() | 176 | void LessonStatisticsView::removeGradesChildren() | ||
171 | { | 177 | { | ||
172 | QModelIndex selectedIndex = selectionModel()->currentIndex(); | 178 | QModelIndex selectedIndex = selectionModel()->currentIndex(); | ||
173 | KEduVocLesson *lesson = static_cast<KEduVocLesson*>(selectedIndex.internalPointer()); | 179 | KEduVocLesson *lesson = static_cast<KEduVocLesson*>(selectedIndex.internalPointer()); | ||
174 | lesson->resetGrades(-1, KEduVocContainer::Recursive); | 180 | lesson->resetGrades(-1, KEduVocContainer::Recursive); | ||
175 | } | 181 | } | ||
182 | | ||||
183 | void LessonStatisticsView::saveExpandedStatus() const | ||||
184 | { | ||||
185 | auto statisticsModel = qobject_cast<StatisticsModel *>(model()); | ||||
186 | Q_ASSERT(statisticsModel != nullptr); | ||||
187 | | ||||
188 | QStringList collapsedItems; | ||||
189 | getCollapsedItems(collapsedItems, statisticsModel->index(0, 0, QModelIndex()), QString()); | ||||
190 | | ||||
191 | const KEduVocDocument *doc = statisticsModel->document(); | ||||
192 | if (doc != nullptr) { | ||||
193 | DocumentSettings documentSettings(doc->url().url()); | ||||
194 | documentSettings.setCollapsedStatisticsViewItems(collapsedItems); | ||||
195 | documentSettings.save(); | ||||
196 | } | ||||
197 | } | ||||
198 | | ||||
199 | void LessonStatisticsView::getCollapsedItems(QStringList &collapsedItems, const QModelIndex &item, | ||||
200 | QString name) const | ||||
201 | { | ||||
202 | if (!item.isValid()) { | ||||
203 | return; | ||||
204 | } | ||||
205 | | ||||
206 | int rowCount = model()->rowCount(item); | ||||
207 | if (rowCount > 0) { | ||||
208 | // Item has children and therefore expandable | ||||
209 | name += item.data().toString(); | ||||
210 | if (!isExpanded(item)) { | ||||
211 | collapsedItems << name; | ||||
212 | } | ||||
213 | for (int row = 0; row < rowCount; ++row) { | ||||
214 | getCollapsedItems(collapsedItems, model()->index(row, 0, item), name + '/'); | ||||
215 | } | ||||
216 | } | ||||
217 | } | ||||
218 | | ||||
219 | void LessonStatisticsView::restoreExpandedStatus() | ||||
220 | { | ||||
221 | auto statisticsModel = qobject_cast<StatisticsModel *>(model()); | ||||
222 | Q_ASSERT(statisticsModel != nullptr); | ||||
223 | | ||||
224 | const KEduVocDocument *doc = statisticsModel->document(); | ||||
225 | if (doc != nullptr) { | ||||
226 | DocumentSettings documentSettings(doc->url().url()); | ||||
227 | documentSettings.load(); | ||||
228 | QStringList collapsedItems = documentSettings.collapsedStatisticsViewItems(); | ||||
229 | setCollapsedItems(collapsedItems, statisticsModel->index(0, 0, QModelIndex()), QString()); | ||||
230 | } | ||||
231 | } | ||||
232 | | ||||
233 | void LessonStatisticsView::setCollapsedItems(const QStringList &collapsedItems, | ||||
234 | const QModelIndex &item, QString name) | ||||
235 | { | ||||
236 | if (!item.isValid()) { | ||||
237 | return; | ||||
238 | } | ||||
239 | | ||||
240 | int rowCount = model()->rowCount(item); | ||||
241 | if (rowCount > 0) { | ||||
242 | // Item has children and therefore expandable | ||||
243 | name += item.data().toString(); | ||||
244 | if (collapsedItems.contains(name)) { | ||||
245 | collapse(item); | ||||
246 | } else { | ||||
247 | expand(item); | ||||
248 | } | ||||
249 | for (int row = 0; row < rowCount; ++row) { | ||||
250 | setCollapsedItems(collapsedItems, model()->index(row, 0, item), name + '/'); | ||||
251 | } | ||||
252 | } | ||||
253 | } | ||||
254 | |