ui: search view autocompletion

- Implemented autocompletion for the QtSearchView.
- Added: MessageFinishedParsing that will be dispatched by the Project after the parsing step is done.
- Moved the initial MessageActivateToken from the Project to the Application.
- Added getNamesForNodesWithNamePrefix() to GraphAccess.
This commit is contained in:
malte_langkabel
2014-07-07 11:25:46 +02:00
parent a70a9009cc
commit c02767362f
18 changed files with 162 additions and 11 deletions
+3 -2
View File
@@ -37,8 +37,9 @@ const std::string& QtCodeFile::getFileName() const
void QtCodeFile::addCodeSnippet(
const std::string& str, const TokenLocationFile& locationFile, int startLineNumber, Id activeTokenId
){
std::shared_ptr<QtCodeSnippet> snippet =
std::make_shared<QtCodeSnippet>(m_parentView, str, locationFile, startLineNumber, activeTokenId, this);
std::shared_ptr<QtCodeSnippet> snippet(
new QtCodeSnippet(m_parentView, str, locationFile, startLineNumber, activeTokenId, this)
);
layout()->addWidget(snippet.get());
m_snippets.push_back(snippet);
}
+18
View File
@@ -1,10 +1,13 @@
#include "qt/element/QtEditBox.h"
#include "utility/logging/logging.h"
QtEditBox::QtEditBox(QWidget *parent)
: QLineEdit(parent)
, m_onReturnPressed(nullptr)
, m_onTextEdited(nullptr)
{
connect(this, SIGNAL(returnPressed()), this, SLOT(slotOnReturnPressed()));
connect(this, SIGNAL(textEdited(const QString&)), this, SLOT(slotOnTextEdited(const QString&)));
}
QtEditBox::~QtEditBox()
@@ -16,8 +19,23 @@ void QtEditBox::setCallbackOnReturnPressed(std::function<void(void)> callback)
m_onReturnPressed = callback;
}
void QtEditBox::setCallbackOnTextEdited(std::function<void(const std::string&)> callback)
{
m_onTextEdited = callback;
}
void QtEditBox::slotOnReturnPressed()
{
if (m_onReturnPressed)
{
m_onReturnPressed();
}
}
void QtEditBox::slotOnTextEdited(const QString& text)
{
if (m_onTextEdited)
{
m_onTextEdited(text.toStdString());
}
}
+3
View File
@@ -14,12 +14,15 @@ public:
~QtEditBox();
void setCallbackOnReturnPressed(std::function<void(void)> callback);
void setCallbackOnTextEdited(std::function<void(const std::string&)> callback);
private slots:
void slotOnReturnPressed();
void slotOnTextEdited(const QString& text);
private:
std::function<void(void)> m_onReturnPressed;
std::function<void(const std::string&)> m_onTextEdited;
};
#endif // QT_EDIT_BOX_H
+34 -3
View File
@@ -10,6 +10,8 @@
QtSearchView::QtSearchView(ViewLayout* viewLayout)
: SearchView(viewLayout)
, m_setTextFunctor(std::bind(&QtSearchView::doSetText, this, std::placeholders::_1))
, m_setAutocompletionListFunctor(std::bind(&QtSearchView::doSetAutocompletionList, this, std::placeholders::_1))
{
}
@@ -36,6 +38,11 @@ void QtSearchView::initGui()
m_searchBox->setPlaceholderText("Please enter your search string.");
m_searchBox->setCallbackOnReturnPressed(std::bind(&QtSearchView::onSeachButtonClick, this));
std::vector<std::string> autocompletionList;
autocompletionList.push_back("tralala");
autocompletionList.push_back("lalila");
setAutocompletionList(autocompletionList);
m_searchButton = new QtButton(widget);
m_searchButton->setText("Search");
m_searchButton->setCallbackOnClick(std::bind(&QtSearchView::onSeachButtonClick, this));
@@ -44,7 +51,26 @@ void QtSearchView::initGui()
widget->layout()->addWidget(m_searchButton);
}
void QtSearchView::setText(const std::string& s) const
void QtSearchView::setText(const std::string& s)
{
m_setTextFunctor(s);
}
void QtSearchView::setAutocompletionList(const std::vector<std::string>& autocompletionList)
{
m_setAutocompletionListFunctor(autocompletionList);
}
void QtSearchView::onSeachButtonClick()
{
SearchController* controller = getController();
if (controller)
{
controller->search(m_searchBox->text().toStdString());
}
}
void QtSearchView::doSetText(const std::string& s)
{
if (m_searchBox->text() != s.c_str())
{
@@ -52,7 +78,12 @@ void QtSearchView::setText(const std::string& s) const
}
}
void QtSearchView::onSeachButtonClick()
void QtSearchView::doSetAutocompletionList(const std::vector<std::string>& autocompletionList)
{
getController()->search(m_searchBox->text().toStdString());
QStringList wordList;
for (const std::string& s: autocompletionList)
wordList << s.c_str();
QCompleter *completer = new QCompleter(wordList, m_searchBox);
completer->setCaseSensitivity(Qt::CaseInsensitive);
m_searchBox->setCompleter(completer);
}
+10 -1
View File
@@ -1,7 +1,10 @@
#ifndef QT_SEARCH_VIEW_H
#define QT_SEARCH_VIEW_H
#include <vector>
#include "component/view/SearchView.h"
#include "qt/utility/QtThreadedFunctor.h"
class QtEditBox;
class QtButton;
@@ -17,13 +20,19 @@ public:
virtual void initGui();
// SearchView implementation
virtual void setText(const std::string& s) const;
virtual void setText(const std::string& s);
virtual void setAutocompletionList(const std::vector<std::string>& autocompletionList);
private:
void onSeachButtonClick();
void doSetText(const std::string& s);
void doSetAutocompletionList(const std::vector<std::string>& autocompletionList);
QtEditBox* m_searchBox;
QtButton* m_searchButton;
QtThreadedFunctor<const std::string&> m_setTextFunctor;
QtThreadedFunctor<const std::vector<std::string>&> m_setAutocompletionListFunctor;
};
# endif // QT_SEARCH_VIEW_H