git-svn-id: svn://db.shs.com.ru/libs@81 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -35,7 +35,24 @@ void SQLRecordWidget::setRecord(const QSqlRecord & q, bool full_update) {
|
||||
break;
|
||||
}
|
||||
if (val == 0) continue;
|
||||
if (qobject_cast<QLineEdit * >(val)) qobject_cast<QLineEdit * >(val)->setText(f.value().toString());
|
||||
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("");
|
||||
else {
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
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()));
|
||||
@@ -44,12 +61,12 @@ void SQLRecordWidget::setRecord(const QSqlRecord & q, bool full_update) {
|
||||
qobject_cast<StringListEdit * >(val)->setValue(s.isEmpty() ? QStringList() : s.split(";"));
|
||||
}
|
||||
if (qobject_cast<QComboBox * >(val)) {
|
||||
QList<QPair<int, QString> > & rv(relations[f.name()]);
|
||||
bool ok = false;
|
||||
int sv(f.value().toInt(&ok));
|
||||
if (!ok)
|
||||
((QComboBox*)val)->setCurrentIndex(-1);
|
||||
else {
|
||||
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);
|
||||
@@ -102,18 +119,22 @@ void SQLRecordWidget::createWidgets(const QSqlRecord & q) {
|
||||
QPair<QString, QString> ctr = trColumn(f.name());
|
||||
QWidget * val = 0;
|
||||
if (relations.contains(f.name())) {
|
||||
val = new QComboBox();
|
||||
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);
|
||||
if (ok)
|
||||
if (sv == rv[j].first)
|
||||
((QComboBox*)val)->setCurrentIndex(j);
|
||||
if (ro) {
|
||||
val = new QLineEdit();
|
||||
} else {
|
||||
val = new QComboBox();
|
||||
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);
|
||||
if (ok)
|
||||
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)) {
|
||||
case QVariant::Int:
|
||||
@@ -166,6 +187,7 @@ void SQLRecordWidget::updateWidgets() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +307,8 @@ QString SQLRecordWidget::getUpdateQuery() const {
|
||||
if (qobject_cast<StringListEdit * >(w))
|
||||
ret += "'" + qobject_cast<StringListEdit * >(w)->value().join(";") + "'";
|
||||
if (qobject_cast<QComboBox * >(w)) {
|
||||
ret += ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex(), Qt::UserRole).toString();
|
||||
QString cd = ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex(), Qt::UserRole).toString();
|
||||
ret += cd.isEmpty() ? "null" : cd;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user