Added support for binding simple data to combo boxes. (not tested)
This commit is contained in:
@@ -8,10 +8,12 @@
|
|||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
#include "iform.h"
|
#include "iform.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
#include "ivalidator.h"
|
#include "ivalidator.h"
|
||||||
|
#include "combodata.h"
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -48,6 +50,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void registerBinding(QComboBox *combo, const QList<ComboData> &values) {
|
||||||
|
m_bindCombos[combo] = values;
|
||||||
|
}
|
||||||
|
|
||||||
void registerValidator(IValidator *validator) {
|
void registerValidator(IValidator *validator) {
|
||||||
m_validators.append(validator);
|
m_validators.append(validator);
|
||||||
}
|
}
|
||||||
@@ -60,6 +66,7 @@ private:
|
|||||||
QSharedPointer<T> m_entity;
|
QSharedPointer<T> m_entity;
|
||||||
QList<QWidget*> m_bindWidgets;
|
QList<QWidget*> m_bindWidgets;
|
||||||
QList<IValidator*> m_validators;
|
QList<IValidator*> m_validators;
|
||||||
|
QHash<QComboBox*, QList<ComboData> > m_bindCombos;
|
||||||
bool m_newRec;
|
bool m_newRec;
|
||||||
|
|
||||||
void bindToUi() {
|
void bindToUi() {
|
||||||
@@ -67,6 +74,24 @@ private:
|
|||||||
const char* prop = widget->metaObject()->userProperty().name();
|
const char* prop = widget->metaObject()->userProperty().name();
|
||||||
widget->setProperty(prop, ((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()));
|
widget->setProperty(prop, ((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
||||||
|
int idx = 0;
|
||||||
|
QVariant field = ((QObject*)m_entity.data())->property(combo->objectName().toStdString().c_str());
|
||||||
|
|
||||||
|
combo->clear();
|
||||||
|
for (int i = 0; i < m_bindCombos[combo].size(); i++) {
|
||||||
|
ComboData data = m_bindCombos[combo][i];
|
||||||
|
combo->addItem(data.label(), data.index());
|
||||||
|
|
||||||
|
if (field == data.index()) {
|
||||||
|
idx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
combo->setCurrentIndex(idx);
|
||||||
|
}
|
||||||
|
|
||||||
bindOtherToUi();
|
bindOtherToUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +108,10 @@ private:
|
|||||||
((QObject*)m_entity.data())->setProperty(widget->objectName().toStdString().c_str(), widget->property(prop));
|
((QObject*)m_entity.data())->setProperty(widget->objectName().toStdString().c_str(), widget->property(prop));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
||||||
|
((QObject*)m_entity.data())->setProperty(combo->objectName().toStdString().c_str(), combo->currentData());
|
||||||
|
}
|
||||||
|
|
||||||
return bindOtherToData();
|
return bindOtherToData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include "combodata.h"
|
||||||
|
|
||||||
|
ComboData::ComboData(const QVariant &index, const QString &label)
|
||||||
|
{
|
||||||
|
m_index = index;
|
||||||
|
m_label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
ComboData::~ComboData()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
QVariant ComboData::index() const
|
||||||
|
{
|
||||||
|
return m_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboData::setIndex(const QVariant &index)
|
||||||
|
{
|
||||||
|
m_index = index;
|
||||||
|
}
|
||||||
|
QString ComboData::label() const
|
||||||
|
{
|
||||||
|
return m_label;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboData::setLabel(const QString &label)
|
||||||
|
{
|
||||||
|
m_label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef COMBODATA_H
|
||||||
|
#define COMBODATA_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "core_global.h"
|
||||||
|
|
||||||
|
class CORESHARED_EXPORT ComboData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ComboData(const QVariant &index, const QString &label);
|
||||||
|
~ComboData();
|
||||||
|
|
||||||
|
QVariant index() const;
|
||||||
|
void setIndex(const QVariant &index);
|
||||||
|
|
||||||
|
QString label() const;
|
||||||
|
void setLabel(const QString &label);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariant m_index;
|
||||||
|
QString m_label;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COMBODATA_H
|
||||||
+3
-3
@@ -49,7 +49,7 @@ void Context::loadPlugins()
|
|||||||
m_plugins.append(new Users);
|
m_plugins.append(new Users);
|
||||||
m_plugins.append(new Roles);
|
m_plugins.append(new Roles);
|
||||||
|
|
||||||
QDir pluginsDir(qApp->applicationDirPath() + "/../plugins");
|
QDir pluginsDir(qApp->applicationDirPath() + "/../../plugins");
|
||||||
|
|
||||||
foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) {
|
foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) {
|
||||||
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
||||||
@@ -96,10 +96,10 @@ void Context::destroy()
|
|||||||
m_dbOpened = false;
|
m_dbOpened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_settings != NULL && m_settings->parent() == NULL)
|
/*if (m_settings != NULL && m_settings->parent() == NULL)
|
||||||
{
|
{
|
||||||
delete m_settings;
|
delete m_settings;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
foreach (IPlugin *plugin, m_plugins)
|
foreach (IPlugin *plugin, m_plugins)
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-2
@@ -43,7 +43,8 @@ SOURCES += \
|
|||||||
savefilterdialog.cpp \
|
savefilterdialog.cpp \
|
||||||
filterdialog.cpp \
|
filterdialog.cpp \
|
||||||
itablemodel.cpp \
|
itablemodel.cpp \
|
||||||
iservice.cpp
|
iservice.cpp \
|
||||||
|
combodata.cpp
|
||||||
|
|
||||||
HEADERS += core.h\
|
HEADERS += core.h\
|
||||||
core_global.h \
|
core_global.h \
|
||||||
@@ -84,7 +85,8 @@ HEADERS += core.h\
|
|||||||
filterdialog.h \
|
filterdialog.h \
|
||||||
itablemodel.h \
|
itablemodel.h \
|
||||||
data/core_global.h \
|
data/core_global.h \
|
||||||
iservice.h
|
iservice.h \
|
||||||
|
combodata.h
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
target.path = /usr/lib
|
target.path = /usr/lib
|
||||||
|
|||||||
Reference in New Issue
Block a user