git-svn-id: svn://db.shs.com.ru/libs@473 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QStack>
|
||||
#include "propertystorage.h"
|
||||
#include "qad_types.h"
|
||||
|
||||
|
||||
/// data:
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <qmath.h>
|
||||
#include "blockbase.h"
|
||||
#include "alignedtextitem.h"
|
||||
#include "chunkstream.h"
|
||||
|
||||
|
||||
class BlockItem;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "propertystorage.h"
|
||||
#include <QColor>
|
||||
#include "qad_types.h"
|
||||
|
||||
|
||||
bool PropertyStorage::isPropertyExists(const QString & _name) const {
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
#ifndef PROPERTYSTORAGE_H
|
||||
#define PROPERTYSTORAGE_H
|
||||
|
||||
#include "qad_types.h"
|
||||
#include <QPointF>
|
||||
#include <QRectF>
|
||||
#include <QLineF>
|
||||
#include <QVariant>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
#include "chunkstream.h"
|
||||
|
||||
|
||||
class PropertyStorage {
|
||||
|
||||
@@ -13,8 +13,10 @@ bool __QADTypesRegistrator__::_inited = false;
|
||||
__QADTypesRegistrator__::__QADTypesRegistrator__() {
|
||||
if (_inited) return;
|
||||
_inited = true;
|
||||
|
||||
qRegisterMetaType<QAD::Enumerator>("QAD::Enumerator");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Enumerator>("QAD::Enumerator");
|
||||
|
||||
qRegisterMetaType<QAD::Enum>("QAD::Enum");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Enum>("QAD::Enum");
|
||||
|
||||
@@ -24,11 +26,15 @@ __QADTypesRegistrator__::__QADTypesRegistrator__() {
|
||||
qRegisterMetaType<QAD::Dir>("QAD::Dir");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Dir>("QAD::Dir");
|
||||
|
||||
qRegisterMetaType<QAD::IODevice>("QAD::IODevice");
|
||||
qRegisterMetaTypeStreamOperators<QAD::IODevice>("QAD::IODevice");
|
||||
|
||||
#if QT_VERSION >= 0x050200
|
||||
QMetaType::registerConverter<QAD::Enum, int>(&QAD::Enum::selectedValue);
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -131,6 +137,7 @@ QVariant::Type typeFromLetter(const QString & l) {
|
||||
if (ft == "e") return (QVariant::Type)qMetaTypeId<QAD::Enum>();
|
||||
if (ft == "F") return (QVariant::Type)qMetaTypeId<QAD::File>();
|
||||
if (ft == "D") return (QVariant::Type)qMetaTypeId<QAD::Dir>();
|
||||
if (ft == "d") return (QVariant::Type)qMetaTypeId<QAD::IODevice>();
|
||||
return QVariant::String;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
#ifndef QAD_TYPES_H
|
||||
#define QAD_TYPES_H
|
||||
|
||||
#include <QPointF>
|
||||
#include <QRectF>
|
||||
#include <QLineF>
|
||||
#include <QVariant>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
#include "chunkstream.h"
|
||||
#include "propertystorage.h"
|
||||
|
||||
|
||||
namespace QAD {
|
||||
@@ -53,6 +47,15 @@ namespace QAD {
|
||||
bool is_abs;
|
||||
};
|
||||
|
||||
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) {}
|
||||
QString prefix;
|
||||
int mode;
|
||||
int opts;
|
||||
PropertyStorage props;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::Enumerator)
|
||||
@@ -75,6 +78,31 @@ inline QDataStream & operator <<(QDataStream & s, const QAD::Dir & v) {s << v.di
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::Dir & v) {s >> v.dir >> v.is_abs; return s;}
|
||||
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;
|
||||
}
|
||||
|
||||
class __QADTypesRegistrator__ {
|
||||
public:
|
||||
__QADTypesRegistrator__();
|
||||
|
||||
72
qad/widgets/propertystorage_editor.cpp
Normal file
72
qad/widgets/propertystorage_editor.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "propertystorage_editor.h"
|
||||
#include "qvariantedit.h"
|
||||
#include <QGridLayout>
|
||||
#include <QToolButton>
|
||||
|
||||
|
||||
PropertyStorageEditor::PropertyStorageEditor(QWidget * parent): QWidget(parent) {
|
||||
setLayout(new QGridLayout());
|
||||
layout()->setContentsMargins(0, 0, 0, 0);
|
||||
storage = 0;
|
||||
}
|
||||
|
||||
|
||||
PropertyStorageEditor::~PropertyStorageEditor() {
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void PropertyStorageEditor::clear() {
|
||||
qDeleteAll(_widgets);
|
||||
_widgets.clear();
|
||||
}
|
||||
|
||||
|
||||
bool PropertyStorageEditor::isEmpty() const {
|
||||
return ((QGridLayout*)layout())->count() == 0;
|
||||
}
|
||||
|
||||
|
||||
void PropertyStorageEditor::setStorage(PropertyStorage * s) {
|
||||
clear();
|
||||
storage = s;
|
||||
if (!storage) return;
|
||||
int r = 0;
|
||||
QGridLayout * layoutProps = (QGridLayout*)layout();
|
||||
foreach (const PropertyStorage::Property & p, *storage) {
|
||||
QLabel * lbl = new QLabel(p.name);
|
||||
_widgets << lbl;
|
||||
lbl->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
|
||||
layoutProps->addWidget(lbl, r, 0);
|
||||
QVariantEdit * ve = new QVariantEdit();
|
||||
ve->setValue(p.value);
|
||||
ve->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
ve->setMinimumWidth(50);
|
||||
connect(ve, SIGNAL(valueChanged(QVariant)), this, SIGNAL(changed()));
|
||||
layoutProps->addWidget(ve, r, 1); _widgets << ve;
|
||||
lbl = new QLabel(p.comment); lbl->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
||||
layoutProps->addWidget(lbl, r, 2); _widgets << lbl;
|
||||
++r;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PropertyStorageEditor::applyProperties() {
|
||||
if (!storage) return;
|
||||
QList<PropertyStorage::Property> & props(storage->properties());
|
||||
QGridLayout * layoutProps = (QGridLayout*)layout();
|
||||
for (int r = 0; r < layoutProps->rowCount(); ++r) {
|
||||
if (layoutProps->itemAtPosition(r, 0) == 0 || layoutProps->itemAtPosition(r, 1) == 0) continue;
|
||||
QLabel * lbl = qobject_cast<QLabel * >(layoutProps->itemAtPosition(r, 0)->widget());
|
||||
QVariantEdit * ve = qobject_cast<QVariantEdit * >(layoutProps->itemAtPosition(r, 1)->widget());
|
||||
if (lbl == 0 || ve == 0) continue;
|
||||
QString pn = lbl->text();
|
||||
for (int i = 0; i < props.size(); ++i) {
|
||||
PropertyStorage::Property & p(props[i]);
|
||||
if (p.name == pn) {
|
||||
p.value = ve->value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
qad/widgets/propertystorage_editor.h
Normal file
27
qad/widgets/propertystorage_editor.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef PROPERTYSTORAGEEDITOR_H
|
||||
#define PROPERTYSTORAGEEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "propertystorage.h"
|
||||
|
||||
|
||||
class PropertyStorageEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PropertyStorageEditor(QWidget * parent = 0);
|
||||
~PropertyStorageEditor();
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
void setStorage(PropertyStorage * s);
|
||||
void applyProperties();
|
||||
|
||||
private:
|
||||
QList<QWidget*> _widgets;
|
||||
PropertyStorage * storage;
|
||||
|
||||
signals:
|
||||
void resetStorageRequest(PropertyStorage * );
|
||||
};
|
||||
|
||||
#endif // PROPERTYSTORAGEEDITOR_H
|
||||
Reference in New Issue
Block a user