Introduced checkable results.

This commit is contained in:
Roberto Raggi
2009-09-29 18:16:13 +02:00
parent 3d62363fee
commit 331effc2fd
7 changed files with 104 additions and 3 deletions

View File

@@ -439,7 +439,9 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
void CppFindReferences::findAll(Symbol *symbol) void CppFindReferences::findAll(Symbol *symbol)
{ {
const bool wasInReplaceMode = _resultWindow->isShowingReplaceUI();
_resultWindow->clearContents(); _resultWindow->clearContents();
_resultWindow->setShowReplaceUI(true);
_resultWindow->popup(true); _resultWindow->popup(true);
const Snapshot snapshot = _modelManager->snapshot(); const Snapshot snapshot = _modelManager->snapshot();

View File

@@ -35,6 +35,7 @@
#include <QPainter> #include <QPainter>
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QApplication> #include <QApplication>
#include <QDebug>
#include <math.h> #include <math.h>
@@ -67,6 +68,18 @@ void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionVi
QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString); QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString);
QItemDelegate::drawFocus(painter, opt, opt.rect); 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(); painter->restore();
} }
} }

View File

@@ -32,7 +32,7 @@
using namespace Find::Internal; using namespace Find::Internal;
SearchResultTreeItem::SearchResultTreeItem(SearchResultTreeItem::ItemType type, const SearchResultTreeItem *parent) 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(); 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() void SearchResultTreeItem::clearChildren()
{ {
qDeleteAll(m_children); qDeleteAll(m_children);
@@ -62,7 +82,7 @@ int SearchResultTreeItem::rowOfItem() const
return (m_parent ? m_parent->m_children.indexOf(const_cast<SearchResultTreeItem*>(this)):0); 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); 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, SearchResultTreeItem *child = new SearchResultTextRow(index, lineNumber, rowText,
searchTermStart, searchTermLength, this); searchTermStart, searchTermLength, this);
if (isUserCheckable()) {
child->setIsUserCheckable(true);
child->setCheckState(Qt::Checked);
}
appendChild(child); appendChild(child);
} }

View File

@@ -54,16 +54,24 @@ public:
ItemType itemType() const; ItemType itemType() const;
const SearchResultTreeItem *parent() const; const SearchResultTreeItem *parent() const;
const SearchResultTreeItem *childAt(int index) const; SearchResultTreeItem *childAt(int index) const;
void appendChild(SearchResultTreeItem *child); void appendChild(SearchResultTreeItem *child);
int childrenCount() const; int childrenCount() const;
int rowOfItem() const; int rowOfItem() const;
void clearChildren(); void clearChildren();
bool isUserCheckable() const;
void setIsUserCheckable(bool isUserCheckable);
Qt::CheckState checkState() const;
void setCheckState(Qt::CheckState checkState);
private: private:
ItemType m_type; ItemType m_type;
const SearchResultTreeItem *m_parent; const SearchResultTreeItem *m_parent;
QList<SearchResultTreeItem *> m_children; QList<SearchResultTreeItem *> m_children;
bool m_isUserCheckable;
Qt::CheckState m_checkState;
}; };
class SearchResultTextRow : public SearchResultTreeItem class SearchResultTextRow : public SearchResultTreeItem

View File

@@ -36,12 +36,14 @@
#include <QtGui/QColor> #include <QtGui/QColor>
#include <QtGui/QPalette> #include <QtGui/QPalette>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QDebug>
using namespace Find::Internal; using namespace Find::Internal;
SearchResultTreeModel::SearchResultTreeModel(QObject *parent) SearchResultTreeModel::SearchResultTreeModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
, m_lastAppendedResultFile(0) , m_lastAppendedResultFile(0)
, m_showReplaceUI(false)
{ {
m_rootItem = new SearchResultTreeItem(); m_rootItem = new SearchResultTreeItem();
m_textEditorFont = QFont("Courier"); m_textEditorFont = QFont("Courier");
@@ -52,11 +54,31 @@ SearchResultTreeModel::~SearchResultTreeModel()
delete m_rootItem; delete m_rootItem;
} }
void SearchResultTreeModel::setShowReplaceUI(bool show)
{
m_showReplaceUI = show;
}
void SearchResultTreeModel::setTextEditorFont(const QFont &font) void SearchResultTreeModel::setTextEditorFont(const QFont &font)
{ {
m_textEditorFont = 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, QModelIndex SearchResultTreeModel::index(int row, int column,
const QModelIndex &parent) const const QModelIndex &parent) const
{ {
@@ -135,12 +157,28 @@ QVariant SearchResultTreeModel::data(const QModelIndex &index, int role) const
return result; 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 SearchResultTreeModel::data(const SearchResultTextRow *row, int role) const
{ {
QVariant result; QVariant result;
switch (role) switch (role)
{ {
case Qt::CheckStateRole:
if (row->isUserCheckable())
result = row->checkState();
break;
case Qt::ToolTipRole: case Qt::ToolTipRole:
result = row->rowText().trimmed(); result = row->rowText().trimmed();
break; break;
@@ -188,6 +226,12 @@ QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) con
switch (role) switch (role)
{ {
#if 0
case Qt::CheckStateRole:
if (file->isUserCheckable())
result = file->checkState();
break;
#endif
case Qt::BackgroundRole: { case Qt::BackgroundRole: {
const QColor baseColor = QApplication::palette().base().color(); const QColor baseColor = QApplication::palette().base().color();
result = baseColor.darker(105); result = baseColor.darker(105);
@@ -228,6 +272,11 @@ void SearchResultTreeModel::appendResultFile(const QString &fileName)
{ {
m_lastAppendedResultFile = new SearchResultFile(fileName, m_rootItem); 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(); const int childrenCount = m_rootItem->childrenCount();
beginInsertRows(QModelIndex(), childrenCount, childrenCount); beginInsertRows(QModelIndex(), childrenCount, childrenCount);
m_rootItem->appendChild(m_lastAppendedResultFile); m_rootItem->appendChild(m_lastAppendedResultFile);

View File

@@ -48,13 +48,16 @@ public:
SearchResultTreeModel(QObject *parent = 0); SearchResultTreeModel(QObject *parent = 0);
~SearchResultTreeModel(); ~SearchResultTreeModel();
void setShowReplaceUI(bool show);
void setTextEditorFont(const QFont &font); void setTextEditorFont(const QFont &font);
Qt::ItemFlags flags(const QModelIndex &index) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const; QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) 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; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex next(const QModelIndex &idx) const; QModelIndex next(const QModelIndex &idx) const;
@@ -81,6 +84,7 @@ private:
SearchResultTreeItem *m_rootItem; SearchResultTreeItem *m_rootItem;
SearchResultFile *m_lastAppendedResultFile; SearchResultFile *m_lastAppendedResultFile;
QFont m_textEditorFont; QFont m_textEditorFont;
bool m_showReplaceUI;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -109,6 +109,7 @@ SearchResultWindow::~SearchResultWindow()
void SearchResultWindow::setShowReplaceUI(bool show) void SearchResultWindow::setShowReplaceUI(bool show)
{ {
m_searchResultTreeView->model()->setShowReplaceUI(show);
m_replaceLabel->setVisible(show); m_replaceLabel->setVisible(show);
m_replaceTextEdit->setVisible(show); m_replaceTextEdit->setVisible(show);
m_replaceButton->setVisible(show); m_replaceButton->setVisible(show);