Commit 331effc2 authored by Roberto Raggi's avatar Roberto Raggi

Introduced checkable results.

parent 3d62363f
......@@ -439,7 +439,9 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
void CppFindReferences::findAll(Symbol *symbol)
{
const bool wasInReplaceMode = _resultWindow->isShowingReplaceUI();
_resultWindow->clearContents();
_resultWindow->setShowReplaceUI(true);
_resultWindow->popup(true);
const Snapshot snapshot = _modelManager->snapshot();
......
......@@ -35,6 +35,7 @@
#include <QPainter>
#include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QDebug>
#include <math.h>
......@@ -67,6 +68,18 @@ void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionVi
QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString);
QItemDelegate::drawFocus(painter, opt, opt.rect);
QVariant value = index.data(Qt::CheckStateRole);
if (value.isValid()) {
Qt::CheckState checkState = Qt::Unchecked;
checkState = static_cast<Qt::CheckState>(value.toInt());
QRect checkRect = check(opt, opt.rect, value);
QRect emptyRect;
doLayout(opt, &checkRect, &emptyRect, &emptyRect, false);
QItemDelegate::drawCheck(painter, opt, opt.rect, checkState);
}
painter->restore();
}
}
......
......@@ -32,7 +32,7 @@
using namespace Find::Internal;
SearchResultTreeItem::SearchResultTreeItem(SearchResultTreeItem::ItemType type, const SearchResultTreeItem *parent)
: m_type(type), m_parent(parent)
: m_type(type), m_parent(parent), m_isUserCheckable(false), m_checkState(Qt::Unchecked)
{
}
......@@ -41,6 +41,26 @@ SearchResultTreeItem::~SearchResultTreeItem()
clearChildren();
}
bool SearchResultTreeItem::isUserCheckable() const
{
return m_isUserCheckable;
}
void SearchResultTreeItem::setIsUserCheckable(bool isUserCheckable)
{
m_isUserCheckable = isUserCheckable;
}
Qt::CheckState SearchResultTreeItem::checkState() const
{
return m_checkState;
}
void SearchResultTreeItem::setCheckState(Qt::CheckState checkState)
{
m_checkState = checkState;
}
void SearchResultTreeItem::clearChildren()
{
qDeleteAll(m_children);
......@@ -62,7 +82,7 @@ int SearchResultTreeItem::rowOfItem() const
return (m_parent ? m_parent->m_children.indexOf(const_cast<SearchResultTreeItem*>(this)):0);
}
const SearchResultTreeItem* SearchResultTreeItem::childAt(int index) const
SearchResultTreeItem* SearchResultTreeItem::childAt(int index) const
{
return m_children.at(index);
}
......@@ -131,5 +151,9 @@ void SearchResultFile::appendResultLine(int index, int lineNumber, const QString
{
SearchResultTreeItem *child = new SearchResultTextRow(index, lineNumber, rowText,
searchTermStart, searchTermLength, this);
if (isUserCheckable()) {
child->setIsUserCheckable(true);
child->setCheckState(Qt::Checked);
}
appendChild(child);
}
......@@ -54,16 +54,24 @@ public:
ItemType itemType() const;
const SearchResultTreeItem *parent() const;
const SearchResultTreeItem *childAt(int index) const;
SearchResultTreeItem *childAt(int index) const;
void appendChild(SearchResultTreeItem *child);
int childrenCount() const;
int rowOfItem() const;
void clearChildren();
bool isUserCheckable() const;
void setIsUserCheckable(bool isUserCheckable);
Qt::CheckState checkState() const;
void setCheckState(Qt::CheckState checkState);
private:
ItemType m_type;
const SearchResultTreeItem *m_parent;
QList<SearchResultTreeItem *> m_children;
bool m_isUserCheckable;
Qt::CheckState m_checkState;
};
class SearchResultTextRow : public SearchResultTreeItem
......
......@@ -36,12 +36,14 @@
#include <QtGui/QColor>
#include <QtGui/QPalette>
#include <QtCore/QDir>
#include <QtCore/QDebug>
using namespace Find::Internal;
SearchResultTreeModel::SearchResultTreeModel(QObject *parent)
: QAbstractItemModel(parent)
, m_lastAppendedResultFile(0)
, m_showReplaceUI(false)
{
m_rootItem = new SearchResultTreeItem();
m_textEditorFont = QFont("Courier");
......@@ -52,11 +54,31 @@ SearchResultTreeModel::~SearchResultTreeModel()
delete m_rootItem;
}
void SearchResultTreeModel::setShowReplaceUI(bool show)
{
m_showReplaceUI = show;
}
void SearchResultTreeModel::setTextEditorFont(const QFont &font)
{
m_textEditorFont = font;
}
Qt::ItemFlags SearchResultTreeModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
if (index.isValid()) {
if (const SearchResultTreeItem *item = static_cast<const SearchResultTreeItem*>(index.internalPointer())) {
if (item->itemType() == SearchResultTreeItem::ResultRow && item->isUserCheckable()) {
flags |= Qt::ItemIsUserCheckable;
}
}
}
return flags;
}
QModelIndex SearchResultTreeModel::index(int row, int column,
const QModelIndex &parent) const
{
......@@ -135,12 +157,28 @@ QVariant SearchResultTreeModel::data(const QModelIndex &index, int role) const
return result;
}
bool SearchResultTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role == Qt::CheckStateRole) {
SearchResultTreeItem *item = static_cast<SearchResultTreeItem*>(index.internalPointer());
SearchResultTextRow *row = static_cast<SearchResultTextRow *>(item);
Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
row->setCheckState(checkState);
return true;
}
return QAbstractItemModel::setData(index, value, role);
}
QVariant SearchResultTreeModel::data(const SearchResultTextRow *row, int role) const
{
QVariant result;
switch (role)
{
case Qt::CheckStateRole:
if (row->isUserCheckable())
result = row->checkState();
break;
case Qt::ToolTipRole:
result = row->rowText().trimmed();
break;
......@@ -188,6 +226,12 @@ QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) con
switch (role)
{
#if 0
case Qt::CheckStateRole:
if (file->isUserCheckable())
result = file->checkState();
break;
#endif
case Qt::BackgroundRole: {
const QColor baseColor = QApplication::palette().base().color();
result = baseColor.darker(105);
......@@ -228,6 +272,11 @@ void SearchResultTreeModel::appendResultFile(const QString &fileName)
{
m_lastAppendedResultFile = new SearchResultFile(fileName, m_rootItem);
if (m_showReplaceUI) {
m_lastAppendedResultFile->setIsUserCheckable(true);
m_lastAppendedResultFile->setCheckState(Qt::Checked);
}
const int childrenCount = m_rootItem->childrenCount();
beginInsertRows(QModelIndex(), childrenCount, childrenCount);
m_rootItem->appendChild(m_lastAppendedResultFile);
......
......@@ -48,13 +48,16 @@ public:
SearchResultTreeModel(QObject *parent = 0);
~SearchResultTreeModel();
void setShowReplaceUI(bool show);
void setTextEditorFont(const QFont &font);
Qt::ItemFlags flags(const QModelIndex &index) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex next(const QModelIndex &idx) const;
......@@ -81,6 +84,7 @@ private:
SearchResultTreeItem *m_rootItem;
SearchResultFile *m_lastAppendedResultFile;
QFont m_textEditorFont;
bool m_showReplaceUI;
};
} // namespace Internal
......
......@@ -109,6 +109,7 @@ SearchResultWindow::~SearchResultWindow()
void SearchResultWindow::setShowReplaceUI(bool show)
{
m_searchResultTreeView->model()->setShowReplaceUI(show);
m_replaceLabel->setVisible(show);
m_replaceTextEdit->setVisible(show);
m_replaceButton->setVisible(show);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment