code format
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
#include "sql_record_widget.h"
|
||||
#include <qpiconfig.h>
|
||||
#include <QSqlRecord>
|
||||
#include <QSqlField>
|
||||
#include <QSqlError>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QCheckBox>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include <QSqlError>
|
||||
#include <QSqlField>
|
||||
#include <QSqlRecord>
|
||||
#include <colorbutton.h>
|
||||
#include <qpiconfig.h>
|
||||
#include <qpiconfigvaluewidget.h>
|
||||
|
||||
|
||||
@@ -20,15 +21,14 @@ SQLRecordWidget::SQLRecordWidget(QWidget * parent): QWidget(parent) {
|
||||
}
|
||||
|
||||
|
||||
SQLRecordWidget::~SQLRecordWidget() {
|
||||
}
|
||||
SQLRecordWidget::~SQLRecordWidget() {}
|
||||
|
||||
|
||||
void SQLRecordWidget::setRecord(const QSqlRecord & q, bool full_update) {
|
||||
//qDebug() << (q.count() - hidden.size()) << (layout()->count() / 2);
|
||||
// qDebug() << (q.count() - hidden.size()) << (layout()->count() / 2);
|
||||
if (full_update || (q.count() - hidden.size()) != (layout()->count() / 2)) createWidgets(q);
|
||||
for (int i = 0; i < q.count(); ++i) {
|
||||
QSqlField f = q.field(i);
|
||||
QSqlField f = q.field(i);
|
||||
QWidget * val = 0;
|
||||
for (int w = 0; w < cws.size(); ++w)
|
||||
if (cws[w]->objectName() == f.name()) {
|
||||
@@ -36,41 +36,41 @@ void SQLRecordWidget::setRecord(const QSqlRecord & q, bool full_update) {
|
||||
break;
|
||||
}
|
||||
if (val == 0) continue;
|
||||
if (qobject_cast<QLineEdit * >(val)) {
|
||||
if (qobject_cast<QLineEdit *>(val)) {
|
||||
if (relations.contains(f.name())) {
|
||||
bool ok = false;
|
||||
int sv(f.value().toInt(&ok));
|
||||
if (!ok)
|
||||
qobject_cast<QLineEdit * >(val)->setText("");
|
||||
qobject_cast<QLineEdit *>(val)->setText("");
|
||||
else {
|
||||
QList<QPair<int, QString> > & rv(relations[f.name()]);
|
||||
QList<QPair<int, QString>> & rv(relations[f.name()]);
|
||||
for (int j = 0; j < rv.size(); ++j) {
|
||||
if (sv == rv[j].first) {
|
||||
qobject_cast<QLineEdit * >(val)->setText(rv[j].second);
|
||||
qobject_cast<QLineEdit *>(val)->setText(rv[j].second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
qobject_cast<QLineEdit * >(val)->setText(f.value().toString());
|
||||
qobject_cast<QLineEdit *>(val)->setText(f.value().toString());
|
||||
}
|
||||
if (qobject_cast<QCheckBox * >(val)) qobject_cast<QCheckBox * >(val)->setChecked(f.value().toBool());
|
||||
if (qobject_cast<QDoubleSpinBox * >(val)) qobject_cast<QDoubleSpinBox * >(val)->setValue(f.value().toDouble());
|
||||
if (qobject_cast<ColorButton * >(val)) qobject_cast<ColorButton * >(val)->setColor(QColor::fromRgba(f.value().toUInt()));
|
||||
if (qobject_cast<StringListEdit * >(val)) {
|
||||
if (qobject_cast<QCheckBox *>(val)) qobject_cast<QCheckBox *>(val)->setChecked(f.value().toBool());
|
||||
if (qobject_cast<QDoubleSpinBox *>(val)) qobject_cast<QDoubleSpinBox *>(val)->setValue(f.value().toDouble());
|
||||
if (qobject_cast<ColorButton *>(val)) qobject_cast<ColorButton *>(val)->setColor(QColor::fromRgba(f.value().toUInt()));
|
||||
if (qobject_cast<StringListEdit *>(val)) {
|
||||
QString s = f.value().toString();
|
||||
qobject_cast<StringListEdit * >(val)->setValue(s.isEmpty() ? QStringList() : s.split(";"));
|
||||
qobject_cast<StringListEdit *>(val)->setValue(s.isEmpty() ? QStringList() : s.split(";"));
|
||||
}
|
||||
if (qobject_cast<QComboBox * >(val)) {
|
||||
if (qobject_cast<QComboBox *>(val)) {
|
||||
bool ok = false;
|
||||
int sv(f.value().toInt(&ok));
|
||||
if (!ok)
|
||||
((QComboBox*)val)->setCurrentIndex(-1);
|
||||
((QComboBox *)val)->setCurrentIndex(-1);
|
||||
else {
|
||||
QList<QPair<int, QString> > & rv(relations[f.name()]);
|
||||
QList<QPair<int, QString>> & rv(relations[f.name()]);
|
||||
for (int j = 0; j < rv.size(); ++j) {
|
||||
if (sv == rv[j].first) {
|
||||
((QComboBox*)val)->setCurrentIndex(j);
|
||||
((QComboBox *)val)->setCurrentIndex(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -81,25 +81,39 @@ void SQLRecordWidget::setRecord(const QSqlRecord & q, bool full_update) {
|
||||
|
||||
|
||||
void SQLRecordWidget::setFixedValue(const QString & name, const QVariant & value) {
|
||||
foreach (QWidget * w, cws) {
|
||||
foreach(QWidget * w, cws) {
|
||||
if (w->objectName() != name) continue;
|
||||
if (qobject_cast<QLineEdit * >(w)) {qobject_cast<QLineEdit * >(w)->setText(value.toString()); qobject_cast<QLineEdit * >(w)->setReadOnly(true);}
|
||||
if (qobject_cast<QCheckBox * >(w)) {qobject_cast<QCheckBox * >(w)->setChecked(value.toBool()); w->setEnabled(false);}
|
||||
if (qobject_cast<QDoubleSpinBox * >(w)) {qobject_cast<QDoubleSpinBox * >(w)->setValue(value.toDouble()); qobject_cast<QDoubleSpinBox * >(w)->setReadOnly(true);}
|
||||
if (qobject_cast<ColorButton * >(w)) {qobject_cast<ColorButton * >(w)->setColor(QColor::fromRgba(value.toUInt())); qobject_cast<ColorButton * >(w)->setEnabled(false);}
|
||||
if (qobject_cast<StringListEdit * >(w)) {qobject_cast<StringListEdit * >(w)->setValue(QStringList()); qobject_cast<StringListEdit * >(w)->setEnabled(false);}
|
||||
if (qobject_cast<QLineEdit *>(w)) {
|
||||
qobject_cast<QLineEdit *>(w)->setText(value.toString());
|
||||
qobject_cast<QLineEdit *>(w)->setReadOnly(true);
|
||||
}
|
||||
if (qobject_cast<QCheckBox *>(w)) {
|
||||
qobject_cast<QCheckBox *>(w)->setChecked(value.toBool());
|
||||
w->setEnabled(false);
|
||||
}
|
||||
if (qobject_cast<QDoubleSpinBox *>(w)) {
|
||||
qobject_cast<QDoubleSpinBox *>(w)->setValue(value.toDouble());
|
||||
qobject_cast<QDoubleSpinBox *>(w)->setReadOnly(true);
|
||||
}
|
||||
if (qobject_cast<ColorButton *>(w)) {
|
||||
qobject_cast<ColorButton *>(w)->setColor(QColor::fromRgba(value.toUInt()));
|
||||
qobject_cast<ColorButton *>(w)->setEnabled(false);
|
||||
}
|
||||
if (qobject_cast<StringListEdit *>(w)) {
|
||||
qobject_cast<StringListEdit *>(w)->setValue(QStringList());
|
||||
qobject_cast<StringListEdit *>(w)->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SQLRecordWidget::clearValues() {
|
||||
foreach (QWidget * w, cws) {
|
||||
if (qobject_cast<QLineEdit * >(w)) qobject_cast<QLineEdit * >(w)->setText(QString());
|
||||
if (qobject_cast<QCheckBox * >(w)) qobject_cast<QCheckBox * >(w)->setChecked(false);
|
||||
if (qobject_cast<QDoubleSpinBox * >(w)) qobject_cast<QDoubleSpinBox * >(w)->setValue(0.);
|
||||
if (qobject_cast<ColorButton * >(w)) qobject_cast<ColorButton * >(w)->setColor(Qt::black);
|
||||
if (qobject_cast<StringListEdit * >(w)) qobject_cast<StringListEdit * >(w)->setValue(QStringList());
|
||||
foreach(QWidget * w, cws) {
|
||||
if (qobject_cast<QLineEdit *>(w)) qobject_cast<QLineEdit *>(w)->setText(QString());
|
||||
if (qobject_cast<QCheckBox *>(w)) qobject_cast<QCheckBox *>(w)->setChecked(false);
|
||||
if (qobject_cast<QDoubleSpinBox *>(w)) qobject_cast<QDoubleSpinBox *>(w)->setValue(0.);
|
||||
if (qobject_cast<ColorButton *>(w)) qobject_cast<ColorButton *>(w)->setColor(Qt::black);
|
||||
if (qobject_cast<StringListEdit *>(w)) qobject_cast<StringListEdit *>(w)->setValue(QStringList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,28 +127,26 @@ void SQLRecordWidget::createWidgets(const QSqlRecord & q) {
|
||||
lay->setLabelAlignment(Qt::AlignRight);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(lay);
|
||||
//qDebug() << "createWidgets" << q.count();
|
||||
// qDebug() << "createWidgets" << q.count();
|
||||
for (int i = 0; i < q.count(); ++i) {
|
||||
QSqlField f = q.field(i);
|
||||
if (hidden.contains(f.name())) continue;
|
||||
QPair<QString, QString> ctr = trColumn(f.name());
|
||||
QWidget * val = 0;
|
||||
QWidget * val = 0;
|
||||
if (relations.contains(f.name())) {
|
||||
if (ro) {
|
||||
val = new QLineEdit();
|
||||
} else {
|
||||
val = new QComboBox();
|
||||
QList<QPair<int, QString> > & rv(relations[f.name()]);
|
||||
QList<QPair<int, QString>> & rv(relations[f.name()]);
|
||||
bool ok = false;
|
||||
int sv(f.value().toInt(&ok));
|
||||
for (int j = 0; j < rv.size(); ++j) {
|
||||
((QComboBox*)val)->addItem(rv[j].second, rv[j].first);
|
||||
((QComboBox *)val)->addItem(rv[j].second, rv[j].first);
|
||||
if (ok)
|
||||
if (sv == rv[j].first)
|
||||
((QComboBox*)val)->setCurrentIndex(j);
|
||||
if (sv == rv[j].first) ((QComboBox *)val)->setCurrentIndex(j);
|
||||
}
|
||||
if (!ok)
|
||||
((QComboBox*)val)->setCurrentIndex(-1);
|
||||
if (!ok) ((QComboBox *)val)->setCurrentIndex(-1);
|
||||
}
|
||||
} else {
|
||||
switch (fieldType(f)) {
|
||||
@@ -144,27 +156,25 @@ void SQLRecordWidget::createWidgets(const QSqlRecord & q) {
|
||||
case QVariant::ULongLong:
|
||||
case QVariant::Double:
|
||||
val = new QDoubleSpinBox();
|
||||
((QDoubleSpinBox*)val)->setRange(-1E+99, 1E+99);
|
||||
((QDoubleSpinBox*)val)->setDecimals(3); break;
|
||||
case QVariant::String:
|
||||
val = new QLineEdit(); break;
|
||||
case QVariant::Bool:
|
||||
val = new QCheckBox(); break;
|
||||
((QDoubleSpinBox *)val)->setRange(-1E+99, 1E+99);
|
||||
((QDoubleSpinBox *)val)->setDecimals(3);
|
||||
break;
|
||||
case QVariant::String: val = new QLineEdit(); break;
|
||||
case QVariant::Bool: val = new QCheckBox(); break;
|
||||
case QVariant::Color:
|
||||
val = new ColorButton();
|
||||
((ColorButton*)val)->setUseAlphaChannel(true);
|
||||
((ColorButton*)val)->setUseNativeDialog(true);
|
||||
break;
|
||||
case QVariant::StringList:
|
||||
val = new StringListEdit();
|
||||
((ColorButton *)val)->setUseAlphaChannel(true);
|
||||
((ColorButton *)val)->setUseNativeDialog(true);
|
||||
break;
|
||||
case QVariant::StringList: val = new StringListEdit(); break;
|
||||
default: break;
|
||||
}
|
||||
if (f.type() == QVariant::String || f.type() == QVariant::StringList) val->setProperty("_string", true);
|
||||
}
|
||||
if (val != 0) {
|
||||
QString lt = ctr.first.left(1).toUpper() + ctr.first.right(ctr.first.length() - 1);
|
||||
while (lt.endsWith("_")) lt.chop(1);
|
||||
while (lt.endsWith("_"))
|
||||
lt.chop(1);
|
||||
QLabel * lbl = new QLabel(lt + ":");
|
||||
lbl->setToolTip(ctr.second);
|
||||
cws << lbl;
|
||||
@@ -172,8 +182,7 @@ void SQLRecordWidget::createWidgets(const QSqlRecord & q) {
|
||||
cws << val;
|
||||
lay->addRow(lbl, val);
|
||||
} else {
|
||||
if (!hidden.contains(ctr.first))
|
||||
hidden << ctr.first;
|
||||
if (!hidden.contains(ctr.first)) hidden << ctr.first;
|
||||
}
|
||||
}
|
||||
updateWidgets();
|
||||
@@ -182,13 +191,13 @@ void SQLRecordWidget::createWidgets(const QSqlRecord & q) {
|
||||
|
||||
|
||||
void SQLRecordWidget::updateWidgets() {
|
||||
foreach (QWidget * w, cws) {
|
||||
if (qobject_cast<QLineEdit * >(w)) qobject_cast<QLineEdit * >(w)->setReadOnly(ro);
|
||||
if (qobject_cast<QCheckBox * >(w)) qobject_cast<QCheckBox * >(w)->setEnabled(!ro);
|
||||
if (qobject_cast<QDoubleSpinBox * >(w)) qobject_cast<QDoubleSpinBox * >(w)->setReadOnly(ro);
|
||||
if (qobject_cast<ColorButton * >(w)) qobject_cast<ColorButton * >(w)->setEnabled(!ro);
|
||||
if (qobject_cast<StringListEdit * >(w)) qobject_cast<StringListEdit * >(w)->setEnabled(!ro);
|
||||
if (qobject_cast<QComboBox * >(w)) qobject_cast<QComboBox * >(w)->setEnabled(!ro);
|
||||
foreach(QWidget * w, cws) {
|
||||
if (qobject_cast<QLineEdit *>(w)) qobject_cast<QLineEdit *>(w)->setReadOnly(ro);
|
||||
if (qobject_cast<QCheckBox *>(w)) qobject_cast<QCheckBox *>(w)->setEnabled(!ro);
|
||||
if (qobject_cast<QDoubleSpinBox *>(w)) qobject_cast<QDoubleSpinBox *>(w)->setReadOnly(ro);
|
||||
if (qobject_cast<ColorButton *>(w)) qobject_cast<ColorButton *>(w)->setEnabled(!ro);
|
||||
if (qobject_cast<StringListEdit *>(w)) qobject_cast<StringListEdit *>(w)->setEnabled(!ro);
|
||||
if (qobject_cast<QComboBox *>(w)) qobject_cast<QComboBox *>(w)->setEnabled(!ro);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +221,7 @@ QVariant::Type SQLRecordWidget::fieldType(const QSqlField & f) {
|
||||
void SQLRecordWidget::addTranslation(const QString & file) {
|
||||
QPIConfig conf(file, QIODevice::ReadOnly, QPIConfig::Config);
|
||||
QPIConfig::Branch ae = conf.allLeaves();
|
||||
foreach (QPIConfig::Entry * e, ae)
|
||||
foreach(QPIConfig::Entry * e, ae)
|
||||
translates[e->name()] = QPair<QString, QString>(e->value(), e->comment());
|
||||
}
|
||||
|
||||
@@ -220,50 +229,52 @@ void SQLRecordWidget::addTranslation(const QString & file) {
|
||||
QString SQLRecordWidget::getValuesQuery() const {
|
||||
QString ret("(");
|
||||
bool first = true;
|
||||
foreach (QWidget * w, cws) {
|
||||
foreach(QWidget * w, cws) {
|
||||
QWidget * vw(0);
|
||||
if (qobject_cast<QLineEdit * >(w)) {if (!qobject_cast<QLineEdit * >(w)->text().isEmpty()) vw = w;}
|
||||
if (qobject_cast<QCheckBox * >(w)) vw = w;
|
||||
if (qobject_cast<QDoubleSpinBox * >(w)) vw = w;
|
||||
if (qobject_cast<ColorButton * >(w)) vw = w;
|
||||
if (qobject_cast<StringListEdit * >(w)) vw = w;
|
||||
if (qobject_cast<QComboBox * >(w)) vw = w;
|
||||
if (qobject_cast<QLineEdit *>(w)) {
|
||||
if (!qobject_cast<QLineEdit *>(w)->text().isEmpty()) vw = w;
|
||||
}
|
||||
if (qobject_cast<QCheckBox *>(w)) vw = w;
|
||||
if (qobject_cast<QDoubleSpinBox *>(w)) vw = w;
|
||||
if (qobject_cast<ColorButton *>(w)) vw = w;
|
||||
if (qobject_cast<StringListEdit *>(w)) vw = w;
|
||||
if (qobject_cast<QComboBox *>(w)) vw = w;
|
||||
if (vw == 0) continue;
|
||||
if (!first) ret += ",";
|
||||
first = false;
|
||||
ret += vw->objectName();
|
||||
}
|
||||
ret += ") VALUES (";
|
||||
foreach (QWidget * w, cws) {
|
||||
foreach(QWidget * w, cws) {
|
||||
QWidget * vw(0);
|
||||
if (qobject_cast<QLineEdit * >(w)) {
|
||||
if (!qobject_cast<QLineEdit * >(w)->text().isEmpty()) {
|
||||
vw = w;
|
||||
if (qobject_cast<QLineEdit *>(w)) {
|
||||
if (!qobject_cast<QLineEdit *>(w)->text().isEmpty()) {
|
||||
vw = w;
|
||||
bool q = w->property("_string").toBool();
|
||||
if (q) ret += "'";
|
||||
ret += qobject_cast<QLineEdit * >(w)->text();
|
||||
ret += qobject_cast<QLineEdit *>(w)->text();
|
||||
if (q) ret += "'";
|
||||
}
|
||||
}
|
||||
if (qobject_cast<QCheckBox * >(w)) {
|
||||
if (qobject_cast<QCheckBox *>(w)) {
|
||||
vw = w;
|
||||
ret += qobject_cast<QCheckBox * >(w)->isChecked() ? "1" : "0";
|
||||
ret += qobject_cast<QCheckBox *>(w)->isChecked() ? "1" : "0";
|
||||
}
|
||||
if (qobject_cast<QDoubleSpinBox * >(w)) {
|
||||
if (qobject_cast<QDoubleSpinBox *>(w)) {
|
||||
vw = w;
|
||||
ret += QString::number(qobject_cast<QDoubleSpinBox * >(w)->value());
|
||||
ret += QString::number(qobject_cast<QDoubleSpinBox *>(w)->value());
|
||||
}
|
||||
if (qobject_cast<ColorButton * >(w)) {
|
||||
if (qobject_cast<ColorButton *>(w)) {
|
||||
vw = w;
|
||||
ret += QString::number(qobject_cast<ColorButton * >(w)->color().rgba());
|
||||
ret += QString::number(qobject_cast<ColorButton *>(w)->color().rgba());
|
||||
}
|
||||
if (qobject_cast<StringListEdit * >(w)) {
|
||||
if (qobject_cast<StringListEdit *>(w)) {
|
||||
vw = w;
|
||||
ret += "'" + qobject_cast<StringListEdit * >(w)->value().join(";") + "'";
|
||||
ret += "'" + qobject_cast<StringListEdit *>(w)->value().join(";") + "'";
|
||||
}
|
||||
if (qobject_cast<QComboBox * >(w)) {
|
||||
if (qobject_cast<QComboBox *>(w)) {
|
||||
vw = w;
|
||||
ret += ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex(), Qt::UserRole).toString();
|
||||
ret += ((QComboBox *)w)->itemData(((QComboBox *)w)->currentIndex(), Qt::UserRole).toString();
|
||||
}
|
||||
if (vw == 0) continue;
|
||||
ret += ",";
|
||||
@@ -277,38 +288,34 @@ QString SQLRecordWidget::getValuesQuery() const {
|
||||
QString SQLRecordWidget::getUpdateQuery() const {
|
||||
QString ret;
|
||||
bool first = true;
|
||||
foreach (QWidget * w, cws) {
|
||||
foreach(QWidget * w, cws) {
|
||||
QWidget * vw(0);
|
||||
if (qobject_cast<QLineEdit * >(w)) vw = w;
|
||||
if (qobject_cast<QCheckBox * >(w)) vw = w;
|
||||
if (qobject_cast<QDoubleSpinBox * >(w)) vw = w;
|
||||
if (qobject_cast<ColorButton * >(w)) vw = w;
|
||||
if (qobject_cast<StringListEdit * >(w)) vw = w;
|
||||
if (qobject_cast<QComboBox * >(w)) vw = w;
|
||||
if (qobject_cast<QLineEdit *>(w)) vw = w;
|
||||
if (qobject_cast<QCheckBox *>(w)) vw = w;
|
||||
if (qobject_cast<QDoubleSpinBox *>(w)) vw = w;
|
||||
if (qobject_cast<ColorButton *>(w)) vw = w;
|
||||
if (qobject_cast<StringListEdit *>(w)) vw = w;
|
||||
if (qobject_cast<QComboBox *>(w)) vw = w;
|
||||
if (vw == 0) continue;
|
||||
if (!first) ret += ",";
|
||||
first = false;
|
||||
ret += vw->objectName() + "=";
|
||||
if (qobject_cast<QLineEdit * >(w)) {
|
||||
if (qobject_cast<QLineEdit * >(w)->text().isEmpty())
|
||||
if (qobject_cast<QLineEdit *>(w)) {
|
||||
if (qobject_cast<QLineEdit *>(w)->text().isEmpty())
|
||||
ret += "null";
|
||||
else {
|
||||
bool q = w->property("_string").toBool();
|
||||
if (q) ret += "'";
|
||||
ret += qobject_cast<QLineEdit * >(w)->text();
|
||||
ret += qobject_cast<QLineEdit *>(w)->text();
|
||||
if (q) ret += "'";
|
||||
}
|
||||
}
|
||||
if (qobject_cast<QCheckBox * >(w))
|
||||
ret += qobject_cast<QCheckBox * >(w)->isChecked() ? "1" : "0";
|
||||
if (qobject_cast<QDoubleSpinBox * >(w))
|
||||
ret += QString::number(qobject_cast<QDoubleSpinBox * >(w)->value());
|
||||
if (qobject_cast<ColorButton * >(w))
|
||||
ret += QString::number(qobject_cast<ColorButton * >(w)->color().rgba());
|
||||
if (qobject_cast<StringListEdit * >(w))
|
||||
ret += "'" + qobject_cast<StringListEdit * >(w)->value().join(";") + "'";
|
||||
if (qobject_cast<QComboBox * >(w)) {
|
||||
QString cd = ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex(), Qt::UserRole).toString();
|
||||
if (qobject_cast<QCheckBox *>(w)) ret += qobject_cast<QCheckBox *>(w)->isChecked() ? "1" : "0";
|
||||
if (qobject_cast<QDoubleSpinBox *>(w)) ret += QString::number(qobject_cast<QDoubleSpinBox *>(w)->value());
|
||||
if (qobject_cast<ColorButton *>(w)) ret += QString::number(qobject_cast<ColorButton *>(w)->color().rgba());
|
||||
if (qobject_cast<StringListEdit *>(w)) ret += "'" + qobject_cast<StringListEdit *>(w)->value().join(";") + "'";
|
||||
if (qobject_cast<QComboBox *>(w)) {
|
||||
QString cd = ((QComboBox *)w)->itemData(((QComboBox *)w)->currentIndex(), Qt::UserRole).toString();
|
||||
ret += cd.isEmpty() ? "null" : cd;
|
||||
}
|
||||
}
|
||||
@@ -327,29 +334,27 @@ void SQLRecordWidget::updateRelations() {
|
||||
if (!db.isOpen()) return;
|
||||
for (int i = 0; i < relations_src.size(); ++i) {
|
||||
QSqlQuery q(QString("SELECT %1,%2 FROM %3").arg(relations_src[i].key, relations_src[i].ocol, relations_src[i].table), db);
|
||||
QList<QPair<int, QString> > cr;
|
||||
QList<QPair<int, QString>> cr;
|
||||
while (q.next())
|
||||
cr << QPair<int, QString>(q.value(0).toInt(), q.value(1).toString());
|
||||
relations[relations_src[i].tcol] = cr;
|
||||
}
|
||||
QFormLayout * lay = (QFormLayout*)layout();
|
||||
QFormLayout * lay = (QFormLayout *)layout();
|
||||
if (!lay) return;
|
||||
for (int i = 0; i < lay->rowCount(); ++i) {
|
||||
QString name = lay->itemAt(i, QFormLayout::FieldRole)->widget()->objectName();
|
||||
if (hidden.contains(name)) continue;
|
||||
QComboBox * val = qobject_cast<QComboBox*>(lay->itemAt(i, QFormLayout::FieldRole)->widget());
|
||||
QComboBox * val = qobject_cast<QComboBox *>(lay->itemAt(i, QFormLayout::FieldRole)->widget());
|
||||
if (!val) continue;
|
||||
if (!relations.contains(name)) continue;
|
||||
QList<QPair<int, QString> > & rv(relations[name]);
|
||||
QList<QPair<int, QString>> & rv(relations[name]);
|
||||
bool ok = false;
|
||||
int sv(val->itemData(val->currentIndex()).toInt());
|
||||
val->clear();
|
||||
for (int j = 0; j < rv.size(); ++j) {
|
||||
val->addItem(rv[j].second, rv[j].first);
|
||||
if (sv == rv[j].first)
|
||||
val->setCurrentIndex(j);
|
||||
if (sv == rv[j].first) val->setCurrentIndex(j);
|
||||
}
|
||||
if (!ok)
|
||||
val->setCurrentIndex(-1);
|
||||
if (!ok) val->setCurrentIndex(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user