1
0
Fork 0

Remove canvas: handle node removes

Especially on the path, handles removes of path coord/cmd data
This commit is contained in:
James Turner 2018-09-29 15:32:16 +01:00
parent 2d348bd641
commit d0017f3bec
4 changed files with 53 additions and 17 deletions

View file

@ -207,7 +207,6 @@ void CanvasConnection::onTextMessageReceived(QString message)
if (json.isObject()) {
// process new nodes
QJsonArray created = json.object().value("created").toArray();
qInfo() << "new nodes:" << created.size();
Q_FOREACH (QJsonValue v, created) {
QJsonObject newProp = v.toObject();
@ -221,7 +220,7 @@ void CanvasConnection::onTextMessageReceived(QString message)
LocalProp* newNode = propertyFromPath(localPath);
newNode->setPosition(newProp.value("position").toInt());
// store in the global dict
unsigned int propId = newProp.value("id").toInt();
int propId = newProp.value("id").toInt();
if (idPropertyDict.contains(propId)) {
qWarning() << "duplicate add of:" << nodePath << "old is" << idPropertyDict.value(propId)->path();
} else {
@ -235,7 +234,7 @@ void CanvasConnection::onTextMessageReceived(QString message)
// process removes
QJsonArray removed = json.object().value("removed").toArray();
Q_FOREACH (QJsonValue v, removed) {
unsigned int propId = v.toInt();
int propId = v.toInt();
if (!idPropertyDict.contains(propId)) {
continue;
}
@ -261,7 +260,7 @@ void CanvasConnection::onTextMessageReceived(QString message)
continue;
}
unsigned int propId = change.at(0).toInt();
int propId = change.at(0).toInt();
if (!idPropertyDict.contains(propId)) {
qWarning() << "ignoring unknown prop ID " << propId;
continue;

View file

@ -151,7 +151,7 @@ void FGCanvasElement::polish()
_fillColor = parseColorValue(getCascadedStyle("fill"));
const auto opacity = getCascadedStyle("fill-opacity");
if (!opacity.isNull()) {
_fillColor.setAlphaF(opacity.toFloat());
_fillColor.setAlphaF(opacity.toReal());
}
_styleDirty = false;
@ -307,7 +307,7 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop)
} else if (nm == "id") {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markSVGIDDirty);
return true;
} else if (prop->name() == "update") {
} else if (nm == "update") {
// disable updates optionally?
return true;
} else if ((nm == "clip") || (nm == "clip-frame")) {
@ -320,11 +320,16 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop)
return true;
}
if (prop->name() == "layer-type") {
if (nm == "symbol-type") {
// ignored for now
return true;
}
if (nm == "layer-type") {
connect(prop, &LocalProp::valueChanged, [this](QVariant value)
{qDebug() << "layer-type:" << value.toByteArray() << "on" << _propertyRoot->path(); });
return true;
} else if (prop->name() == "z-index") {
} else if (nm == "z-index") {
connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markZIndexDirty);
return true;
}
@ -355,12 +360,12 @@ QColor FGCanvasElement::fillColor() const
void FGCanvasElement::onCenterChanged(QVariant value)
{
LocalProp* senderProp = static_cast<LocalProp*>(sender());
int centerTerm = senderProp->index();
const unsigned int centerTerm = senderProp->index();
if (centerTerm == 0) {
_center.setX(value.toFloat());
_center.setX(value.toReal());
} else {
_center.setY(value.toFloat());
_center.setY(value.toReal());
}
requestPolish();
@ -522,10 +527,10 @@ void FGCanvasElement::parseCSSClip(QByteArray value)
return;
}
const float top = parseCSSValue(clipRectDesc.at(0));
const float right = parseCSSValue(clipRectDesc.at(1));
const float bottom = parseCSSValue(clipRectDesc.at(2));
const float left = parseCSSValue(clipRectDesc.at(3));
const qreal top = parseCSSValue(clipRectDesc.at(0));
const qreal right = parseCSSValue(clipRectDesc.at(1));
const qreal bottom = parseCSSValue(clipRectDesc.at(2));
const qreal left = parseCSSValue(clipRectDesc.at(3));
_clipRect = QRectF(left, top, right - left, bottom - top);
// qDebug() << "final clip rect:" << _clipRect << "from" << value;

View file

@ -527,6 +527,37 @@ bool FGCanvasPath::onChildAdded(LocalProp *prop)
return false;
}
bool FGCanvasPath::onChildRemoved(LocalProp* prop)
{
if (FGCanvasElement::onChildRemoved(prop)) {
return true;
}
const auto name = prop->name();
if (name == "rect") {
_isRect = false;
markPathDirty();
return true;
}
if ((name == "cmd") || (name == "coord") || (name == "svg")) {
markPathDirty();
return true;
}
if ((name == "cmd-geo") || (name == "coord-geo")) {
// ignored
return true;
}
if (name.startsWith("stroke")) {
markStrokeDirty();
return true;
}
return false;
}
typedef enum
{
PathClose = ( 0 << 1),
@ -806,8 +837,8 @@ void FGCanvasPath::rebuildPathFromCommands(const std::vector<int>& commands, con
bool isRelative = cmd & 0x1;
const int op = cmd & ~0x1;
const int cmdIndex = op >> 1;
const float baseX = isRelative ? newPath.currentPosition().x() : 0.0f;
const float baseY = isRelative ? newPath.currentPosition().y() : 0.0f;
const qreal baseX = isRelative ? newPath.currentPosition().x() : 0.0f;
const qreal baseY = isRelative ? newPath.currentPosition().y() : 0.0f;
if ((currentCoord + CoordsPerCommand[cmdIndex]) > coords.size()) {
qWarning() << "insufficient path data" << currentCoord << cmdIndex << CoordsPerCommand[cmdIndex] << coords.size();

View file

@ -48,6 +48,7 @@ private:
void markStrokeDirty();
private:
bool onChildAdded(LocalProp *prop) override;
bool onChildRemoved(LocalProp* prop) override;
void rebuildPath() const;
void rebuildPen() const;