Added support for bindig relations (foreign keys) to combo boxes.
This commit is contained in:
+8
-2
@@ -15,7 +15,6 @@
|
|||||||
#include "ivalidator.h"
|
#include "ivalidator.h"
|
||||||
#include "combodata.h"
|
#include "combodata.h"
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class AutoForm : public IForm
|
class AutoForm : public IForm
|
||||||
{
|
{
|
||||||
@@ -84,7 +83,14 @@ private:
|
|||||||
ComboData data = m_bindCombos[combo][i];
|
ComboData data = m_bindCombos[combo][i];
|
||||||
combo->addItem(data.label(), data.index());
|
combo->addItem(data.label(), data.index());
|
||||||
|
|
||||||
if (field == data.index()) {
|
if (data.index().canConvert<QObject*>()) {
|
||||||
|
ComboItem* ci = qobject_cast<ComboItem*>(data.index().value<QObject*>());
|
||||||
|
ComboItem* ciField = qobject_cast<ComboItem*>(field.value<QObject*>());
|
||||||
|
if (ci->eq(ciField)) {
|
||||||
|
idx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (field == data.index()) {
|
||||||
idx = i;
|
idx = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-4
@@ -6,10 +6,21 @@ ComboData::ComboData(const QVariant &index, const QString &label)
|
|||||||
m_label = label;
|
m_label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ComboData::ComboData(const QSharedPointer<QObject> &index)
|
||||||
|
{
|
||||||
|
m_index = QVariant::fromValue(index);
|
||||||
|
ComboItem *ci = qobject_cast<ComboItem*>(index.data());
|
||||||
|
|
||||||
|
if (ci != NULL)
|
||||||
|
{
|
||||||
|
m_label = ci->toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ComboData::~ComboData()
|
ComboData::~ComboData()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ComboData::index() const
|
QVariant ComboData::index() const
|
||||||
{
|
{
|
||||||
return m_index;
|
return m_index;
|
||||||
@@ -19,6 +30,7 @@ void ComboData::setIndex(const QVariant &index)
|
|||||||
{
|
{
|
||||||
m_index = index;
|
m_index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ComboData::label() const
|
QString ComboData::label() const
|
||||||
{
|
{
|
||||||
return m_label;
|
return m_label;
|
||||||
@@ -28,6 +40,3 @@ void ComboData::setLabel(const QString &label)
|
|||||||
{
|
{
|
||||||
m_label = label;
|
m_label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,16 @@
|
|||||||
#define COMBODATA_H
|
#define COMBODATA_H
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QSharedDataPointer>
|
||||||
|
|
||||||
#include "core_global.h"
|
#include "core_global.h"
|
||||||
|
#include "data/comboitem.h"
|
||||||
|
|
||||||
class CORESHARED_EXPORT ComboData
|
class CORESHARED_EXPORT ComboData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ComboData(const QVariant &index, const QString &label);
|
ComboData(const QVariant &index, const QString &label);
|
||||||
|
ComboData(const QSharedPointer<QObject> &index);
|
||||||
~ComboData();
|
~ComboData();
|
||||||
|
|
||||||
QVariant index() const;
|
QVariant index() const;
|
||||||
|
|||||||
@@ -8,5 +8,6 @@
|
|||||||
#include "transaction.h"
|
#include "transaction.h"
|
||||||
#include "gridform.h"
|
#include "gridform.h"
|
||||||
#include "permissionservice.h"
|
#include "permissionservice.h"
|
||||||
|
#include "combodata.h"
|
||||||
|
|
||||||
#endif // CORE_H
|
#endif // CORE_H
|
||||||
|
|||||||
+6
-2
@@ -44,7 +44,8 @@ SOURCES += \
|
|||||||
filterdialog.cpp \
|
filterdialog.cpp \
|
||||||
itablemodel.cpp \
|
itablemodel.cpp \
|
||||||
iservice.cpp \
|
iservice.cpp \
|
||||||
combodata.cpp
|
combodata.cpp \
|
||||||
|
data/comboitem.cpp
|
||||||
|
|
||||||
HEADERS += core.h\
|
HEADERS += core.h\
|
||||||
core_global.h \
|
core_global.h \
|
||||||
@@ -86,7 +87,8 @@ HEADERS += core.h\
|
|||||||
itablemodel.h \
|
itablemodel.h \
|
||||||
data/core_global.h \
|
data/core_global.h \
|
||||||
iservice.h \
|
iservice.h \
|
||||||
combodata.h
|
combodata.h \
|
||||||
|
data/comboitem.h
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
target.path = /usr/lib
|
target.path = /usr/lib
|
||||||
@@ -123,3 +125,5 @@ FORMS += \
|
|||||||
OTHER_FILES += \
|
OTHER_FILES += \
|
||||||
users/metaData.json \
|
users/metaData.json \
|
||||||
roles/metaData.json
|
roles/metaData.json
|
||||||
|
|
||||||
|
TRANSLATIONS = core_cz.ts
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include "comboitem.h"
|
||||||
|
|
||||||
|
ComboItem::ComboItem(QObject *parent)
|
||||||
|
:QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ComboItem::~ComboItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef COMBOITEM_H
|
||||||
|
#define COMBOITEM_H
|
||||||
|
|
||||||
|
#include "core_global.h"
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class CORESHARED_EXPORT ComboItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ComboItem(QObject *parent = NULL);
|
||||||
|
~ComboItem();
|
||||||
|
|
||||||
|
virtual bool eq(ComboItem *other) = 0;
|
||||||
|
virtual QString toString() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COMBOITEM_H
|
||||||
Reference in New Issue
Block a user