Changeset View
Changeset View
Standalone View
Standalone View
sidebar/SidebarMode.cpp
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 92 | { | |||
---|---|---|---|---|---|
96 | //this avoids the brief flash it had | 96 | //this avoids the brief flash it had | ||
97 | clear(); | 97 | clear(); | ||
98 | const int subRows = activeModule.isValid() ? m_parentModel->rowCount(activeModule) : 0; | 98 | const int subRows = activeModule.isValid() ? m_parentModel->rowCount(activeModule) : 0; | ||
99 | if ( subRows > 1) { | 99 | if ( subRows > 1) { | ||
100 | for (int i = 0; i < subRows; ++i) { | 100 | for (int i = 0; i < subRows; ++i) { | ||
101 | const QModelIndex& index = m_parentModel->index(i, 0, activeModule); | 101 | const QModelIndex& index = m_parentModel->index(i, 0, activeModule); | ||
102 | QStandardItem *item = new QStandardItem(m_parentModel->data(index, Qt::DecorationRole).value<QIcon>(), m_parentModel->data(index, Qt::DisplayRole).toString()); | 102 | QStandardItem *item = new QStandardItem(m_parentModel->data(index, Qt::DecorationRole).value<QIcon>(), m_parentModel->data(index, Qt::DisplayRole).toString()); | ||
103 | item->setData(index.data(Qt::UserRole), Qt::UserRole); | 103 | item->setData(index.data(Qt::UserRole), Qt::UserRole); | ||
104 | item->setData(index.data(MenuModel::DefaultIndicatorRole), MenuModel::DefaultIndicatorRole); | ||||
104 | appendRow(item); | 105 | appendRow(item); | ||
105 | } | 106 | } | ||
106 | } | 107 | } | ||
107 | blockSignals(false); | 108 | blockSignals(false); | ||
108 | beginResetModel(); | 109 | beginResetModel(); | ||
109 | endResetModel(); | 110 | endResetModel(); | ||
110 | m_title = activeModule.data(Qt::DisplayRole).toString(); | 111 | m_title = activeModule.data(Qt::DisplayRole).toString(); | ||
111 | emit titleChanged(); | 112 | emit titleChanged(); | ||
112 | } | 113 | } | ||
113 | 114 | | |||
115 | QHash<int, QByteArray> SubcategoryModel::roleNames() const | ||||
116 | { | ||||
117 | auto roleNames = QStandardItemModel::roleNames(); | ||||
ervin: This is generally implemented by calling the roleNames() of the parent class and then tune the… | |||||
118 | roleNames.insert(MenuModel::DefaultIndicatorRole, "showDefaultIndicator"); | ||||
119 | return roleNames; | ||||
120 | } | ||||
121 | | ||||
114 | 122 | | |||
115 | class MostUsedModel : public QSortFilterProxyModel | 123 | class MostUsedModel : public QSortFilterProxyModel | ||
116 | { | 124 | { | ||
117 | public: | 125 | public: | ||
118 | explicit MostUsedModel(QObject *parent = nullptr) | 126 | explicit MostUsedModel(QObject *parent = nullptr) | ||
119 | : QSortFilterProxyModel (parent) | 127 | : QSortFilterProxyModel (parent) | ||
120 | { | 128 | { | ||
121 | sort(0, Qt::DescendingOrder); | 129 | sort(0, Qt::DescendingOrder); | ||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Line(s) | 354 | { | |||
367 | 375 | | |||
368 | d->subCategoryModel = new SubcategoryModel( d->categorizedModel, this ); | 376 | d->subCategoryModel = new SubcategoryModel( d->categorizedModel, this ); | ||
369 | d->mainWidget = new FocusHackWidget(); | 377 | d->mainWidget = new FocusHackWidget(); | ||
370 | d->mainWidget->installEventFilter(this); | 378 | d->mainWidget->installEventFilter(this); | ||
371 | d->mainLayout = new QHBoxLayout(d->mainWidget); | 379 | d->mainLayout = new QHBoxLayout(d->mainWidget); | ||
372 | d->mainLayout->setContentsMargins(0, 0, 0, 0); | 380 | d->mainLayout->setContentsMargins(0, 0, 0, 0); | ||
373 | d->moduleView = new ModuleView( d->mainWidget ); | 381 | d->moduleView = new ModuleView( d->mainWidget ); | ||
374 | connect( d->moduleView, &ModuleView::moduleChanged, this, &SidebarMode::moduleLoaded ); | 382 | connect( d->moduleView, &ModuleView::moduleChanged, this, &SidebarMode::moduleLoaded ); | ||
383 | connect(d->moduleView, &ModuleView::moduleSaved, this, &SidebarMode::updateDefaults); | ||||
375 | d->quickWidget = nullptr; | 384 | d->quickWidget = nullptr; | ||
376 | moduleView()->setFaceType(KPageView::Plain); | 385 | moduleView()->setFaceType(KPageView::Plain); | ||
377 | if (applicationMode() == BaseMode::InfoCenter) { | 386 | if (applicationMode() == BaseMode::InfoCenter) { | ||
378 | d->moduleView->setSaveStatistics(false); | 387 | d->moduleView->setSaveStatistics(false); | ||
379 | d->moduleView->setApplyVisible(false); | 388 | d->moduleView->setApplyVisible(false); | ||
380 | d->moduleView->setDefaultsVisible(false); | 389 | d->moduleView->setDefaultsVisible(false); | ||
381 | d->moduleView->setResetVisible(false); | 390 | d->moduleView->setResetVisible(false); | ||
382 | } | 391 | } | ||
▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Line(s) | |||||
566 | } | 575 | } | ||
567 | 576 | | |||
568 | void SidebarMode::moduleLoaded() | 577 | void SidebarMode::moduleLoaded() | ||
569 | { | 578 | { | ||
570 | d->placeHolderWidget->hide(); | 579 | d->placeHolderWidget->hide(); | ||
571 | d->moduleView->show(); | 580 | d->moduleView->show(); | ||
572 | } | 581 | } | ||
573 | 582 | | |||
583 | void SidebarMode::updateDefaults() | ||||
584 | { | ||||
585 | QModelIndex categoryIdx = d->categorizedModel->index(d->activeCategoryRow, 0); | ||||
586 | auto item = categoryIdx.data(Qt::UserRole).value<MenuItem*>(); | ||||
ervin: I'd feel better with a Q_ASSERT(item) | |||||
587 | Q_ASSERT(item); | ||||
588 | // If subcategory exist update from subcategory | ||||
ervin: Technically correct, we tend to favor the use of `isEmpty()` though. | |||||
589 | if (!item->children().isEmpty()) { | ||||
590 | item = item->child(d->activeSubCategoryRow); | ||||
591 | } | ||||
592 | item->updateDefaultIndicator(); | ||||
593 | | ||||
594 | emit d->categorizedModel->dataChanged(categoryIdx, categoryIdx); | ||||
595 | | ||||
596 | auto subCateogryIdx = d->subCategoryModel->index(d->activeSubCategoryRow, 0); | ||||
597 | d->subCategoryModel->setData(subCateogryIdx, item->showDefaultIndicator(), MenuModel::DefaultIndicatorRole); | ||||
598 | emit d->subCategoryModel->dataChanged(subCateogryIdx, subCateogryIdx); | ||||
599 | | ||||
600 | if (d->activeSearchRow > -1) { | ||||
601 | auto searchIdx = d->searchModel->index(d->activeSearchRow, 0); | ||||
602 | auto idx = d->categorizedModel->mapFromSource(d->flatModel->mapToSource(d->searchModel->mapToSource(searchIdx))); | ||||
603 | emit d->searchModel->dataChanged(searchIdx, searchIdx); | ||||
604 | if (idx.parent().isValid()) { | ||||
605 | auto searchIdxParent = d->searchModel->mapFromSource(d->flatModel->mapFromSource(d->categorizedModel->mapToSource(idx.parent()))); | ||||
606 | emit d->searchModel->dataChanged(searchIdxParent, searchIdxParent); | ||||
607 | } | ||||
608 | } | ||||
609 | } | ||||
610 | | ||||
574 | int SidebarMode::activeSearchRow() const | 611 | int SidebarMode::activeSearchRow() const | ||
575 | { | 612 | { | ||
576 | return d->activeSearchRow; | 613 | return d->activeSearchRow; | ||
577 | } | 614 | } | ||
578 | 615 | | |||
579 | int SidebarMode::activeCategoryRow() const | 616 | int SidebarMode::activeCategoryRow() const | ||
580 | { | 617 | { | ||
581 | return d->activeCategoryRow; | 618 | return d->activeCategoryRow; | ||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |
This is generally implemented by calling the roleNames() of the parent class and then tune the returned hash. This way you ensure you keep the support for the standard roles. In your case that'd give something like: