diff --git a/src/plugins/coreplugin/find/searchresulttreeitems.cpp b/src/plugins/coreplugin/find/searchresulttreeitems.cpp index 1b2e1c30531..57662b79ed0 100644 --- a/src/plugins/coreplugin/find/searchresulttreeitems.cpp +++ b/src/plugins/coreplugin/find/searchresulttreeitems.cpp @@ -37,9 +37,8 @@ SearchResultTreeItem::SearchResultTreeItem(const SearchResultItem &item, SearchResultTreeItem *parent) : item(item), m_parent(parent), - m_isUserCheckable(false), m_isGenerated(false), - m_checkState(Qt::Unchecked) + m_checkState(Qt::Checked) { } @@ -53,16 +52,6 @@ bool SearchResultTreeItem::isLeaf() const return childrenCount() == 0 && parent() != 0; } -bool SearchResultTreeItem::isUserCheckable() const -{ - return m_isUserCheckable; -} - -void SearchResultTreeItem::setIsUserCheckable(bool isUserCheckable) -{ - m_isUserCheckable = isUserCheckable; -} - Qt::CheckState SearchResultTreeItem::checkState() const { return m_checkState; @@ -130,10 +119,6 @@ void SearchResultTreeItem::insertChild(int index, SearchResultTreeItem *child) void SearchResultTreeItem::insertChild(int index, const SearchResultItem &item) { SearchResultTreeItem *child = new SearchResultTreeItem(item, this); - if (isUserCheckable()) { - child->setIsUserCheckable(true); - child->setCheckState(Qt::Checked); - } insertChild(index, child); } diff --git a/src/plugins/coreplugin/find/searchresulttreeitems.h b/src/plugins/coreplugin/find/searchresulttreeitems.h index 12506c8cf5e..7684ffeb1fc 100644 --- a/src/plugins/coreplugin/find/searchresulttreeitems.h +++ b/src/plugins/coreplugin/find/searchresulttreeitems.h @@ -58,9 +58,6 @@ public: int rowOfItem() const; void clearChildren(); - bool isUserCheckable() const; - void setIsUserCheckable(bool isUserCheckable); - Qt::CheckState checkState() const; void setCheckState(Qt::CheckState checkState); @@ -72,7 +69,6 @@ public: private: SearchResultTreeItem *m_parent; QList m_children; - bool m_isUserCheckable; bool m_isGenerated; Qt::CheckState m_checkState; }; diff --git a/src/plugins/coreplugin/find/searchresulttreemodel.cpp b/src/plugins/coreplugin/find/searchresulttreemodel.cpp index a8e04594c74..d7809160a21 100644 --- a/src/plugins/coreplugin/find/searchresulttreemodel.cpp +++ b/src/plugins/coreplugin/find/searchresulttreemodel.cpp @@ -57,7 +57,9 @@ SearchResultTreeModel::~SearchResultTreeModel() void SearchResultTreeModel::setShowReplaceUI(bool show) { + beginResetModel(); m_showReplaceUI = show; + endResetModel(); } void SearchResultTreeModel::setTextEditorFont(const QFont &font, const SearchResultColor &color) @@ -73,10 +75,8 @@ Qt::ItemFlags SearchResultTreeModel::flags(const QModelIndex &idx) const Qt::ItemFlags flags = QAbstractItemModel::flags(idx); if (idx.isValid()) { - if (const SearchResultTreeItem *item = treeItemAtIndex(idx)) { - if (item->isUserCheckable()) - flags |= Qt::ItemIsUserCheckable; - } + if (m_showReplaceUI) + flags |= Qt::ItemIsUserCheckable; } return flags; @@ -189,28 +189,24 @@ bool SearchResultTreeModel::setCheckState(const QModelIndex &idx, Qt::CheckState SearchResultTreeItem *currentItem = item; QModelIndex currentIndex = idx; while (SearchResultTreeItem *parent = currentItem->parent()) { - if (parent->isUserCheckable()) { - bool hasChecked = false; - bool hasUnchecked = false; - for (int i = 0; i < parent->childrenCount(); ++i) { - SearchResultTreeItem *child = parent->childAt(i); - if (!child->isUserCheckable()) - continue; - if (child->checkState() == Qt::Checked) - hasChecked = true; - else if (child->checkState() == Qt::Unchecked) - hasUnchecked = true; - else if (child->checkState() == Qt::PartiallyChecked) - hasChecked = hasUnchecked = true; - } - if (hasChecked && hasUnchecked) - parent->setCheckState(Qt::PartiallyChecked); - else if (hasChecked) - parent->setCheckState(Qt::Checked); - else - parent->setCheckState(Qt::Unchecked); - emit dataChanged(idx.parent(), idx.parent()); + bool hasChecked = false; + bool hasUnchecked = false; + for (int i = 0; i < parent->childrenCount(); ++i) { + SearchResultTreeItem *child = parent->childAt(i); + if (child->checkState() == Qt::Checked) + hasChecked = true; + else if (child->checkState() == Qt::Unchecked) + hasUnchecked = true; + else if (child->checkState() == Qt::PartiallyChecked) + hasChecked = hasUnchecked = true; } + if (hasChecked && hasUnchecked) + parent->setCheckState(Qt::PartiallyChecked); + else if (hasChecked) + parent->setCheckState(Qt::Checked); + else + parent->setCheckState(Qt::Unchecked); + emit dataChanged(idx.parent(), idx.parent()); currentItem = parent; currentIndex = idx.parent(); } @@ -234,8 +230,7 @@ QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role) switch (role) { case Qt::CheckStateRole: - if (row->isUserCheckable()) - result = row->checkState(); + result = row->checkState(); break; case Qt::ToolTipRole: result = row->item.text.trimmed(); @@ -315,10 +310,8 @@ QSet SearchResultTreeModel::addPath(const QStringList &p item.path = currentPath; item.text = part; partItem = new SearchResultTreeItem(item, currentItem); - if (m_showReplaceUI) { - partItem->setIsUserCheckable(true); + if (m_showReplaceUI) partItem->setCheckState(Qt::Checked); - } partItem->setGenerated(true); beginInsertRows(currentItemIndex, insertionIndex, insertionIndex); currentItem->insertChild(insertionIndex, partItem); diff --git a/src/plugins/coreplugin/find/searchresultwidget.cpp b/src/plugins/coreplugin/find/searchresultwidget.cpp index 1917d6ce4d4..1df894f6717 100644 --- a/src/plugins/coreplugin/find/searchresultwidget.cpp +++ b/src/plugins/coreplugin/find/searchresultwidget.cpp @@ -87,7 +87,8 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) : m_count(0), m_preserveCaseSupported(true), m_isShowingReplaceUI(false), - m_searchAgainSupported(false) + m_searchAgainSupported(false), + m_replaceSupported(false) { QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); @@ -206,7 +207,7 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) : topReplaceLayout->addWidget(m_replaceButton); topReplaceLayout->addWidget(m_preserveCaseCheck); topReplaceLayout->addStretch(2); - setShowReplaceUI(false); + setShowReplaceUI(m_replaceSupported); setSupportPreserveCase(true); connect(m_searchResultTreeView, SIGNAL(jumpToSearchResult(SearchResultItem)), @@ -262,7 +263,8 @@ void SearchResultWidget::addResults(const QList &items, Search m_replaceTextEdit->setEnabled(true); // We didn't have an item before, set the focus to the search widget or replace text edit - if (m_isShowingReplaceUI) { + setShowReplaceUI(m_replaceSupported); + if (m_replaceSupported) { m_replaceTextEdit->setFocus(); m_replaceTextEdit->selectAll(); } else { @@ -294,13 +296,10 @@ int SearchResultWidget::count() const return m_count; } -QString SearchResultWidget::dontAskAgainGroup() const -{ - return m_dontAskAgainGroup; -} - -void SearchResultWidget::setDontAskAgainGroup(const QString &group) +void SearchResultWidget::setSupportsReplace(bool replaceSupported, const QString &group) { + m_replaceSupported = replaceSupported; + setShowReplaceUI(replaceSupported); m_dontAskAgainGroup = group; } @@ -475,6 +474,7 @@ void SearchResultWidget::handleReplaceButton() // by pressing return in replace line edit if (m_replaceButton->isEnabled()) { m_infoBar.clear(); + setShowReplaceUI(false); emit replaceButtonClicked(m_replaceTextEdit->text(), checkedItems(), m_preserveCaseSupported && m_preserveCaseCheck->isChecked()); } diff --git a/src/plugins/coreplugin/find/searchresultwidget.h b/src/plugins/coreplugin/find/searchresultwidget.h index 2546f16d9e9..6023ee8f444 100644 --- a/src/plugins/coreplugin/find/searchresultwidget.h +++ b/src/plugins/coreplugin/find/searchresultwidget.h @@ -66,13 +66,11 @@ public: int count() const; - QString dontAskAgainGroup() const; - void setDontAskAgainGroup(const QString &group); + void setSupportsReplace(bool replaceSupported, const QString &group); void setTextToReplace(const QString &textToReplace); QString textToReplace() const; void setSupportPreserveCase(bool enabled); - void setShowReplaceUI(bool visible); bool hasFocusInternally() const; void setFocusInternally(); @@ -118,6 +116,7 @@ private slots: void searchAgain(); private: + void setShowReplaceUI(bool visible); void continueAfterSizeWarning(); void cancelAfterSizeWarning(); @@ -127,23 +126,24 @@ private: SearchResultTreeView *m_searchResultTreeView; int m_count; QString m_dontAskAgainGroup; - bool m_preserveCaseSupported; QFrame *m_messageWidget; InfoBar m_infoBar; InfoBarDisplay m_infoBarDisplay; - bool m_isShowingReplaceUI; QWidget *m_topReplaceWidget; QLabel *m_replaceLabel; QLineEdit *m_replaceTextEdit; QToolButton *m_replaceButton; QToolButton *m_searchAgainButton; QCheckBox *m_preserveCaseCheck; - bool m_searchAgainSupported; QWidget *m_descriptionContainer; QLabel *m_label; QLabel *m_searchTerm; QToolButton *m_cancelButton; QLabel *m_matchesFoundLabel; + bool m_preserveCaseSupported; + bool m_isShowingReplaceUI; + bool m_searchAgainSupported; + bool m_replaceSupported; }; } // Internal diff --git a/src/plugins/coreplugin/find/searchresultwindow.cpp b/src/plugins/coreplugin/find/searchresultwindow.cpp index 8233dd43885..3b73bd83b60 100644 --- a/src/plugins/coreplugin/find/searchresultwindow.cpp +++ b/src/plugins/coreplugin/find/searchresultwindow.cpp @@ -400,11 +400,10 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label, widget->setTextEditorFont(d->m_font, d->m_color); widget->setTabWidth(d->m_tabWidth); widget->setSupportPreserveCase(preserveCaseMode == PreserveCaseEnabled); - widget->setShowReplaceUI(searchOrSearchAndReplace != SearchOnly); + bool supportsReplace = searchOrSearchAndReplace != SearchOnly; + widget->setSupportsReplace(supportsReplace, supportsReplace ? cfgGroup : QString()); widget->setAutoExpandResults(d->m_expandCollapseAction->isChecked()); widget->setInfo(label, toolTip, searchTerm); - if (searchOrSearchAndReplace == SearchAndReplace) - widget->setDontAskAgainGroup(cfgGroup); auto result = new SearchResult(widget); d->m_searchResults.prepend(result); d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm));