7 #include <QDragEnterEvent>
8 #include <QDragLeaveEvent>
9 #include <QDragMoveEvent>
15 #include <QStringList>
19 #include "ui_dbdistributorselectorcomponent.h"
32 using namespace swift::misc::simulation;
33 using namespace swift::misc::network;
37 CDbDistributorSelectorComponent::CDbDistributorSelectorComponent(QWidget *parent)
40 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
42 this->setFocusProxy(ui->le_Distributor);
43 this->setAcceptDrops(
true);
47 bool c = connect(ui->le_Distributor, &QLineEdit::editingFinished,
this,
48 &CDbDistributorSelectorComponent::onDataChanged, Qt::QueuedConnection);
49 Q_ASSERT_X(c, Q_FUNC_INFO,
"Missing connect");
54 &CDbDistributorSelectorComponent::onDistributorsRead, Qt::QueuedConnection);
55 Q_ASSERT_X(c, Q_FUNC_INFO,
"Missing connect");
58 this->onDistributorsRead(CEntityFlags::DistributorEntity, CEntityFlags::ReadFinished,
69 const QString key(distributor.
getDbKey());
70 if (key.isEmpty()) {
return; }
71 if (distributor != m_currentDistributor)
73 ui->le_Distributor->setText(key);
74 m_currentDistributor = distributor;
81 QString keyOrAlias(distributorKeyOrAlias.toUpper().trimmed());
87 ui->lbl_Description->setText(
"");
88 ui->le_Distributor->setText(keyOrAlias);
95 const QString distributorKeyOrAlias(ui->le_Distributor->text().trimmed().toUpper());
96 if (distributorKeyOrAlias.isEmpty()) {
return CDistributor(); }
97 if (m_currentDistributor.
matchesKeyOrAlias(distributorKeyOrAlias)) {
return m_currentDistributor; }
112 ui->lbl_Description->setVisible(description);
119 ui->le_Distributor->clear();
125 if (!event || !
acceptDrop(event->mimeData())) {
return; }
126 setBackgroundRole(QPalette::Highlight);
127 event->acceptProposedAction();
132 if (!event || !
acceptDrop(event->mimeData())) {
return; }
133 event->acceptProposedAction();
138 if (!event) {
return; }
144 if (!event || !
acceptDrop(event->mimeData())) {
return; }
157 if (distributors.
isEmpty()) {
return; }
163 void CDbDistributorSelectorComponent::onDistributorsRead(CEntityFlags::Entity entity,
167 if (entity.testFlag(CEntityFlags::DistributorEntity) && CEntityFlags::isFinishedReadState(readState))
171 const QStringList keysAndAliases(
173 QCompleter *c =
new QCompleter(keysAndAliases,
this);
174 c->setCaseSensitivity(Qt::CaseInsensitive);
175 c->setCompletionMode(QCompleter::PopupCompletion);
176 c->setMaxVisibleItems(10);
177 connect(c, qOverload<const QString &>(&QCompleter::activated),
this,
178 &CDbDistributorSelectorComponent::onCompleterActivated);
180 ui->le_Distributor->setCompleter(c);
181 m_completerDistributors.reset(c);
186 m_completerDistributors.reset(
nullptr);
192 void CDbDistributorSelectorComponent::onDataChanged()
195 const QString keyOrAlias(ui->le_Distributor->text().trimmed().toUpper());
196 if (keyOrAlias.isEmpty()) {
return; }
201 void CDbDistributorSelectorComponent::onCompleterActivated(
const QString &distributorKeyOrAlias)
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
int getDistributorsCount() const
Distributors count.
swift::misc::simulation::CDistributorList getDistributors() const
Distributors.
bool acceptDrop(const QMimeData *mime) const
Accept drop?
swift::misc::CVariant toCVariant(const QMimeData *mime) const
Mime data to CVariant (normally encapsulating a value object)
void setAcceptedMetaTypeIds(const QList< int > &ids)
Accepted ids.
void clear()
Clear selection.
void changedDistributor(const swift::misc::simulation::CDistributor &distributor)
Distributor was changed.
virtual void dragLeaveEvent(QDragLeaveEvent *event)
bool isSet() const
Set with valid Distributor.
virtual void dropEvent(QDropEvent *event)
void setReadOnly(bool readOnly)
Read only.
virtual void dragMoveEvent(QDragMoveEvent *event)
virtual void dragEnterEvent(QDragEnterEvent *event)
void setDistributor(const swift::misc::simulation::CDistributor &distributor)
Current distributor.
swift::misc::simulation::CDistributor getDistributor() const
Distributor.
virtual ~CDbDistributorSelectorComponent()
Destructor.
void withDistributorDescription(bool description)
Display distributor description.
reference front()
Access the first element.
bool isEmpty() const
Synonym for empty.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T value() const
Return the value converted to the type T.
bool isValid() const
True if this variant is valid.
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
OBJ findByKey(KEYTYPE key, const OBJ ¬Found=OBJ()) const
Object with key, notFound otherwise.
bool hasValidDbKey() const
Has valid DB key.
const QString & getDbKey() const
Get DB key.
ReadState
State of operation.
Value object encapsulating information of software distributor.
bool matchesKeyOrAlias(const QString &keyOrAlias) const
Matches key or alias.
bool hasCompleteData() const
Complete data?
Value object encapsulating a list of distributors.
CDistributor findByKeyOrAlias(const QString &keyOrAlias) const
Find by id or alias.
QStringList getDbKeysAndAliases(bool sort) const
All DB keys and aliases.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.