remove devices from blockview
git-svn-id: svn://db.shs.com.ru/libs@12 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -52,43 +52,6 @@ void BlockItemPin::_reparent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockItemPin::_updateText() {
|
|
||||||
QString p;
|
|
||||||
QMapIterator<QString, Device> 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<QString, QString> BlockItemPin::devicesPath() const {
|
|
||||||
QMap<QString, QString> ret;
|
|
||||||
QMapIterator<QString, Device> 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<QString, QString> & dp) {
|
|
||||||
QMapIterator<QString, Device> 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) {
|
QVariant BlockItemPin::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant & value) {
|
||||||
if (change == QGraphicsItem::ItemParentChange)
|
if (change == QGraphicsItem::ItemParentChange)
|
||||||
_reparent();
|
_reparent();
|
||||||
@@ -112,8 +75,6 @@ void BlockItemPin::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BlockItem::BlockItem(QGraphicsItem * parent): QGraphicsObject(parent), PropertyStorage(),
|
BlockItem::BlockItem(QGraphicsItem * parent): QGraphicsObject(parent), PropertyStorage(),
|
||||||
g_main(this), g_selection(this) {
|
g_main(this), g_selection(this) {
|
||||||
setData(1006, "item");
|
setData(1006, "item");
|
||||||
@@ -329,13 +290,11 @@ void BlockItem::loadModel(const QByteArray & data) {
|
|||||||
|
|
||||||
QByteArray BlockItem::save() {
|
QByteArray BlockItem::save() {
|
||||||
ChunkStream cs;
|
ChunkStream cs;
|
||||||
QMap<QString, QMap<QString, QString> > pdp;
|
|
||||||
QMap<QString, QList<BlockItem::Property> > pp;
|
QMap<QString, QList<BlockItem::Property> > pp;
|
||||||
foreach (BlockItemPin * p, pins()) {
|
foreach (BlockItemPin * p, pins()) {
|
||||||
pdp[p->text()] = p->devicesPath();
|
|
||||||
pp[p->text()] = p->properties();
|
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();
|
return cs.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,19 +302,12 @@ QByteArray BlockItem::save() {
|
|||||||
void BlockItem::load(const QByteArray & data) {
|
void BlockItem::load(const QByteArray & data) {
|
||||||
if (data.isEmpty()) return;
|
if (data.isEmpty()) return;
|
||||||
ChunkStream cs(data);
|
ChunkStream cs(data);
|
||||||
QMap<QString, QMap<QString, QString> > _v;
|
|
||||||
QMap<QString, QList<BlockItem::Property> > _p;
|
QMap<QString, QList<BlockItem::Property> > _p;
|
||||||
while (!cs.atEnd()) {
|
while (!cs.atEnd()) {
|
||||||
switch (cs.read()) {
|
switch (cs.read()) {
|
||||||
case 1: setPos(cs.getData<QPointF>()); break;
|
case 1: setPos(cs.getData<QPointF>()); break;
|
||||||
case 2: setRotation(cs.getData<qreal>()); break;
|
case 2: setRotation(cs.getData<qreal>()); break;
|
||||||
case 3: props = cs.getData<QList<BlockItem::Property> >(); break;
|
case 3: props = cs.getData<QList<BlockItem::Property> >(); break;
|
||||||
case 4:
|
|
||||||
_v = cs.getData<QMap<QString, QMap<QString, QString> > >();
|
|
||||||
foreach (BlockItemPin * p, pins())
|
|
||||||
if (_v.contains(p->text()))
|
|
||||||
p->setDevicesPath(_v[p->text()]);
|
|
||||||
break;
|
|
||||||
case 5:
|
case 5:
|
||||||
_p = cs.getData<QMap<QString, QList<BlockItem::Property> > >();
|
_p = cs.getData<QMap<QString, QList<BlockItem::Property> > >();
|
||||||
foreach (BlockItemPin * p, pins())
|
foreach (BlockItemPin * p, pins())
|
||||||
@@ -380,7 +332,6 @@ BlockItem * BlockItem::copy() const {
|
|||||||
np->setBusType(p->busType());
|
np->setBusType(p->busType());
|
||||||
np->setAlignment(p->alignment());
|
np->setAlignment(p->alignment());
|
||||||
np->setText(p->text());
|
np->setText(p->text());
|
||||||
np->setDevices(p->devices());
|
|
||||||
np->properties() = p->properties();
|
np->properties() = p->properties();
|
||||||
ret->addPin(np);
|
ret->addPin(np);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,13 +57,6 @@ public:
|
|||||||
InputOutput = 0x3
|
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);}
|
void setPen(const QPen & p) {ell_item.setPen(p);}
|
||||||
QPen pen() const {return ell_item.pen();}
|
QPen pen() const {return ell_item.pen();}
|
||||||
void setBrush(const QBrush & b) {ell_item.setBrush(b);}
|
void setBrush(const QBrush & b) {ell_item.setBrush(b);}
|
||||||
@@ -73,8 +66,6 @@ public:
|
|||||||
Qt::Alignment alignment() const {return align;}
|
Qt::Alignment alignment() const {return align;}
|
||||||
Direction direction() const {return dir;}
|
Direction direction() const {return dir;}
|
||||||
QString text() const {return text_item.text();}
|
QString text() const {return text_item.text();}
|
||||||
const QMap<QString, Device> & devices() const {return devices_;}
|
|
||||||
QMap<QString, QString> devicesPath() const;
|
|
||||||
State state() const {return state_;}
|
State state() const {return state_;}
|
||||||
|
|
||||||
void setBusType(int type_) {bus_type = type_;}
|
void setBusType(int type_) {bus_type = type_;}
|
||||||
@@ -82,13 +73,6 @@ public:
|
|||||||
void setDirection(Direction d) {dir = d; _init(true);}
|
void setDirection(Direction d) {dir = d; _init(true);}
|
||||||
void setText(const QString & t) {text_item.setText(t); _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 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<QString, QString> & dp);
|
|
||||||
void removeDevice(const QString & name) {devices_.remove(name); _updateText();}
|
|
||||||
void clearDevices() {devices_.clear(); _updateText();}
|
|
||||||
void setDevices(const QMap<QString, Device> & 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_);}
|
void saveState() {sstate_.push(state_);}
|
||||||
bool restoreState() {if (sstate_.isEmpty()) return false; setState(sstate_.pop()); return true;}
|
bool restoreState() {if (sstate_.isEmpty()) return false; setState(sstate_.pop()); return true;}
|
||||||
@@ -108,7 +92,6 @@ protected:
|
|||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent * e);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent * e);
|
||||||
void _init(bool affect_parent = false);
|
void _init(bool affect_parent = false);
|
||||||
void _reparent();
|
void _reparent();
|
||||||
void _updateText();
|
|
||||||
int bus_type;
|
int bus_type;
|
||||||
State state_;
|
State state_;
|
||||||
QGraphicsEllipseItem ell_item;
|
QGraphicsEllipseItem ell_item;
|
||||||
@@ -118,7 +101,6 @@ protected:
|
|||||||
BlockItem * parent_;
|
BlockItem * parent_;
|
||||||
Qt::Alignment align;
|
Qt::Alignment align;
|
||||||
Direction dir;
|
Direction dir;
|
||||||
QMap<QString, Device> devices_;
|
|
||||||
QBrush br[6];
|
QBrush br[6];
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -190,7 +172,7 @@ protected:
|
|||||||
|
|
||||||
inline QDataStream & operator <<(QDataStream & s, const BlockItemPin * p) {
|
inline QDataStream & operator <<(QDataStream & s, const BlockItemPin * p) {
|
||||||
ChunkStream cs;
|
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;}
|
s << cs.data(); return s;}
|
||||||
inline QDataStream & operator >>(QDataStream & s, BlockItemPin *& p) {
|
inline QDataStream & operator >>(QDataStream & s, BlockItemPin *& p) {
|
||||||
ChunkStream cs(s);
|
ChunkStream cs(s);
|
||||||
@@ -200,22 +182,6 @@ inline QDataStream & operator >>(QDataStream & s, BlockItemPin *& p) {
|
|||||||
case 1: p->setAlignment((Qt::Alignment)cs.getData<int>()); break;
|
case 1: p->setAlignment((Qt::Alignment)cs.getData<int>()); break;
|
||||||
case 2: p->setBusType(cs.getData<int>()); break;
|
case 2: p->setBusType(cs.getData<int>()); break;
|
||||||
case 3: p->setText(cs.getData<QString>()); break;
|
case 3: p->setText(cs.getData<QString>()); break;
|
||||||
case 4: p->setDevices(cs.getData<QMap<QString, BlockItemPin::Device> >()); 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<QString>(); break;
|
|
||||||
case 2: d.devFPath = cs.getData<QString>(); break;
|
|
||||||
case 3: d.editable = cs.getData<bool>(); break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
Reference in New Issue
Block a user