From 75c57f392db1cfb7f45b94ba4effae5461f58154 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 12 Sep 2012 16:47:44 +0200 Subject: [PATCH] scide: LookupDialog - redo lookup on classes after partial lookup Signed-off-by: Tim Blechmann --- editors/sc-ide/widgets/lookup_dialog.cpp | 31 ++++++++++++++++++++++++++++++- editors/sc-ide/widgets/lookup_dialog.hpp | 10 ++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/editors/sc-ide/widgets/lookup_dialog.cpp b/editors/sc-ide/widgets/lookup_dialog.cpp index fb26fa261..639b5dd8b 100644 --- a/editors/sc-ide/widgets/lookup_dialog.cpp +++ b/editors/sc-ide/widgets/lookup_dialog.cpp @@ -132,7 +132,7 @@ using std::pair; using std::vector; LookupDialog::LookupDialog( QWidget * parent ): - GenericLookupDialog(parent) + GenericLookupDialog(parent), mIsPartialQuery(false) { setWindowTitle(tr("Look Up Class or Method Definition")); @@ -155,6 +155,7 @@ void LookupDialog::performQuery() return; } + mIsPartialQuery = false; if (queryString[0].isUpper()) { bool success = performClassQuery(queryString); if (success) { @@ -174,6 +175,33 @@ void LookupDialog::performQuery() focusResults(); } +void LookupDialog::onAccepted(QModelIndex currentIndex) +{ + if (!mIsPartialQuery) { + GenericLookupDialog::onAccepted(currentIndex); + return; + } + + QStandardItemModel * model = qobject_cast(mResult->model()); + currentIndex = currentIndex.sibling(currentIndex.row(), 0); + QStandardItem *currentItem = model->itemFromIndex(currentIndex); + + if (!currentItem) { + reject(); + return; + } + + bool isClass = currentItem->data(IsClassRole).toBool(); + if (!isClass) { + GenericLookupDialog::onAccepted(currentIndex); + return; + } + + QString className = currentItem->text(); + mQueryEdit->setText(className); + performQuery(); +} + QList GenericLookupDialog::makeDialogItem( QString const & name, QString const & displayPath, QString const & path, int position, bool isClassItem ) { @@ -275,6 +303,7 @@ QStandardItemModel * LookupDialog::modelForPartialQuery(const QString & queryStr return NULL; } + mIsPartialQuery = true; QStandardItemModel * model = new QStandardItemModel(this); QStandardItem *parentItem = model->invisibleRootItem(); diff --git a/editors/sc-ide/widgets/lookup_dialog.hpp b/editors/sc-ide/widgets/lookup_dialog.hpp index 583563cc0..f80201909 100644 --- a/editors/sc-ide/widgets/lookup_dialog.hpp +++ b/editors/sc-ide/widgets/lookup_dialog.hpp @@ -43,11 +43,14 @@ public: void query( const QString & query ) { mQueryEdit->setText(query); this->performQuery(); } void clearQuery() { mQueryEdit->clear(); } -private slots: - void onAccepted(QModelIndex); +protected Q_SLOTS: + virtual void onAccepted(QModelIndex); + +private Q_SLOTS: virtual void performQuery() = 0; protected: + QStandardItem * currentItem(); bool eventFilter( QObject *, QEvent * ); void paintEvent( QPaintEvent * ); void focusResults(); @@ -68,6 +71,7 @@ public: private slots: void performQuery(); + void onAccepted(QModelIndex); private: QStandardItemModel * modelForClass(const QString & className); @@ -76,6 +80,8 @@ private: bool performClassQuery(const QString & className); bool performMethodQuery(const QString & methodName); bool performPartialQuery(const QString & queryString); + + bool mIsPartialQuery; }; // LATER: cache symbol references to avoid duplicate lookup -- 2.11.4.GIT