7 #include <QDragEnterEvent>
8 #include <QDragLeaveEvent>
9 #include <QDragMoveEvent>
18 #include "ui_dbcountryselectorcomponent.h"
30 using namespace swift::misc::network;
34 CDbCountrySelectorComponent::CDbCountrySelectorComponent(QWidget *parent)
38 this->setFocusProxy(ui->le_CountryIso);
39 this->setAcceptDrops(
true);
42 connect(ui->le_CountryIso, &QLineEdit::returnPressed,
this, &CDbCountrySelectorComponent::onDataChanged);
43 connect(ui->le_CountryName, &QLineEdit::returnPressed,
this, &CDbCountrySelectorComponent::onDataChanged);
44 connect(ui->le_CountryIso, &QLineEdit::editingFinished,
this, &CDbCountrySelectorComponent::onDataChanged);
45 connect(ui->le_CountryName, &QLineEdit::returnPressed,
this, &CDbCountrySelectorComponent::onDataChanged);
49 &CDbCountrySelectorComponent::onCountriesRead, Qt::QueuedConnection);
50 this->onCountriesRead(CEntityFlags::DistributorEntity, CEntityFlags::ReadFinished,
58 ui->le_CountryIso->setText(country.
getIsoCode());
59 ui->le_CountryName->setText(country.
getName());
60 ui->lbl_CountryIcon->setPixmap(
CIcon(country.
toIcon()));
61 if (country != m_currentCountry)
63 m_currentCountry = country;
77 const QString iso(ui->le_CountryIso->text().trimmed().toUpper());
78 const QString name(ui->le_CountryName->text().trimmed());
82 if (name.isEmpty()) {
return CCountry(); }
89 ui->le_CountryIso->setReadOnly(readOnly);
90 ui->le_CountryName->setReadOnly(readOnly);
91 ui->le_CountryName->setEnabled((!readOnly));
92 ui->lbl_CountryIcon->setVisible(!readOnly);
93 this->setEnabled(!readOnly);
100 ui->le_CountryIso->clear();
101 ui->le_CountryName->clear();
102 ui->lbl_CountryIcon->setPixmap(QPixmap());
107 if (!event || !
acceptDrop(event->mimeData())) {
return; }
108 setBackgroundRole(QPalette::Highlight);
109 event->acceptProposedAction();
114 if (!event || !
acceptDrop(event->mimeData())) {
return; }
115 event->acceptProposedAction();
120 if (!event) {
return; }
126 if (!event || !
acceptDrop(event->mimeData())) {
return; }
139 if (countries.
isEmpty()) {
return; }
145 void CDbCountrySelectorComponent::onCountriesRead(CEntityFlags::Entity entity,
CEntityFlags::ReadState readState,
149 if (entity.testFlag(CEntityFlags::CountryEntity) && CEntityFlags::isFinishedReadState(readState))
154 c->setCaseSensitivity(Qt::CaseInsensitive);
155 c->setCompletionMode(QCompleter::PopupCompletion);
156 c->setMaxVisibleItems(10);
157 connect(c, qOverload<const QString &>(&QCompleter::activated),
this,
158 &CDbCountrySelectorComponent::onCompleterActivated);
160 ui->le_CountryName->setCompleter(c);
161 m_completerCountryNames.reset(c);
163 else { m_completerCountryNames.reset(
nullptr); }
167 void CDbCountrySelectorComponent::onDataChanged()
170 QObject *sender = this->sender();
171 if (sender == ui->le_CountryIso)
173 QString iso(ui->le_CountryIso->text().trimmed().toUpper());
174 if (CCountry::isValidIsoCode(iso))
179 else if (sender == ui->le_CountryName)
181 QString name(ui->le_CountryName->text().trimmed());
186 void CDbCountrySelectorComponent::onCompleterActivated(
const QString &countryName)
188 ui->le_CountryName->setText(countryName);
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::CCountryList getCountries() const
Countries.
int getCountriesCount() const
Country count.
swift::misc::CCountry getCountryForIsoCode(const QString &iso) const
Country by ISO code (GB, US...)
swift::misc::CCountry getCountryForName(const QString &name) const
Country by name (France, China ..)
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.
virtual void dragEnterEvent(QDragEnterEvent *event)
~CDbCountrySelectorComponent()
Destructor.
virtual void dragMoveEvent(QDragMoveEvent *event)
void clear()
Clear selection.
void countryChanged(const swift::misc::CCountry &country)
Country has been changed.
swift::misc::CCountry getCountry() const
Country.
void setCountry(const swift::misc::CCountry &country)
Current country.
void setReadOnly(bool readOnly)
Read only.
virtual void dropEvent(QDropEvent *event)
virtual void dragLeaveEvent(QDragLeaveEvent *event)
bool isSet() const
Set with valid country.
const QString & getName() const
Country name.
bool isValid() const
Valid?
bool hasIsoCode() const
ISO code?
const QString & getIsoCode() const
DB ISO code.
CIcons::IconIndex toIcon() const
Representing icon.
Value object encapsulating a list of countries.
QStringList toNameList(bool sorted=false) const
Name string list.
Value object for icons. An icon is stored in the global icon repository and identified by its index....
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.
ReadState
State of operation.
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.