! Sets the \c model for the tree view to present. */
| 233 | Sets the \c model for the tree view to present. |
| 234 | */ |
| 235 | void ProjectExplorer::setModel(AspectTreeModel* treeModel) { |
| 236 | m_treeView->setModel(treeModel); |
| 237 | |
| 238 | connect(treeModel, &AspectTreeModel::renameRequested, m_treeView, static_cast<void (QAbstractItemView::*)(const QModelIndex&)>(&QAbstractItemView::edit)); |
| 239 | connect(treeModel, &AspectTreeModel::indexSelected, this, &ProjectExplorer::selectIndex); |
| 240 | connect(treeModel, &AspectTreeModel::indexDeselected, this, &ProjectExplorer::deselectIndex); |
| 241 | connect(treeModel, &AspectTreeModel::hiddenAspectSelected, this, &ProjectExplorer::hiddenAspectSelected); |
| 242 | |
| 243 | connect(m_treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ProjectExplorer::selectionChanged); |
| 244 | |
| 245 | // create action for showing/hiding the columns in the tree. |
| 246 | // this is done here since the number of columns is not available in createActions() yet. |
| 247 | if (list_showColumnActions.isEmpty()) { |
| 248 | // read the status of the column actions if available |
| 249 | KConfigGroup group = Settings::group(QStringLiteral("ProjectExplorer")); |
| 250 | const QString& status = group.readEntry(QLatin1String("VisibleColumns"), QString()); |
| 251 | QVector<int> checkedActions; |
| 252 | if (!status.isEmpty()) { |
| 253 | QStringList strList = status.split(QLatin1Char(' ')); |
| 254 | for (int i = 0; i < strList.size(); ++i) |
| 255 | checkedActions << strList.at(i).toInt(); |
| 256 | } |
| 257 | |
| 258 | if (!showAllColumnsAction) { |
| 259 | showAllColumnsAction = new QAction(i18n("Show All"), this); |
| 260 | showAllColumnsAction->setCheckable(true); |
| 261 | showAllColumnsAction->setChecked(false); |
| 262 | showAllColumnsAction->setEnabled(true); |
| 263 | connect(showAllColumnsAction, &QAction::triggered, this, &ProjectExplorer::showAllColumns); |
| 264 | } |
| 265 | |
| 266 | if (checkedActions.size() != m_treeView->model()->columnCount()) { |
| 267 | showAllColumnsAction->setEnabled(true); |
| 268 | showAllColumnsAction->setChecked(false); |
| 269 | } else { |
| 270 | showAllColumnsAction->setEnabled(false); |
| 271 | showAllColumnsAction->setChecked(true); |
| 272 | } |
| 273 | |
| 274 | // create an action for every available column in the model |
| 275 | for (int i = 0; i < m_treeView->model()->columnCount(); i++) { |
| 276 | auto* showColumnAction = new QAction(treeModel->headerData(i, Qt::Horizontal).toString(), this); |
| 277 | showColumnAction->setCheckable(true); |
| 278 | |
| 279 | // restore the status, if available |
| 280 | if (!checkedActions.isEmpty()) { |
| 281 | if (checkedActions.indexOf(i) != -1) |
| 282 | showColumnAction->setChecked(true); |
| 283 | else |
| 284 | m_treeView->hideColumn(i); |
| 285 | } else { |
| 286 | // initially, show the first two columns only (name and type) |
| 287 | if (i < 2) |
| 288 | showColumnAction->setChecked(true); |
| 289 | else |
| 290 | m_treeView->hideColumn(i); |
| 291 | } |
| 292 |