git-svn-id: svn://db.shs.com.ru/libs@414 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -270,7 +270,7 @@ QByteArray BlockItem::save() const {
|
||||
pp[p->text()] = p->properties();
|
||||
}
|
||||
cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, props) << cs.chunk(5, pp) << cs.chunk(6, size());
|
||||
cs << cs.chunk(10, data(2000)) << cs.chunk(11, data(2001)) << cs.chunk(0xFF, _blockitem_current_version_);
|
||||
cs << cs.chunk(10, data(2000)) << cs.chunk(11, data(2001)) << cs.chunk(12, prop_bindings) << cs.chunk(0xFF, _blockitem_current_version_);
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
@@ -297,6 +297,7 @@ void BlockItem::load(const QByteArray & data) {
|
||||
case 6: setSize(cs.getData<QSizeF>()); break;
|
||||
case 10: setData(2000, cs.getData<QVariant>()); break;
|
||||
case 11: setData(2001, cs.getData<QVariant>()); break;
|
||||
case 12: prop_bindings = cs.getData<QList<QPair<QString, QString> > >(); break;
|
||||
case 0xFF: cs.get(version); break;
|
||||
}
|
||||
}
|
||||
@@ -418,6 +419,86 @@ void BlockItem::arrangePins() {
|
||||
#undef _POS
|
||||
|
||||
|
||||
void BlockItem::removeBindings(const QString & bind_name) {
|
||||
for(int i=0; i<prop_bindings.size(); ++i) {
|
||||
if (prop_bindings[i].second == bind_name) {
|
||||
prop_bindings.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::removeBindingByProperty(const QString & prop_name) {
|
||||
for(int i=0; i<prop_bindings.size(); ++i) {
|
||||
if (prop_bindings[i].first == prop_name) {
|
||||
prop_bindings.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::addBinding(const QString & prop_name, const QString & bind_name) {
|
||||
QPair<QString, QString> pb(prop_name, bind_name);
|
||||
prop_bindings.removeAll(pb);
|
||||
prop_bindings << pb;
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::applyBinding(const QString & bind_name, const QVariant & bind_value) {
|
||||
for(int i=0; i<prop_bindings.size(); ++i) {
|
||||
if (prop_bindings[i].second == bind_name) {
|
||||
setPropertyValue(prop_bindings[i].first, bind_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::applyBindings(const PropertyStorage & bindings) {
|
||||
for(int i=0; i<prop_bindings.size(); ++i) {
|
||||
if (bindings.isPropertyExists(prop_bindings[i].second)) {
|
||||
setPropertyValue(prop_bindings[i].first, bindings.propertyValueByName(prop_bindings[i].second));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::setBindings(const QList<QPair<QString, QString> > & bindings) {
|
||||
prop_bindings = bindings;
|
||||
}
|
||||
|
||||
|
||||
QList<QPair<QString, QString> > BlockItem::getBindings() {
|
||||
return prop_bindings;
|
||||
}
|
||||
|
||||
|
||||
QString BlockItem::getBindName(const QString & prop_name) const {
|
||||
for(int i=0; i<prop_bindings.size(); ++i) {
|
||||
if (prop_bindings[i].first == prop_name) {
|
||||
return prop_bindings[i].second;
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
QStringList BlockItem::getBindNames() const {
|
||||
QStringList ret;
|
||||
for(int i=0; i<prop_bindings.size(); ++i)
|
||||
if (!ret.contains(prop_bindings[i].second)) ret << prop_bindings[i].second;
|
||||
return ret;
|
||||
}
|
||||
|
||||
QStringList BlockItem::getBindProps() const {
|
||||
QStringList ret;
|
||||
for(int i=0; i<prop_bindings.size(); ++i)
|
||||
ret << prop_bindings[i].first;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
|
||||
//if ()
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class BlockItem: public QGraphicsObject, public PropertyStorage
|
||||
public:
|
||||
BlockItem(QGraphicsItem * parent = 0);
|
||||
~BlockItem();
|
||||
|
||||
|
||||
BlockItem * copy() const;
|
||||
BlockItemPin * addPin(BlockItemPin * pin, bool update_ = true);
|
||||
BlockItemPin * addPin(Qt::Alignment align, int bus_type, const QString & text, bool update_ = true);
|
||||
@@ -61,9 +61,20 @@ public:
|
||||
QByteArray save() const;
|
||||
void load(const QByteArray & data);
|
||||
void arrangePins();
|
||||
|
||||
|
||||
void removeBindings(const QString & bind_name);
|
||||
void removeBindingByProperty(const QString & prop_name);
|
||||
void addBinding(const QString & prop_name, const QString & bind_name);
|
||||
void applyBinding(const QString & bind_name, const QVariant & bind_value);
|
||||
void applyBindings(const PropertyStorage & bindings);
|
||||
void setBindings(const QList<QPair<QString, QString> > & bindings);
|
||||
QList<QPair<QString, QString> > getBindings();
|
||||
QString getBindName(const QString & prop_name) const;
|
||||
QStringList getBindNames() const;
|
||||
QStringList getBindProps() const;
|
||||
|
||||
enum {Type = UserType + 1};
|
||||
|
||||
|
||||
protected:
|
||||
void _resize(QSizeF s);
|
||||
void _moveToTop(bool only_decors = false);
|
||||
@@ -78,13 +89,14 @@ protected:
|
||||
double bottom() const {return boundingRect().bottom();}
|
||||
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant & value);
|
||||
|
||||
|
||||
QGraphicsRectItem g_main, g_selection;
|
||||
int pins_margin;
|
||||
QColor col;
|
||||
QMap<Qt::Alignment, QVector<BlockItemPin * > > pins_;
|
||||
QList<QGraphicsItem * > decors_;
|
||||
|
||||
QList<QPair<QString, QString> > prop_bindings; // <property_name, binding_name>
|
||||
|
||||
private:
|
||||
double thickness() const;
|
||||
void setThickness(double w);
|
||||
|
||||
Reference in New Issue
Block a user