| 173 | } |
| 174 | |
| 175 | void DownloadListView::onHeaderCustomContextMenu(const QPoint& point) |
| 176 | { |
| 177 | QMenu menu; |
| 178 | |
| 179 | // display a list of all headers as checkboxes |
| 180 | QAbstractItemModel* model = header()->model(); |
| 181 | for (int i = 1; i < model->columnCount(); ++i) { |
| 182 | QString columnName = model->headerData(i, Qt::Horizontal).toString(); |
| 183 | QCheckBox* checkBox = new QCheckBox(&menu); |
| 184 | checkBox->setText(columnName); |
| 185 | checkBox->setChecked(!header()->isSectionHidden(i)); |
| 186 | QWidgetAction* checkableAction = new QWidgetAction(&menu); |
| 187 | checkableAction->setDefaultWidget(checkBox); |
| 188 | menu.addAction(checkableAction); |
| 189 | } |
| 190 | |
| 191 | menu.exec(header()->viewport()->mapToGlobal(point)); |
| 192 | |
| 193 | // view/hide columns depending on check-state |
| 194 | int i = 1; |
| 195 | for (const QAction* action : menu.actions()) { |
| 196 | const QWidgetAction* widgetAction = qobject_cast<const QWidgetAction*>(action); |
| 197 | if (widgetAction != nullptr) { |
| 198 | const QCheckBox* checkBox = |
| 199 | qobject_cast<const QCheckBox*>(widgetAction->defaultWidget()); |
| 200 | if (checkBox != nullptr) { |
| 201 | header()->setSectionHidden(i, !checkBox->isChecked()); |
| 202 | } |
| 203 | } |
| 204 | ++i; |
| 205 | } |
| 206 | |
| 207 | qobject_cast<DownloadListHeader*>(header())->customResizeSections(); |
| 208 | } |
| 209 | |
| 210 | void DownloadListView::resizeEvent(QResizeEvent* event) |
| 211 | { |
nothing calls this directly
no test coverage detected