git-svn-id: svn://db.shs.com.ru/libs@475 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2018-12-19 12:45:11 +00:00
parent 9760c4b6f2
commit 5be5313214
14 changed files with 474 additions and 36 deletions

View File

@@ -34,7 +34,7 @@ __QADTypesRegistrator__::__QADTypesRegistrator__() {
QMetaType::registerConverter<QAD::Enum, QString>(&QAD::Enum::selectedName);
QMetaType::registerConverter<QAD::File, QString>(&QAD::File::toString);
QMetaType::registerConverter<QAD::Dir, QString>(&QAD::Dir::toString);
/// TDOD : //QMetaType::registerConverter<QAD::Dir, QString>(&QAD::IODevice::constructFullPath);
QMetaType::registerConverter<QAD::IODevice, QString>(&QAD::IODevice::toString);
#endif
}
@@ -122,6 +122,30 @@ QAD::Enum & QAD::Enum::operator <<(const QStringList & v) {
QString QAD::IODevice::toString() const {
QString s;
s += "IODevice(" + prefix + ", ";
int rwc = 0;
if (mode & QIODevice::ReadOnly) {s += "r"; ++rwc;}
if (mode & QIODevice::WriteOnly) {s += "w"; ++rwc;}
if (rwc == 1) s += "o";
if (options != 0) {
if (options & 1)
s += " br";
if (options & 2)
s += " bw";
}
PropertyStorage ps = props;
foreach (const PropertyStorage::Property & p, ps) {
s += ", " + p.name + "=\"" + p.value.toString() + "\"";
}
s += ")";
return s;
}
QVariant::Type typeFromLetter(const QString & l) {
if (l.isEmpty()) return QVariant::String;
QString ft = l.left(1);

View File

@@ -48,11 +48,14 @@ namespace QAD {
};
struct IODevice {
IODevice(const QString & devece_prefix = QString(), const PropertyStorage & device_properties = PropertyStorage(), int open_mode = QIODevice::ReadWrite, int device_options = 0)
: prefix(devece_prefix), mode(open_mode), opts(device_options), props(device_properties) {}
IODevice(const QString & device_prefix = QString(), const PropertyStorage & device_properties = PropertyStorage(),
int open_mode = QIODevice::ReadWrite, int device_options = 0)
: prefix(device_prefix), mode(open_mode), options(device_options), props(device_properties) {}
QString toString() const;
bool isValid() const {return !prefix.isEmpty();}
QString prefix;
int mode;
int opts;
int options;
PropertyStorage props;
};
@@ -79,29 +82,10 @@ inline QDataStream & operator >>(QDataStream & s, QAD::Dir & v) {s >> v.dir >> v
inline QDebug operator <<(QDebug s, const QAD::Dir & v) {s.nospace() << v.dir; return s.space();}
Q_DECLARE_METATYPE(QAD::IODevice)
inline QDataStream & operator <<(QDataStream & s, const QAD::IODevice & v) {s << v.prefix << v.mode << v.opts << v.props; return s;}
inline QDataStream & operator >>(QDataStream & s, QAD::IODevice & v) {s >> v.prefix >> v.mode >> v.opts >> v.props; return s;}
inline QDebug operator <<(QDebug d, const QAD::IODevice & v) {
QString s;
s += "IODevice(" + v.prefix + ", ";
int rwc = 0;
if (v.mode & QIODevice::ReadOnly) {s += "r"; ++rwc;}
if (v.mode & QIODevice::WriteOnly) {s += "w"; ++rwc;}
if (rwc == 1) s += "o";
if (v.opts != 0) {
if (v.opts & 1)
s += " br";
if (v.opts & 2)
s += " bw";
}
PropertyStorage ps = v.props;
foreach (const PropertyStorage::Property & p, ps) {
s += ", " + p.name + "=\"" + p.value.toString() + "\"";
}
s += ")";
d.noquote() << s;
return d;
}
inline QDataStream & operator <<(QDataStream & s, const QAD::IODevice & v) {s << v.prefix << v.mode << v.options << v.props; return s;}
inline QDataStream & operator >>(QDataStream & s, QAD::IODevice & v) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;}
inline QDebug operator <<(QDebug s, const QAD::IODevice & v) {s.nospace() << v.toString(); return s.space();}
class __QADTypesRegistrator__ {
public:

View File

@@ -22,6 +22,8 @@ private:
signals:
void resetStorageRequest(PropertyStorage * );
void changed();
};
#endif // PROPERTYSTORAGEEDITOR_H

View File

@@ -163,7 +163,7 @@ QVariantEdit::QVariantEdit(QWidget * parent): QWidget(parent) {
_point = 0;
_path = 0;
_enum = 0;
_cur_edit = 0;
_custom =_cur_edit = 0;
_recreate(QVariant());
}
@@ -314,6 +314,18 @@ void QVariantEdit::_recreate(const QVariant & new_value) {
_cur_edit = _path;
connect(_path, SIGNAL(valueChanged()), this, SLOT(_changed()));
}
if (!_cur_edit) { // try custom
QVariantEditorFactoryBase * f = QVariantEditorFactories::editorFactory(new_value.userType());
if (f) {
QWidget * fw = f->createEditor();
if (fw) {
fw->setParent(this);
_custom = fw;
_cur_edit = _custom;
connect(_custom, SIGNAL(valueChanged()), this, SLOT(_changed()));
}
}
}
}
//qDebug() << _cur_edit;
if (_cur_edit) {
@@ -368,6 +380,9 @@ QVariant QVariantEdit::value() const {
return QVariant::fromValue<QAD::Dir>(ret);
}
}
if (_custom) {
return _custom->property("value");
}
}
return QVariant();
}
@@ -390,6 +405,7 @@ void QVariantEdit::setValue(const QVariant & v) {
else _setFile(v.value<QAD::File>());
}
if (_enum) {_setEnum(v.value<QAD::Enum>());}
if (_custom) {_setCustom(v);}
if (_cur_edit) _cur_edit->blockSignals(false);
}
@@ -398,6 +414,7 @@ void QVariantEdit::_delete() {
if (_cur_edit)
delete _cur_edit;
_cur_edit = 0;
_custom = 0;
_empty = 0;
_line = 0;
_check = 0;
@@ -460,6 +477,12 @@ void QVariantEdit::_setDir(const QAD::Dir & v) {
_path->is_abs = v.is_abs;
}
void QVariantEdit::_setCustom(const QVariant & v) {
_custom->setProperty("value", v);
}
void QVariantEdit::_changed() {
if (_check) _check->setText(_check->isChecked() ? "true" : "false");
emit valueChanged(value());

View File

@@ -1,6 +1,7 @@
#ifndef QVARIANTEDIT_H
#define QVARIANTEDIT_H
#include "qvariantedit_custom.h"
#include "qad_types.h"
#include "clineedit.h"
#include "ecombobox.h"
@@ -102,6 +103,7 @@ protected:
void _setEnum(const QAD::Enum & v);
void _setFile(const QAD::File & v);
void _setDir(const QAD::Dir & v);
void _setCustom(const QVariant & v);
QLabel * _empty;
@@ -116,7 +118,7 @@ protected:
QPointEdit * _point;
PathEdit * _path;
EComboBox * _enum;
QWidget * _cur_edit;
QWidget * _custom, * _cur_edit;
QVariant _value;
private slots: