From 3b56ff030e44c1a6ccb6fc1420b8850c00527f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Wed, 6 May 2015 08:00:29 +0000 Subject: [PATCH] remove devices from blockview git-svn-id: svn://db.shs.com.ru/libs@12 a8b55f48-bf90-11e4-a774-851b48703e85 --- qad_blockview/blockitem.cpp | 51 +------------------------------------ qad_blockview/blockitem.h | 36 +------------------------- 2 files changed, 2 insertions(+), 85 deletions(-) diff --git a/qad_blockview/blockitem.cpp b/qad_blockview/blockitem.cpp index 4101b9c..2055ab6 100644 --- a/qad_blockview/blockitem.cpp +++ b/qad_blockview/blockitem.cpp @@ -52,43 +52,6 @@ void BlockItemPin::_reparent() { } -void BlockItemPin::_updateText() { - QString p; - QMapIterator it(devices_); - while (it.hasNext()) { - it.next(); - if (!p.isEmpty()) p += "\n"; - if (it.key().isEmpty()) p += it.value().devFPath; - else p += QString("%1 = %2").arg(it.key(), it.value().devFPath); - } - text_item.setToolTip(p); - setToolTip(p); -} - - -QMap BlockItemPin::devicesPath() const { - QMap ret; - QMapIterator it(devices_); - while (it.hasNext()) { - it.next(); - if (!it.value().editable) continue; - ret[it.key()] = it.value().devFPath; - } - return ret; -} - - -void BlockItemPin::setDevicesPath(const QMap & dp) { - QMapIterator it(devices_); - while (it.hasNext()) { - it.next(); - if (!it.value().editable) continue; - if (!dp.contains(it.key())) continue; - devices_[it.key()].devFPath = dp[it.key()]; - } -} - - QVariant BlockItemPin::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant & value) { if (change == QGraphicsItem::ItemParentChange) _reparent(); @@ -112,8 +75,6 @@ void BlockItemPin::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) { } - - BlockItem::BlockItem(QGraphicsItem * parent): QGraphicsObject(parent), PropertyStorage(), g_main(this), g_selection(this) { setData(1006, "item"); @@ -329,13 +290,11 @@ void BlockItem::loadModel(const QByteArray & data) { QByteArray BlockItem::save() { ChunkStream cs; - QMap > pdp; QMap > pp; foreach (BlockItemPin * p, pins()) { - pdp[p->text()] = p->devicesPath(); pp[p->text()] = p->properties(); } - cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, props) << cs.chunk(4, pdp) << cs.chunk(5, pp); + cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, props) << cs.chunk(5, pp); return cs.data(); } @@ -343,19 +302,12 @@ QByteArray BlockItem::save() { void BlockItem::load(const QByteArray & data) { if (data.isEmpty()) return; ChunkStream cs(data); - QMap > _v; QMap > _p; while (!cs.atEnd()) { switch (cs.read()) { case 1: setPos(cs.getData()); break; case 2: setRotation(cs.getData()); break; case 3: props = cs.getData >(); break; - case 4: - _v = cs.getData > >(); - foreach (BlockItemPin * p, pins()) - if (_v.contains(p->text())) - p->setDevicesPath(_v[p->text()]); - break; case 5: _p = cs.getData > >(); foreach (BlockItemPin * p, pins()) @@ -380,7 +332,6 @@ BlockItem * BlockItem::copy() const { np->setBusType(p->busType()); np->setAlignment(p->alignment()); np->setText(p->text()); - np->setDevices(p->devices()); np->properties() = p->properties(); ret->addPin(np); } diff --git a/qad_blockview/blockitem.h b/qad_blockview/blockitem.h index e0b297a..69e2a48 100644 --- a/qad_blockview/blockitem.h +++ b/qad_blockview/blockitem.h @@ -57,13 +57,6 @@ public: InputOutput = 0x3 }; - struct Device { - Device(const QString & n = QString(), const QString & p = QString(), bool e = false) {name = n; devFPath = p; editable = e;} - QString name; - QString devFPath; - bool editable; - }; - void setPen(const QPen & p) {ell_item.setPen(p);} QPen pen() const {return ell_item.pen();} void setBrush(const QBrush & b) {ell_item.setBrush(b);} @@ -73,8 +66,6 @@ public: Qt::Alignment alignment() const {return align;} Direction direction() const {return dir;} QString text() const {return text_item.text();} - const QMap & devices() const {return devices_;} - QMap devicesPath() const; State state() const {return state_;} void setBusType(int type_) {bus_type = type_;} @@ -82,13 +73,6 @@ public: void setDirection(Direction d) {dir = d; _init(true);} void setText(const QString & t) {text_item.setText(t); _init(true);} void setState(State s) {state_ = s; setBrush(br[int(state_)]); update();} - void addDevice(const QString & name, const QString & path, bool editable = false) {devices_[name] = Device(name, path, editable); _updateText();} - void setDevicesPath(const QMap & dp); - void removeDevice(const QString & name) {devices_.remove(name); _updateText();} - void clearDevices() {devices_.clear(); _updateText();} - void setDevices(const QMap & d) {devices_ = d; _updateText();} - Device device(const QString & name) const {return devices_.value(name);} - bool isDeviceExists(const QString & name) const {return devices_.contains(name);} void saveState() {sstate_.push(state_);} bool restoreState() {if (sstate_.isEmpty()) return false; setState(sstate_.pop()); return true;} @@ -108,7 +92,6 @@ protected: void hoverLeaveEvent(QGraphicsSceneHoverEvent * e); void _init(bool affect_parent = false); void _reparent(); - void _updateText(); int bus_type; State state_; QGraphicsEllipseItem ell_item; @@ -118,7 +101,6 @@ protected: BlockItem * parent_; Qt::Alignment align; Direction dir; - QMap devices_; QBrush br[6]; }; @@ -190,7 +172,7 @@ protected: inline QDataStream & operator <<(QDataStream & s, const BlockItemPin * p) { ChunkStream cs; - cs << cs.chunk(1, int(p->alignment())) << cs.chunk(2, p->busType()) << cs.chunk(3, p->text()) << cs.chunk(4, p->devices()); + cs << cs.chunk(1, int(p->alignment())) << cs.chunk(2, p->busType()) << cs.chunk(3, p->text()); s << cs.data(); return s;} inline QDataStream & operator >>(QDataStream & s, BlockItemPin *& p) { ChunkStream cs(s); @@ -200,22 +182,6 @@ inline QDataStream & operator >>(QDataStream & s, BlockItemPin *& p) { case 1: p->setAlignment((Qt::Alignment)cs.getData()); break; case 2: p->setBusType(cs.getData()); break; case 3: p->setText(cs.getData()); break; - case 4: p->setDevices(cs.getData >()); break; - } - } - return s; -} - - -inline QDataStream & operator <<(QDataStream & s, const BlockItemPin::Device & d) { - ChunkStream cs; cs << cs.chunk(1, d.name) << cs.chunk(2, d.devFPath) << cs.chunk(3, d.editable); s << cs.data(); return s;} -inline QDataStream & operator >>(QDataStream & s, BlockItemPin::Device & d) { - ChunkStream cs(s); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: d.name = cs.getData(); break; - case 2: d.devFPath = cs.getData(); break; - case 3: d.editable = cs.getData(); break; } } return s;