Commit 3f305ce6 authored by Patrick Avery's avatar Patrick Avery

Add Auto Completer for StringItem QLineEdit

parent aaa91e4a
Pipeline #112326 passed with stage
......@@ -48,3 +48,15 @@ bool StringItem::isSecure() const
return sdef->isSecure();
const std::vector<std::string>& StringItem::autoCompleteList() const
const StringItemDefinition* sdef =
static_cast<const StringItemDefinition*>(this->definition().get());
if (!sdef)
static const std::vector<std::string> emptyVec;
return emptyVec;
return sdef->autoCompleteList();
......@@ -35,6 +35,11 @@ public:
// Returns true if the item's value is not to be displayed in a GUI
bool isSecure() const;
// If a line edit is to be used, this returns the auto complete list.
// The sorting of the autocomplete list will be based entirely upon the
// sorting present in the std::vector.
const std::vector<std::string>& autoCompleteList() const;
// Assigns this item to be equivalent to another. Options are processed by derived item classes
// Returns true if success and false if a problem occured. By default, an attribute being used by this
// to represent an expression will be copied if needed. Use IGNORE_EXPRESSIONS option to prevent this
......@@ -43,12 +43,16 @@ public:
void setIsSecure(bool val) { m_secure = val; }
bool isSecure() const { return m_secure; }
void setAutoCompleteList(const std::vector<std::string>& list) { m_autoCompleteList = list; };
const std::vector<std::string>& autoCompleteList() const { return m_autoCompleteList; }
smtk::attribute::ItemDefinitionPtr createCopy(
smtk::attribute::ItemDefinition::CopyInfo& info) const override;
StringItemDefinition(const std::string& myName);
bool m_multiline;
std::vector<std::string> m_autoCompleteList;
bool m_secure;
......@@ -34,6 +34,8 @@ PySharedPtrClass< smtk::attribute::StringItemDefinition, smtk::attribute::ValueI
.def("isSecure", &smtk::attribute::StringItemDefinition::isSecure)
.def("setIsMultiline", &smtk::attribute::StringItemDefinition::setIsMultiline, py::arg("val"))
.def("setIsSecure", &smtk::attribute::StringItemDefinition::setIsSecure, py::arg("val"))
.def("setAutoCompleteList", &smtk::attribute::StringItemDefinition::setAutoCompleteList, py::arg("list"))
.def("autoCompleteList", &smtk::attribute::StringItemDefinition::autoCompleteList)
.def("type", &smtk::attribute::StringItemDefinition::type)
.def_static("ToItemDefinition", [](const std::shared_ptr<smtk::attribute::StringItemDefinition> d) {
return std::dynamic_pointer_cast<smtk::attribute::ItemDefinition>(d);
......@@ -18,6 +18,7 @@
#include <QCheckBox>
#include <QComboBox>
#include <QCompleter>
#include <QDoubleSpinBox>
#include <QDoubleValidator>
#include <QFrame>
......@@ -1132,6 +1133,20 @@ QWidget* qtInputsItem::createEditBox(int elementIdx, QWidget* pWidget)
// Check to see if there is an autocomplete list. If so, make a
// QCompleter.
if (!sitem->autoCompleteList().empty())
QStringList autoCompleteList;
for (const auto& entry : sitem->autoCompleteList())
QCompleter* completer = new QCompleter(autoCompleteList, lineEdit);
// This will keep the same sorting the user provided
inputWidget = lineEdit;
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