version 2.22.0
blockview small code clean add PIValueTree to BLockItem, BlockItemPin and BlockBusItem add QAD::CursorOverrider::restore() fix QCodeEdit escape key while block selection
This commit is contained in:
@@ -3,8 +3,8 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
||||
project(QAD)
|
||||
set(QAD_MAJOR 2)
|
||||
set(QAD_MINOR 21)
|
||||
set(QAD_REVISION 1)
|
||||
set(QAD_MINOR 22)
|
||||
set(QAD_REVISION 0)
|
||||
set(QAD_SUFFIX )
|
||||
set(QAD_COMPANY SHS)
|
||||
set(QAD_DOMAIN org.SHS)
|
||||
|
||||
@@ -1 +1 @@
|
||||
qad_library(blockview "Gui;Widgets" "qad_widgets")
|
||||
qad_library(blockview "Gui;Widgets" "qad_widgets;qad_piqt")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "blockview.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <piqt.h>
|
||||
|
||||
|
||||
BlockBusItem::BlockBusItem(bool temp): QGraphicsObject(), PropertyStorage() {
|
||||
@@ -369,8 +370,9 @@ void BlockBusItem::clearBusState() {
|
||||
|
||||
QByteArray BlockBusItem::save() const {
|
||||
ChunkStream cs;
|
||||
cs << cs.chunk(1, busType()) << cs.chunk(2, busName()) << cs.chunk(3, width()) << cs.chunk(4, pen()) << cs.chunk(5, brush())
|
||||
<< cs.chunk(6, pol) << cs.chunk(7, segments) << cs.chunk(8, props) << cs.chunk(9, im_bus_scale) << cs.chunk(10, im_end_scale);
|
||||
cs.add(1, busType()).add(2, busName()).add(3, width()).add(4, pen()).add(5, brush());
|
||||
cs.add(6, pol).add(7, segments).add(8, props).add(9, im_bus_scale).add(10, im_end_scale);
|
||||
cs.add(11, piqSerialize(value_tree));
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
@@ -391,6 +393,7 @@ void BlockBusItem::load(const QByteArray & data) {
|
||||
case 8: props = cs.getData<QList<BlockItem::Property>>(); break;
|
||||
case 9: im_bus_scale = cs.getData<double>(); break;
|
||||
case 10: im_end_scale = cs.getData<double>(); break;
|
||||
case 11: value_tree = piqDeserialize<PIValueTree>(cs.getData<QByteArray>()); break;
|
||||
}
|
||||
}
|
||||
updateGeometry();
|
||||
|
||||
@@ -110,6 +110,8 @@ public:
|
||||
void saveState();
|
||||
void restoreState();
|
||||
|
||||
PIValueTree & values() { return value_tree; }
|
||||
|
||||
enum {
|
||||
Type = UserType + 2
|
||||
};
|
||||
@@ -151,6 +153,7 @@ protected:
|
||||
QImage im_bus, im_end;
|
||||
QPolygonF pol, bpol, pol_s;
|
||||
Qt::KeyboardModifiers mm_mods;
|
||||
PIValueTree value_tree;
|
||||
bool temp_, square_node;
|
||||
double pen_width, grid_step, im_bus_scale, im_end_scale;
|
||||
int selPoint, selSegment, max_ep, bus_type, state_;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "blockview.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <piqt.h>
|
||||
|
||||
|
||||
#define BLOCKITEM_DEFAULT_PIN_MARGIN 20
|
||||
@@ -59,7 +60,7 @@ void BlockItem::_resize(QSizeF s) {
|
||||
void BlockItem::_moveToTop(bool only_decors) {
|
||||
qreal dy = -g_main.rect().center().y() + 10;
|
||||
if (!only_decors) moveBy(0., dy);
|
||||
foreach(QGraphicsItem * d, decors_)
|
||||
for (QGraphicsItem * d: decors_)
|
||||
d->moveBy(0., -dy);
|
||||
}
|
||||
|
||||
@@ -153,7 +154,7 @@ void BlockItem::clearDecors() {
|
||||
bool pbs = false;
|
||||
if (scene()) pbs = scene()->blockSignals(true);
|
||||
if (scene()) {
|
||||
foreach(QGraphicsItem * i, decors_)
|
||||
for (QGraphicsItem * i: decors_)
|
||||
scene()->sendEvent(i, new QGraphicsSceneEvent(QEvent::Close));
|
||||
}
|
||||
qDeleteAll(decors_);
|
||||
@@ -217,12 +218,12 @@ void BlockItem::loadModel(const QByteArray & data) {
|
||||
case 4: setColor(cs.getData<QColor>()); break;
|
||||
case 5:
|
||||
cs.get(tp);
|
||||
foreach(BlockItemPin * p, tp)
|
||||
for (BlockItemPin * p: tp)
|
||||
addPin(p);
|
||||
break;
|
||||
case 6:
|
||||
cs.get(dl);
|
||||
foreach(QGraphicsItem * d, dl)
|
||||
for (QGraphicsItem * d: dl)
|
||||
addDecor(d);
|
||||
break;
|
||||
case 7: setPinsMargin(cs.getData<int>()); break;
|
||||
@@ -240,12 +241,13 @@ void BlockItem::loadModel(const QByteArray & data) {
|
||||
QByteArray BlockItem::save() const {
|
||||
ChunkStream cs;
|
||||
QMap<QString, QList<BlockItem::Property>> pp;
|
||||
foreach(BlockItemPin * p, pins()) {
|
||||
for (BlockItemPin * p: pins()) {
|
||||
// qDebug() << "save pin" << p->text() << "->" << p->properties().size();
|
||||
pp[p->text()] = p->properties();
|
||||
}
|
||||
cs.add(1, pos()).add(2, rotation()).add(3, props).add(5, pp).add(6, size());
|
||||
cs.add(10, data(2000)).add(11, data(2001)).add(12, prop_bindings).add(0xFF, _blockitem_current_version_);
|
||||
cs.add(13, piqSerialize(value_tree));
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
@@ -254,6 +256,7 @@ void BlockItem::load(const QByteArray & data) {
|
||||
if (data.isEmpty()) return;
|
||||
ChunkStream cs(data);
|
||||
QMap<QString, QList<BlockItem::Property>> _p;
|
||||
value_tree = {};
|
||||
int version = -1;
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
@@ -263,7 +266,7 @@ void BlockItem::load(const QByteArray & data) {
|
||||
case 5:
|
||||
cs.get(_p);
|
||||
// qDebug() << "load pins" << _p.size();
|
||||
foreach(BlockItemPin * p, pins()) {
|
||||
for (BlockItemPin * p: pins()) {
|
||||
// qDebug() << "load pin" << p->text() << "->" << _p.contains(p->text());
|
||||
if (_p.contains(p->text())) p->properties() = _p[p->text()];
|
||||
}
|
||||
@@ -272,6 +275,7 @@ void BlockItem::load(const QByteArray & data) {
|
||||
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 13: value_tree = piqDeserialize<PIValueTree>(cs.getData<QByteArray>()); break;
|
||||
case 0xFF: cs.get(version); break;
|
||||
}
|
||||
}
|
||||
@@ -290,7 +294,7 @@ BlockItem * BlockItem::copy() const {
|
||||
ret->props = props;
|
||||
ret->setPinsMargin(pinsMargin());
|
||||
QVector<BlockItemPin *> mp = pins();
|
||||
foreach(BlockItemPin * p, mp) {
|
||||
for (BlockItemPin * p: mp) {
|
||||
BlockItemPin * np = new BlockItemPin();
|
||||
np->setBusType(p->busType());
|
||||
np->setAlignment(p->alignment());
|
||||
@@ -309,14 +313,14 @@ BlockItem * BlockItem::copy() const {
|
||||
|
||||
QList<BlockBusItem *> BlockItem::connectedBuses() const {
|
||||
QList<BlockBusItem *> ret;
|
||||
foreach(BlockItemPin * p, pins())
|
||||
for (BlockItemPin * p: pins())
|
||||
ret << p->connectedBuses();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
BlockItemPin * BlockItem::pinByText(const QString & t) const {
|
||||
foreach(BlockItemPin * p, pins())
|
||||
for (BlockItemPin * p: pins())
|
||||
if (p->text() == t) return p;
|
||||
return 0;
|
||||
}
|
||||
@@ -324,17 +328,38 @@ BlockItemPin * BlockItem::pinByText(const QString & t) const {
|
||||
|
||||
BlockItemPin * BlockItem::pinAtBus(BlockBusItem * bus) const {
|
||||
if (bus == 0) return 0;
|
||||
foreach(BlockItemPin * p, pins())
|
||||
for (BlockItemPin * p: pins())
|
||||
if (p->connectedBuses().contains(bus)) return p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BlockItem::setColor(QColor c) {
|
||||
col = c;
|
||||
_resize(size());
|
||||
}
|
||||
|
||||
|
||||
QRectF BlockItem::sceneRect() const {
|
||||
return g_main.mapRectToScene(g_main.boundingRect());
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::setWidth(qreal w) {
|
||||
setSize(QSizeF(w, size().height()));
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::setHeight(qreal h) {
|
||||
setSize(QSizeF(size().width(), h));
|
||||
}
|
||||
|
||||
|
||||
void BlockItem::setPinsMargin(int marg) {
|
||||
if (marg > 1 && marg < 256) pins_margin = marg;
|
||||
arrangePins();
|
||||
}
|
||||
|
||||
|
||||
QRectF BlockItem::boundingRect() const {
|
||||
return g_main.mapRectToParent(g_main.boundingRect());
|
||||
}
|
||||
@@ -357,7 +382,7 @@ void BlockItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
void BlockItem::arrangePins() {
|
||||
QVector<BlockItemPin *> pl = pins();
|
||||
pins_.clear();
|
||||
foreach(BlockItemPin * p, pl)
|
||||
for (BlockItemPin * p: pl)
|
||||
pins_[p->alignment()] << p;
|
||||
QVector<BlockItemPin *> cp = pins_.value(Qt::AlignBottom);
|
||||
for (int i = 0; i < cp.size(); ++i)
|
||||
@@ -525,3 +550,28 @@ QRectF BlockItem::selectionRect() const {
|
||||
void BlockItem::setSelectionRect(const QRectF & r) {
|
||||
g_selection.setRect(r);
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator<<(QDataStream & s, const BlockItemPin * p) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, int(p->alignment())).add(2, p->busType()).add(3, p->text()).add(4, p->toolTip());
|
||||
cs.add(5, piqSerialize(p->value_tree));
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator>>(QDataStream & s, BlockItemPin *& p) {
|
||||
ChunkStream cs(s);
|
||||
p = new BlockItemPin();
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: p->setAlignment((Qt::Alignment)cs.getData<int>()); break;
|
||||
case 2: p->setBusType(cs.getData<int>()); break;
|
||||
case 3: p->setText(cs.getData<QString>()); break;
|
||||
case 4: p->setToolTip(cs.getData<QString>()); break;
|
||||
case 5: p->value_tree = piqDeserialize<PIValueTree>(cs.getData<QByteArray>()); break;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "qad_blockview_export.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <pivaluetree.h>
|
||||
|
||||
|
||||
class QAD_BLOCKVIEW_EXPORT BlockItem
|
||||
@@ -58,10 +59,7 @@ public:
|
||||
BlockItemPin * pinByText(const QString & t) const;
|
||||
BlockItemPin * pinAtBus(BlockBusItem * bus) const;
|
||||
QColor color() const { return col; }
|
||||
void setColor(QColor c) {
|
||||
col = c;
|
||||
_resize(size());
|
||||
}
|
||||
void setColor(QColor c);
|
||||
QSizeF size() const { return g_main.rect().size(); }
|
||||
QRectF sceneRect() const;
|
||||
qreal width() const { return size().width(); }
|
||||
@@ -69,12 +67,9 @@ public:
|
||||
int pinsMargin() const { return pins_margin; }
|
||||
void setSize(QSizeF s) { _resize(s); }
|
||||
void setSize(qreal w, qreal h) { setSize(QSizeF(w, h)); }
|
||||
void setWidth(qreal w) { setSize(QSizeF(w, size().height())); }
|
||||
void setHeight(qreal h) { setSize(QSizeF(size().width(), h)); }
|
||||
void setPinsMargin(int marg) {
|
||||
if (marg > 1 && marg < 256) pins_margin = marg;
|
||||
arrangePins();
|
||||
}
|
||||
void setWidth(qreal w);
|
||||
void setHeight(qreal h);
|
||||
void setPinsMargin(int marg);
|
||||
|
||||
QByteArray saveModel();
|
||||
void loadModel(const QByteArray & data);
|
||||
@@ -93,6 +88,8 @@ public:
|
||||
QStringList getBindNames() const;
|
||||
QStringList getBindProps() const;
|
||||
|
||||
PIValueTree & values() { return value_tree; }
|
||||
|
||||
enum {
|
||||
Type = UserType + 1
|
||||
};
|
||||
@@ -128,6 +125,7 @@ private:
|
||||
|
||||
QPropertyAnimation anim_thick, anim_sel;
|
||||
QElapsedTimer t_sel;
|
||||
PIValueTree value_tree;
|
||||
bool is_hovered = false, is_blockeditor = false;
|
||||
|
||||
signals:
|
||||
@@ -136,25 +134,8 @@ signals:
|
||||
};
|
||||
|
||||
|
||||
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->toolTip());
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, BlockItemPin *& p) {
|
||||
ChunkStream cs(s);
|
||||
p = new BlockItemPin();
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: p->setAlignment((Qt::Alignment)cs.getData<int>()); break;
|
||||
case 2: p->setBusType(cs.getData<int>()); break;
|
||||
case 3: p->setText(cs.getData<QString>()); break;
|
||||
case 4: p->setToolTip(cs.getData<QString>()); break;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
QDataStream & operator<<(QDataStream & s, const BlockItemPin * p);
|
||||
QDataStream & operator>>(QDataStream & s, BlockItemPin *& p);
|
||||
|
||||
|
||||
inline QDataStream & operator<<(QDataStream & s, const BlockItem * b) {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QStack>
|
||||
#include <pivaluetree.h>
|
||||
#include <qmath.h>
|
||||
|
||||
|
||||
@@ -45,6 +46,8 @@ class QAD_BLOCKVIEW_EXPORT BlockItemPin
|
||||
, public PropertyStorage {
|
||||
friend class BlockView;
|
||||
friend class BlockItem;
|
||||
friend QDataStream & operator<<(QDataStream & s, const BlockItemPin * p);
|
||||
friend QDataStream & operator>>(QDataStream & s, BlockItemPin *& p);
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(double pinSize READ pinSize WRITE resizePin DESIGNABLE false SCRIPTABLE false)
|
||||
|
||||
@@ -92,6 +95,7 @@ public:
|
||||
|
||||
void enlargePin(bool enlarge);
|
||||
|
||||
PIValueTree & values() { return value_tree; }
|
||||
|
||||
BlockItem * parent() const { return parent_; }
|
||||
QList<BlockBusItem *> connectedBuses() const { return buses_; }
|
||||
@@ -119,6 +123,7 @@ protected:
|
||||
BlockItem * parent_;
|
||||
Qt::Alignment align;
|
||||
QBrush br[6];
|
||||
PIValueTree value_tree;
|
||||
|
||||
private slots:
|
||||
void animationAccept();
|
||||
|
||||
@@ -56,6 +56,8 @@ __QADTypesRegistrator__::__QADTypesRegistrator__() {
|
||||
__QADTypesRegistrator__ __registrator__(1);
|
||||
|
||||
|
||||
// QAD::Enum
|
||||
|
||||
QAD::Enum::Enum(const QMetaEnum & meta, int selected) {
|
||||
enum_name = meta.name();
|
||||
for (int i = 0; i < meta.keyCount(); ++i) {
|
||||
@@ -146,6 +148,8 @@ QAD::Enum & QAD::Enum::operator<<(const QStringList & v) {
|
||||
}
|
||||
|
||||
|
||||
// QAD::IODevice
|
||||
|
||||
QString QAD::IODevice::toString() const {
|
||||
QString s;
|
||||
if (__QADTypesRegistrator__::instance()->toString_funcs.contains(qMetaTypeId<QAD::IODevice>())) {
|
||||
@@ -157,6 +161,27 @@ QString QAD::IODevice::toString() const {
|
||||
}
|
||||
|
||||
|
||||
// QAD::CursorOverrider
|
||||
|
||||
QAD::CursorOverrider::CursorOverrider(const QCursor & c) {
|
||||
QApplication::setOverrideCursor(c);
|
||||
}
|
||||
|
||||
|
||||
QAD::CursorOverrider::~CursorOverrider() {
|
||||
restore();
|
||||
}
|
||||
|
||||
|
||||
void QAD::CursorOverrider::restore() {
|
||||
if (!on) return;
|
||||
on = false;
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
||||
// global
|
||||
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QVariant::Type
|
||||
#else
|
||||
|
||||
@@ -47,12 +47,14 @@ class QMetaEnum;
|
||||
|
||||
namespace QAD {
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT Enumerator {
|
||||
Enumerator(int v = 0, const QString & n = QString()): value(v), name(n) {}
|
||||
int value;
|
||||
QString name;
|
||||
};
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT Enum {
|
||||
Enum(const QString & n = QString()): enum_name(n) {}
|
||||
Enum(const QMetaEnum & meta, int selected = 0);
|
||||
@@ -73,6 +75,7 @@ struct QAD_UTILS_EXPORT Enum {
|
||||
Enum & operator<<(const QStringList & v);
|
||||
};
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT File {
|
||||
File(const QString & p = QString(), const QString & f = QString(), bool abs = false, bool save_mode = false)
|
||||
: file(p)
|
||||
@@ -86,6 +89,7 @@ struct QAD_UTILS_EXPORT File {
|
||||
bool is_save;
|
||||
};
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT Dir {
|
||||
Dir(const QString & d = QString(), bool abs = false): dir(d), is_abs(abs) {}
|
||||
QString toString() const { return dir; }
|
||||
@@ -93,6 +97,7 @@ struct QAD_UTILS_EXPORT Dir {
|
||||
bool is_abs;
|
||||
};
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT IODevice {
|
||||
IODevice(const QString & device_prefix = QString(),
|
||||
const PropertyStorage & device_properties = PropertyStorage(),
|
||||
@@ -110,22 +115,30 @@ struct QAD_UTILS_EXPORT IODevice {
|
||||
PropertyStorage props;
|
||||
};
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT MathVector {
|
||||
MathVector(const QVector<double> & vec = QVector<double>()) { v = vec; }
|
||||
QVector<double> v;
|
||||
};
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT MathMatrix {
|
||||
MathMatrix(const QVector<QVector<double>> & mat = QVector<QVector<double>>()) { m = mat; }
|
||||
QVector<QVector<double>> m; // [Row][Column]
|
||||
};
|
||||
|
||||
|
||||
class QAD_UTILS_EXPORT CursorOverrider {
|
||||
public:
|
||||
CursorOverrider(const QCursor & c = Qt::WaitCursor) { QApplication::setOverrideCursor(c); }
|
||||
~CursorOverrider() { QApplication::restoreOverrideCursor(); }
|
||||
CursorOverrider(const QCursor & c = Qt::WaitCursor);
|
||||
~CursorOverrider();
|
||||
void restore();
|
||||
|
||||
private:
|
||||
bool on = true;
|
||||
};
|
||||
|
||||
|
||||
} // namespace QAD
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::Enumerator)
|
||||
|
||||
@@ -608,8 +608,15 @@ bool QCodeEdit::codeKeyEvent(QKeyEvent * ke) {
|
||||
hideHelp();
|
||||
if (completer->isVisible()) {
|
||||
completer->hide();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
if (hasBlockSelection()) {
|
||||
cancelBlockSelection();
|
||||
return true;
|
||||
}
|
||||
if (ui->widgetSearch->isVisible()) {
|
||||
hideSearch();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case Qt::Key_Up:
|
||||
|
||||
Reference in New Issue
Block a user