diff --git a/plugins/quickopen/expandingtree/expandingtree.cpp b/plugins/quickopen/expandingtree/expandingtree.cpp --- a/plugins/quickopen/expandingtree/expandingtree.cpp +++ b/plugins/quickopen/expandingtree/expandingtree.cpp @@ -39,7 +39,7 @@ void ExpandingTree::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { QTreeView::drawRow( painter, option, index ); - const ExpandingWidgetModel* eModel = qobject_cast(model()); + const ExpandingWidgetModel* eModel = qobject_cast( qobject_cast(model())->sourceModel()); if(eModel && eModel->isPartiallyExpanded( index ) != ExpandingWidgetModel::ExpansionType::NotExpanded) { QRect rect = eModel->partialExpandRect( index ); diff --git a/plugins/quickopen/expandingtree/expandingwidgetmodel.h b/plugins/quickopen/expandingtree/expandingwidgetmodel.h --- a/plugins/quickopen/expandingtree/expandingwidgetmodel.h +++ b/plugins/quickopen/expandingtree/expandingwidgetmodel.h @@ -26,6 +26,7 @@ #include #include #include +#include class KWidget; class QTreeView; @@ -108,6 +109,8 @@ virtual QTreeView* treeView() const = 0; + virtual QSortFilterProxyModel* proxyModel() const = 0; + ///Should return true if the given row should be painted like a contained item(as opposed to label-rows etc.) virtual bool indexIsItem(const QModelIndex& index) const = 0; diff --git a/plugins/quickopen/expandingtree/expandingwidgetmodel.cpp b/plugins/quickopen/expandingtree/expandingwidgetmodel.cpp --- a/plugins/quickopen/expandingtree/expandingwidgetmodel.cpp +++ b/plugins/quickopen/expandingtree/expandingwidgetmodel.cpp @@ -89,18 +89,19 @@ QVariant ExpandingWidgetModel::data( const QModelIndex & index, int role ) const { + QModelIndex sourceIndex = proxyModel()->mapFromSource(index); switch( role ) { case Qt::BackgroundRole: { - if( index.column() == 0 ) { + if( sourceIndex.column() == 0 ) { //Highlight by match-quality uint color = matchColor(index); if( color ) return QBrush( color ); } //Use a special background-color for expanded items - if( isExpanded(index) ) { - if( index.row() & 1 ) { + if( isExpanded(sourceIndex) ) { + if( sourceIndex.row() & 1 ) { return doAlternate(treeView()->palette().toolTipBase().color()); } else { return treeView()->palette().toolTipBase(); @@ -171,10 +172,12 @@ //Notify the underlying models that the item was selected, and eventually get back the text for the expanding widget. if( !idx.isValid() ) { //All items have been unselected - if( oldIndex.isValid() ) - emit dataChanged(oldIndex, oldIndex); + if( oldIndex.isValid() ) { + QModelIndex oldSourceIndex = proxyModel()->mapToSource(oldIndex); + emit dataChanged(oldSourceIndex, oldSourceIndex); + } } else { - QVariant variant = data(idx, CodeCompletionModel::ItemSelected); + QVariant variant = data(proxyModel()->mapToSource(idx), CodeCompletionModel::ItemSelected); if( !isExpanded(idx) && variant.type() == QVariant::String) { @@ -187,7 +190,7 @@ //Say that one row above until one row below has changed, so no items will need to be moved(the space that is taken from one item is given to the other) if( oldIndex.isValid() && oldIndex < idx ) { - emit dataChanged(oldIndex, idx); + emit dataChanged(proxyModel()->mapToSource(oldIndex), proxyModel()->mapToSource(idx)); if( treeView()->verticalScrollMode() == QAbstractItemView::ScrollPerItem ) { @@ -221,7 +224,7 @@ //Since this also doesn't work smoothly, leave it for now //treeView()->scrollTo( nextLine, QAbstractItemView::EnsureVisible ); } else if( oldIndex.isValid() && idx < oldIndex ) { - emit dataChanged(idx, oldIndex); + emit dataChanged(proxyModel()->mapToSource(idx), proxyModel()->mapToSource(oldIndex)); //For consistency with the down-scrolling, we keep one additional line visible above the current visible. @@ -230,11 +233,11 @@ if( prevLine.isValid() ) treeView()->scrollTo( prevLine );*/ } else - emit dataChanged(idx, idx); + emit dataChanged(proxyModel()->mapToSource(idx), proxyModel()->mapToSource(idx)); } else if( oldIndex.isValid() ) { //We are not partially expanding a new row, but we previously had a partially expanded row. So signalize that it has been unexpanded. - emit dataChanged(oldIndex, oldIndex); + emit dataChanged(proxyModel()->mapToSource(oldIndex), proxyModel()->mapToSource(oldIndex)); } } }else{ @@ -246,7 +249,7 @@ if( !idx.isValid() ) return QString(); - return data(firstColumn(idx), CodeCompletionModel::ItemSelected).toString(); + return data(firstColumn(proxyModel()->mapToSource(idx)), CodeCompletionModel::ItemSelected).toString(); } QRect ExpandingWidgetModel::partialExpandRect(const QModelIndex& idx_) const @@ -295,7 +298,7 @@ if( !m_expandState.contains(idx) ) { m_expandState.insert(idx, NotExpandable); - QVariant v = data(idx, CodeCompletionModel::IsExpandable); + QVariant v = data(proxyModel()->mapToSource(idx), CodeCompletionModel::IsExpandable); if( v.canConvert() && v.toBool() ) m_expandState[idx] = Expandable; } @@ -329,7 +332,7 @@ if( expanded && !m_expandingWidgets.contains(idx) ) { - QVariant v = data(idx, CodeCompletionModel::ExpandingWidget); + QVariant v = data(proxyModel()->mapToSource(idx), CodeCompletionModel::ExpandingWidget); if( v.canConvert() ) { m_expandingWidgets[idx] = v.value(); @@ -348,7 +351,7 @@ if( !expanded && firstColumn(treeView()->currentIndex()) == idx && (isPartiallyExpanded(idx) == ExpandingWidgetModel::ExpansionType::NotExpanded) ) rowSelected(idx); //Partially expand the row. - emit dataChanged(idx, idx); + emit dataChanged(proxyModel()->mapToSource(idx), proxyModel()->mapToSource(idx)); if(treeView()) treeView()->scrollTo(idx); @@ -526,4 +529,3 @@ //Combine the custom-highlightings return totalHighlighting; } - diff --git a/plugins/quickopen/quickopenmodel.h b/plugins/quickopen/quickopenmodel.h --- a/plugins/quickopen/quickopenmodel.h +++ b/plugins/quickopen/quickopenmodel.h @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -80,8 +81,10 @@ //The expandingwidgetmodel needs access to the tree-view void setTreeView( QTreeView* view ); + void setProxyModel( QSortFilterProxyModel* proxyModel ); QTreeView* treeView() const override; + QSortFilterProxyModel* proxyModel() const override; virtual QSet fileSet() const; @@ -126,7 +129,7 @@ QSet m_enabledItems; QSet m_enabledScopes; + QSortFilterProxyModel* proxy_model; }; #endif - diff --git a/plugins/quickopen/quickopenmodel.cpp b/plugins/quickopen/quickopenmodel.cpp --- a/plugins/quickopen/quickopenmodel.cpp +++ b/plugins/quickopen/quickopenmodel.cpp @@ -34,7 +34,7 @@ using namespace KDevelop; -QuickOpenModel::QuickOpenModel( QWidget* parent ) : ExpandingWidgetModel( parent ), m_treeView(nullptr), m_expandingWidgetHeightIncrease(0), m_resetBehindRow(0) +QuickOpenModel::QuickOpenModel( QWidget* parent ) : ExpandingWidgetModel( parent ), m_treeView(nullptr), m_expandingWidgetHeightIncrease(0), m_resetBehindRow(0), proxy_model(nullptr) { m_resetTimer = new QTimer(this); m_resetTimer->setSingleShot(true); @@ -323,10 +323,10 @@ switch( role ) { case Qt::DecorationRole: { - if( isExpandable(index) ) { + if( isExpandable( proxyModel()->mapFromSource(index) ) ) { //Show the expanded/unexpanded handles cacheIcons(); - if( isExpanded(index) ) { + if( isExpanded( proxyModel()->mapFromSource(index) ) ) { return m_expandedIcon; } else { return m_collapsedIcon; @@ -418,10 +418,18 @@ return m_treeView; } +QSortFilterProxyModel* QuickOpenModel::proxyModel() const { + return proxy_model; +} + bool QuickOpenModel::indexIsItem(const QModelIndex& /*index*/) const { return true; } +void QuickOpenModel::setProxyModel( QSortFilterProxyModel* proxyModel ) { + proxy_model = proxyModel; +} + void QuickOpenModel::setTreeView( QTreeView* view ) { m_treeView = view; } diff --git a/plugins/quickopen/quickopenwidget.h b/plugins/quickopen/quickopenwidget.h --- a/plugins/quickopen/quickopenwidget.h +++ b/plugins/quickopen/quickopenwidget.h @@ -28,6 +28,7 @@ #include #include #include +#include class QuickOpenModel; @@ -79,6 +80,7 @@ void avoidMenuAltFocus(); QuickOpenModel* m_model; + QSortFilterProxyModel* m_proxy; bool m_expandedTemporary, m_hadNoCommandSinceAlt; QTime m_altDownTime; QString m_preselectedText; diff --git a/plugins/quickopen/quickopenwidget.cpp b/plugins/quickopen/quickopenwidget.cpp --- a/plugins/quickopen/quickopenwidget.cpp +++ b/plugins/quickopen/quickopenwidget.cpp @@ -198,7 +198,16 @@ ui.list->setModel( nullptr ); ui.list->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); m_model->setTreeView( ui.list ); - ui.list->setModel( m_model ); + + m_proxy = new QSortFilterProxyModel; + m_proxy->setSourceModel(m_model); + m_proxy->setDynamicSortFilter(true); + if( m_model->allScopes().isEmpty() && m_model->allTypes().isEmpty() ) + m_proxy->sort(1); + + m_model->setProxyModel(m_proxy); + + ui.list->setModel( m_proxy ); m_filterTimer.stop(); m_filter = QString(); @@ -223,6 +232,8 @@ } QuickOpenWidget::~QuickOpenWidget() { + delete m_proxy; + m_model->setProxyModel( nullptr ); m_model->setTreeView( nullptr ); } @@ -311,7 +322,8 @@ m_model->textChanged( m_filter ); QModelIndex currentIndex = m_model->index(0, 0, QModelIndex()); - ui.list->selectionModel()->setCurrentIndex( currentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows | QItemSelectionModel::Current ); + + ui.list->selectionModel()->setCurrentIndex( m_proxy->mapFromSource( currentIndex ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows | QItemSelectionModel::Current ); callRowSelected(); } @@ -326,7 +338,7 @@ void QuickOpenWidget::accept() { QString filterText = ui.searchLine->text(); - m_model->execute( ui.list->currentIndex(), filterText ); + m_model->execute( m_proxy->mapToSource( ui.list->currentIndex() ), filterText ); } void QuickOpenWidget::doubleClicked ( const QModelIndex & index ) { @@ -490,7 +502,7 @@ //which kills the quickopen widget. QPointer stillExists(this); - if( m_model->execute( ui.list->currentIndex(), filterText ) ) { + if( m_model->execute( m_proxy->mapToSource( ui.list->currentIndex() ), filterText ) ) { if(!stillExists) return true;