code format
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "qvariantedit.h"
|
||||
|
||||
#include <QDateTimeEdit>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -6,7 +7,8 @@
|
||||
|
||||
QStringList StringListEdit::value() const {
|
||||
QStringList l;
|
||||
for (int i = 0; i < combo->count(); ++i) l << combo->itemText(i);
|
||||
for (int i = 0; i < combo->count(); ++i)
|
||||
l << combo->itemText(i);
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -46,14 +48,14 @@ void StringListEdit::clear() {
|
||||
|
||||
|
||||
StringListEdit::StringListEdit(QWidget * parent): QWidget(parent) {
|
||||
lay = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
lay = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
combo = new EComboBox(this);
|
||||
combo->setEditable(true);
|
||||
combo->setLineEdit(new CLineEdit);
|
||||
combo->setInsertPolicy(QComboBox::NoInsert);
|
||||
butt_apply = new QPushButton(this);
|
||||
butt_add = new QPushButton(this);
|
||||
butt_del = new QPushButton(this);
|
||||
butt_add = new QPushButton(this);
|
||||
butt_del = new QPushButton(this);
|
||||
butt_clear = new QPushButton(this);
|
||||
butt_apply->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_add->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
@@ -80,8 +82,9 @@ StringListEdit::StringListEdit(QWidget * parent): QWidget(parent) {
|
||||
connect(butt_apply, SIGNAL(clicked(bool)), this, SLOT(editItem()));
|
||||
connect(butt_add, SIGNAL(clicked(bool)), this, SLOT(addItem()));
|
||||
connect(butt_del, SIGNAL(clicked(bool)), this, SLOT(delItem()));
|
||||
connect(butt_clear, &QPushButton::clicked, [this](){
|
||||
if (QMessageBox::question(this, tr("Clear All"), tr("Clear All?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) clear();
|
||||
connect(butt_clear, &QPushButton::clicked, [this]() {
|
||||
if (QMessageBox::question(this, tr("Clear All"), tr("Clear All?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||
clear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,13 +108,11 @@ void StringListEdit::editItem() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PathEdit::PathEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRight, this) {
|
||||
is_dir = is_abs = is_save = false;
|
||||
filter = tr("All files(*)");
|
||||
line = new CLineEdit(this);
|
||||
butt_select = new QPushButton(this);
|
||||
filter = tr("All files(*)");
|
||||
line = new CLineEdit(this);
|
||||
butt_select = new QPushButton(this);
|
||||
butt_select->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_select->setIcon(QIcon(":/icons/document-open.png"));
|
||||
butt_select->setToolTip(tr("Choose") + " ...");
|
||||
@@ -134,7 +135,6 @@ void PathEdit::changeEvent(QEvent * e) {
|
||||
|
||||
void PathEdit::resizeEvent(QResizeEvent *) {
|
||||
butt_select->setMaximumHeight(line->height());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,8 @@ void PathEdit::setValue(const QString & v) {
|
||||
|
||||
void PathEdit::select() {
|
||||
QString ret;
|
||||
if (is_dir) ret = QFileDialog::getExistingDirectory(this, tr("Select directory"), value());
|
||||
if (is_dir)
|
||||
ret = QFileDialog::getExistingDirectory(this, tr("Select directory"), value());
|
||||
else {
|
||||
if (is_save)
|
||||
ret = QFileDialog::getSaveFileName(this, tr("Select file"), value(), filter);
|
||||
@@ -157,31 +158,28 @@ void PathEdit::select() {
|
||||
ret = QFileDialog::getOpenFileName(this, tr("Select file"), value(), filter);
|
||||
}
|
||||
if (ret.isEmpty()) return;
|
||||
if (!is_abs)
|
||||
ret = QDir::current().relativeFilePath(ret);
|
||||
if (!is_abs) ret = QDir::current().relativeFilePath(ret);
|
||||
line->setText(ret);
|
||||
emit valueChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QVariantEdit::QVariantEdit(QWidget * parent): QWidget(parent) {
|
||||
setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||
layout()->setContentsMargins(0, 0, 0, 0);
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
_custom =_cur_edit = 0;
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
_custom = _cur_edit = 0;
|
||||
_recreate(QVariant());
|
||||
}
|
||||
|
||||
@@ -277,7 +275,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::Double:
|
||||
#endif
|
||||
_espin = new EvalSpinBox(this);
|
||||
_espin = new EvalSpinBox(this);
|
||||
_cur_edit = _espin;
|
||||
connect(_espin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -296,7 +294,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QString:
|
||||
#endif
|
||||
_line = new CLineEdit(this);
|
||||
_line = new CLineEdit(this);
|
||||
_cur_edit = _line;
|
||||
connect(_line, SIGNAL(textChanged(QString)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -305,7 +303,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QStringList:
|
||||
#endif
|
||||
_list = new StringListEdit(this);
|
||||
_list = new StringListEdit(this);
|
||||
_cur_edit = _list;
|
||||
connect(_list, SIGNAL(valueChanged()), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -354,7 +352,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QDate:
|
||||
#endif
|
||||
_date = new QDateEdit(this);
|
||||
_date = new QDateEdit(this);
|
||||
_cur_edit = _date;
|
||||
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -363,7 +361,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QTime:
|
||||
#endif
|
||||
_date = new QTimeEdit(this);
|
||||
_date = new QTimeEdit(this);
|
||||
_cur_edit = _date;
|
||||
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -372,7 +370,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
#else
|
||||
case QMetaType::QDateTime:
|
||||
#endif
|
||||
_date = new QDateTimeEdit(this);
|
||||
_date = new QDateTimeEdit(this);
|
||||
_cur_edit = _date;
|
||||
connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -403,7 +401,7 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
QWidget * fw = f->createEditor();
|
||||
if (fw) {
|
||||
fw->setParent(this);
|
||||
_custom = fw;
|
||||
_custom = fw;
|
||||
_cur_edit = _custom;
|
||||
connect(_custom, SIGNAL(valueChanged()), this, SLOT(_changed()));
|
||||
}
|
||||
@@ -525,15 +523,15 @@ QVariant QVariantEdit::value() const {
|
||||
for (int i = 0; i < _enum->count(); ++i)
|
||||
ret.enum_list << QAD::Enumerator(_enum->itemData(i).toInt(), _enum->itemText(i));
|
||||
ret.enum_name = _enum->property("enum_name").toString();
|
||||
ret.selected = _enum->currentText();
|
||||
ret.selected = _enum->currentText();
|
||||
return QVariant::fromValue<QAD::Enum>(ret);
|
||||
}
|
||||
if (_value.canConvert<QAD::File>() && _path) {
|
||||
if (!_path->is_dir) {
|
||||
QAD::File ret;
|
||||
ret.file = _path->value();
|
||||
ret.filter = _path->filter;
|
||||
ret.is_abs = _path->is_abs;
|
||||
ret.file = _path->value();
|
||||
ret.filter = _path->filter;
|
||||
ret.is_abs = _path->is_abs;
|
||||
ret.is_save = _path->is_save;
|
||||
return QVariant::fromValue<QAD::File>(ret);
|
||||
}
|
||||
@@ -541,7 +539,7 @@ QVariant QVariantEdit::value() const {
|
||||
if (_value.canConvert<QAD::Dir>() && _path) {
|
||||
if (_path->is_dir) {
|
||||
QAD::Dir ret;
|
||||
ret.dir = _path->value();
|
||||
ret.dir = _path->value();
|
||||
ret.is_abs = _path->is_abs;
|
||||
return QVariant::fromValue<QAD::Dir>(ret);
|
||||
}
|
||||
@@ -557,42 +555,66 @@ QVariant QVariantEdit::value() const {
|
||||
void QVariantEdit::setValue(const QVariant & v) {
|
||||
_recreate(v);
|
||||
if (_cur_edit) _cur_edit->blockSignals(true);
|
||||
if (_line) {_line->setText(v.toString());}
|
||||
if (_check) {_check->setChecked(v.toBool()); _check->setText(v.toBool() ? "true" : "false");}
|
||||
if (_color) {_color->setColor(v.value<QColor>());}
|
||||
if (_list) {_list->setValue(v.toStringList());}
|
||||
if (_date) {_date->setDateTime(v.toDateTime());}
|
||||
if (_spin) {_spin->setValue(v.toDouble());}
|
||||
if (_espin) {_espin->setValue(v.toDouble());}
|
||||
if (_rect) {_rect->setValue(v.toRectF());}
|
||||
if (_point) {_point->setValue(v.toPointF());}
|
||||
if (_path) {
|
||||
if (_path->is_dir) _setDir(v.value<QAD::Dir>());
|
||||
else _setFile(v.value<QAD::File>());
|
||||
if (_line) {
|
||||
_line->setText(v.toString());
|
||||
}
|
||||
if (_check) {
|
||||
_check->setChecked(v.toBool());
|
||||
_check->setText(v.toBool() ? "true" : "false");
|
||||
}
|
||||
if (_color) {
|
||||
_color->setColor(v.value<QColor>());
|
||||
}
|
||||
if (_list) {
|
||||
_list->setValue(v.toStringList());
|
||||
}
|
||||
if (_date) {
|
||||
_date->setDateTime(v.toDateTime());
|
||||
}
|
||||
if (_spin) {
|
||||
_spin->setValue(v.toDouble());
|
||||
}
|
||||
if (_espin) {
|
||||
_espin->setValue(v.toDouble());
|
||||
}
|
||||
if (_rect) {
|
||||
_rect->setValue(v.toRectF());
|
||||
}
|
||||
if (_point) {
|
||||
_point->setValue(v.toPointF());
|
||||
}
|
||||
if (_path) {
|
||||
if (_path->is_dir)
|
||||
_setDir(v.value<QAD::Dir>());
|
||||
else
|
||||
_setFile(v.value<QAD::File>());
|
||||
}
|
||||
if (_enum) {
|
||||
_setEnum(v.value<QAD::Enum>());
|
||||
}
|
||||
if (_custom) {
|
||||
_setCustom(v);
|
||||
}
|
||||
if (_enum) {_setEnum(v.value<QAD::Enum>());}
|
||||
if (_custom) {_setCustom(v);}
|
||||
if (_cur_edit) _cur_edit->blockSignals(false);
|
||||
}
|
||||
|
||||
|
||||
void QVariantEdit::_delete() {
|
||||
if (_cur_edit)
|
||||
delete _cur_edit;
|
||||
if (_cur_edit) delete _cur_edit;
|
||||
_cur_edit = 0;
|
||||
_custom = 0;
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
_custom = 0;
|
||||
_empty = 0;
|
||||
_line = 0;
|
||||
_check = 0;
|
||||
_color = 0;
|
||||
_list = 0;
|
||||
_date = 0;
|
||||
_spin = 0;
|
||||
_espin = 0;
|
||||
_rect = 0;
|
||||
_point = 0;
|
||||
_path = 0;
|
||||
_enum = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -604,9 +626,9 @@ void QVariantEdit::_resize() {
|
||||
|
||||
void QVariantEdit::_newPath() {
|
||||
_delete();
|
||||
_path = new PathEdit(this);
|
||||
_path = new PathEdit(this);
|
||||
_cur_edit = _path;
|
||||
_value = _value.toString();
|
||||
_value = _value.toString();
|
||||
connect(_path, SIGNAL(valueChanged()), this, SLOT(_changed()));
|
||||
_resize();
|
||||
}
|
||||
@@ -615,7 +637,7 @@ void QVariantEdit::_newPath() {
|
||||
void QVariantEdit::_setEnum(const QAD::Enum & v) {
|
||||
_enum->clear();
|
||||
_enum->setProperty("enum_name", v.enum_name);
|
||||
foreach (const QAD::Enumerator & e, v.enum_list)
|
||||
foreach(const QAD::Enumerator & e, v.enum_list)
|
||||
_enum->addItem(e.name, QVariant(e.value));
|
||||
int i(0);
|
||||
for (i = 0; i < _enum->count(); ++i)
|
||||
@@ -623,18 +645,16 @@ void QVariantEdit::_setEnum(const QAD::Enum & v) {
|
||||
_enum->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
if (i == _enum->count())
|
||||
_enum->setCurrentIndex(-1);
|
||||
if (i == _enum->count()) _enum->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
|
||||
void QVariantEdit::_setFile(const QAD::File & v) {
|
||||
_path->is_dir = false;
|
||||
_path->is_dir = false;
|
||||
_path->filter = v.filter;
|
||||
_path->is_abs = v.is_abs;
|
||||
_path->is_save = v.is_save;
|
||||
_path->setValue(v.file);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -654,4 +674,3 @@ void QVariantEdit::_changed() {
|
||||
if (_check) _check->setText(_check->isChecked() ? "true" : "false");
|
||||
emit valueChanged(value());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user