ui: Tab in search completes up to next ::, Delete erases to last ::

bug id = 133
This commit is contained in:
Eberhard Graether
2016-08-06 16:39:43 +02:00
parent fae418897c
commit 17fece804b
7 changed files with 67 additions and 5 deletions
+43 -4
View File
@@ -17,6 +17,8 @@
#include "component/view/GraphViewStyle.h"
#include "settings/ColorScheme.h"
std::string QtSmartSearchBox::s_delimiter = "::";
QtSearchElement::QtSearchElement(const QString& text, QWidget* parent)
: QPushButton(text, parent)
{
@@ -144,7 +146,16 @@ bool QtSmartSearchBox::event(QEvent *event)
{
if (m_completer->popup()->isVisible())
{
addMatchAndUpdate(m_highlightedMatch);
if (m_highlightedMatch.hasChildren)
{
setEditText((m_highlightedMatch.text + s_delimiter).c_str());
}
else
{
setEditText(m_highlightedMatch.text.c_str());
}
requestAutoCompletions();
}
else if (m_allowMultipleElements)
{
@@ -193,7 +204,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
return;
}
}
else if (event->matches(QKeySequence::Delete))
else if (event->matches(QKeySequence::Delete) || event->matches(QKeySequence::DeleteStartOfWord))
{
if (hasSelectedElements())
{
@@ -206,6 +217,27 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
deleteSelectedElements();
return;
}
else
{
std::vector<std::string> names = utility::splitToVector(text().toStdString(), s_delimiter);
if (names.back() == "")
{
names.pop_back();
}
if (names.size() < 2)
{
setEditText("");
}
else
{
names.back() = "";
setEditText(utility::join(names, s_delimiter).c_str());
}
requestAutoCompletions();
return;
}
}
else if (event->matches(QKeySequence::MoveToPreviousChar))
{
@@ -863,9 +895,16 @@ void QtSmartSearchBox::clearLineEdit()
hideAutoCompletions();
}
void QtSmartSearchBox::requestAutoCompletions() const
void QtSmartSearchBox::requestAutoCompletions()
{
MessageSearchAutocomplete(text().toStdString()).dispatch();
if (text().size())
{
MessageSearchAutocomplete(text().toStdString()).dispatch();
}
else
{
hideAutoCompletions();
}
}
void QtSmartSearchBox::hideAutoCompletions()
+3 -1
View File
@@ -66,6 +66,8 @@ private slots:
void onElementSelected(QtSearchElement* element);
private:
static std::string s_delimiter;
void moveCursor(int offset);
void moveCursorTo(int goal);
@@ -90,7 +92,7 @@ private:
void updatePlaceholder();
void clearLineEdit();
void requestAutoCompletions() const;
void requestAutoCompletions();
void hideAutoCompletions();
std::deque<SearchMatch> getMatchesForInput(const std::string& text) const;