EComboBox and StringListEdit improvments
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
#include "qvariantedit.h"
|
||||
#include <QDateTimeEdit>
|
||||
#include <QFileDialog>
|
||||
|
||||
|
||||
StringListEdit::~StringListEdit() {
|
||||
delete combo;
|
||||
delete butt_add;
|
||||
delete butt_del;
|
||||
delete butt_clear;
|
||||
}
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
QStringList StringListEdit::value() const {
|
||||
@@ -19,10 +12,15 @@ QStringList StringListEdit::value() const {
|
||||
|
||||
|
||||
void StringListEdit::setValue(const QStringList & v) {
|
||||
int pi = combo->currentIndex();
|
||||
combo->clear();
|
||||
if (!v.isEmpty()) {
|
||||
combo->addItems(v);
|
||||
combo->setCurrentIndex(0);
|
||||
if (pi < combo->count() && pi >= 0) {
|
||||
combo->setCurrentIndex(pi);
|
||||
} else {
|
||||
combo->setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,36 +45,44 @@ void StringListEdit::clear() {
|
||||
}
|
||||
|
||||
|
||||
StringListEdit::StringListEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRight, this) {
|
||||
StringListEdit::StringListEdit(QWidget * parent): QWidget(parent) {
|
||||
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_clear = new QPushButton(this);
|
||||
/*butt_add->setIconSize(QSize(16, 16));
|
||||
butt_del->setIconSize(QSize(16, 16));
|
||||
butt_clear->setIconSize(QSize(16, 16));*/
|
||||
butt_apply->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_add->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_del->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_clear->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_apply->setIcon(QIcon(":/icons/list-edit-apply.png"));
|
||||
butt_add->setIcon(QIcon(":/icons/list-add.png"));
|
||||
butt_del->setIcon(QIcon(":/icons/edit-delete.png"));
|
||||
butt_del->setIcon(QIcon(":/icons/list-remove.png"));
|
||||
butt_clear->setIcon(QIcon(":/icons/edit-clear.png"));
|
||||
butt_apply->setToolTip(tr("Apply"));
|
||||
butt_add->setToolTip(tr("Add"));
|
||||
butt_del->setToolTip(tr("Remove"));
|
||||
butt_clear->setToolTip(tr("Clear"));
|
||||
lay.setContentsMargins(0, 0, 0, 0);
|
||||
lay.setSpacing(2);
|
||||
lay.addWidget(combo);
|
||||
lay.addWidget(butt_add);
|
||||
lay.addWidget(butt_del);
|
||||
lay.addWidget(butt_clear);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(2);
|
||||
lay->addWidget(combo);
|
||||
lay->addWidget(butt_apply);
|
||||
lay->addWidget(butt_add);
|
||||
lay->addWidget(butt_del);
|
||||
lay->addWidget(butt_clear);
|
||||
setLayout(lay);
|
||||
connect(combo->lineEdit(), SIGNAL(returnPressed()), this, SLOT(editItem()));
|
||||
connect(combo, SIGNAL(rowsChanged()), this, SIGNAL(valueChanged()));
|
||||
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, SIGNAL(clicked(bool)), this, SLOT(clear()));
|
||||
connect(butt_clear, &QPushButton::clicked, [this](){
|
||||
if (QMessageBox::question(this, tr("Clear All"), tr("Clear All?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) clear();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +101,7 @@ void StringListEdit::editItem() {
|
||||
int ci = combo->currentIndex();
|
||||
if (ci < 0) return;
|
||||
combo->setItemText(ci, combo->currentText());
|
||||
emit valueChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -104,14 +111,11 @@ PathEdit::PathEdit(QWidget * parent): QWidget(parent), lay(QBoxLayout::LeftToRig
|
||||
is_dir = is_abs = is_save = false;
|
||||
filter = tr("All files(*)");
|
||||
line = new CLineEdit(this);
|
||||
//line->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
butt_select = new QPushButton(this);
|
||||
//butt_select->setIconSize(QSize(16, 16));
|
||||
butt_select->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
butt_select->setIcon(QIcon(":/icons/document-open.png"));
|
||||
butt_select->setToolTip(tr("Choose") + " ...");
|
||||
lay.setContentsMargins(0, 0, 0, 0);
|
||||
//lay.setSpacing(2);
|
||||
lay.addWidget(line);
|
||||
lay.addWidget(butt_select);
|
||||
connect(line, SIGNAL(textChanged(QString)), this, SIGNAL(valueChanged()));
|
||||
@@ -188,7 +192,6 @@ QVariantEdit::~QVariantEdit() {
|
||||
|
||||
|
||||
void QVariantEdit::resizeEvent(QResizeEvent * e) {
|
||||
//_resize();
|
||||
QWidget::resizeEvent(e);
|
||||
}
|
||||
|
||||
@@ -275,8 +278,6 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
case QMetaType::Double:
|
||||
#endif
|
||||
_espin = new EvalSpinBox(this);
|
||||
//_spin->setDecimals(5);
|
||||
//_spin->setRange(-1E+199, 1E+199);
|
||||
_cur_edit = _espin;
|
||||
connect(_espin, SIGNAL(valueChanged(double)), this, SLOT(_changed()));
|
||||
break;
|
||||
@@ -409,10 +410,8 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
//qDebug() << _cur_edit;
|
||||
if (_cur_edit) {
|
||||
_resize();
|
||||
//_cur_edit->show();
|
||||
}
|
||||
_value = new_value;
|
||||
}
|
||||
@@ -610,7 +609,6 @@ void QVariantEdit::_newPath() {
|
||||
_value = _value.toString();
|
||||
connect(_path, SIGNAL(valueChanged()), this, SLOT(_changed()));
|
||||
_resize();
|
||||
//_cur_edit->show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user