r22909 by jghali - Some refactoring for node edit related code
scribus-commit
scribus-commit at lists.scribus.net
Thu Mar 21 17:37:28 UTC 2019
Author: jghali
Date: Thu Mar 21 17:37:28 2019
New Revision: 22909
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22909
Log:
Some refactoring for node edit related code
Modified:
trunk/Scribus/scribus/canvasmode.cpp
trunk/Scribus/scribus/canvasmode_nodeedit.cpp
trunk/Scribus/scribus/nodeeditcontext.cpp
trunk/Scribus/scribus/nodeeditcontext.h
trunk/Scribus/scribus/ui/nodeeditpalette.cpp
Modified: trunk/Scribus/scribus/canvasmode.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22909&path=/trunk/Scribus/scribus/canvasmode.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode.cpp (original)
+++ trunk/Scribus/scribus/canvasmode.cpp Thu Mar 21 17:37:28 2019
@@ -1338,15 +1338,16 @@
if ((m_doc->appMode == modeEditClip) && (m_doc->nodeEdit.hasNodeSelected()))
{
int storedClRe = m_doc->nodeEdit.clre();
- if ((m_doc->nodeEdit.selNode().count() != 0) && (m_doc->nodeEdit.edPoints()))
+ const auto& nodeSelection = m_doc->nodeEdit.selNode();
+ if ((nodeSelection.count() != 0) && (m_doc->nodeEdit.edPoints()))
{
QPolygonF poly;
if ((currItem->imageFlippedH() && (!m_doc->nodeEdit.isContourLine())) && (currItem->isSymbol() || currItem->isGroup()))
moveBy *= -1;
- for (int itm = 0; itm < m_doc->nodeEdit.selNode().count(); ++itm)
+ for (int itm = 0; itm < nodeSelection.count(); ++itm)
{
FPoint np;
- int clRe = m_doc->nodeEdit.selNode().at(itm);
+ int clRe = nodeSelection.at(itm);
if (m_doc->nodeEdit.isContourLine())
np = currItem->ContourLine.point(clRe);
else
@@ -1428,15 +1429,16 @@
if ((m_doc->appMode == modeEditClip) && (m_doc->nodeEdit.hasNodeSelected()))
{
int storedClRe = m_doc->nodeEdit.clre();
- if ((m_doc->nodeEdit.selNode().count() != 0) && (m_doc->nodeEdit.edPoints()))
+ const auto& nodeSelection = m_doc->nodeEdit.selNode();
+ if ((nodeSelection.count() != 0) && (m_doc->nodeEdit.edPoints()))
{
QPolygonF poly;
if ((currItem->imageFlippedH() && (!m_doc->nodeEdit.isContourLine())) && (currItem->isSymbol() || currItem->isGroup()))
moveBy *= -1;
- for (int itm = 0; itm < m_doc->nodeEdit.selNode().count(); ++itm)
+ for (int itm = 0; itm < nodeSelection.count(); ++itm)
{
FPoint np;
- int clRe = m_doc->nodeEdit.selNode().at(itm);
+ int clRe = nodeSelection.at(itm);
if (m_doc->nodeEdit.isContourLine())
np = currItem->ContourLine.point(clRe);
else
@@ -1518,15 +1520,16 @@
if ((m_doc->appMode == modeEditClip) && (m_doc->nodeEdit.hasNodeSelected()))
{
int storedClRe = m_doc->nodeEdit.clre();
- if ((m_doc->nodeEdit.selNode().count() != 0) && (m_doc->nodeEdit.edPoints()))
+ const auto& nodeSelection = m_doc->nodeEdit.selNode();
+ if ((nodeSelection.count() != 0) && (m_doc->nodeEdit.edPoints()))
{
QPolygonF poly;
if ((currItem->imageFlippedV() && (!m_doc->nodeEdit.isContourLine())) && (currItem->isSymbol() || currItem->isGroup()))
moveBy *= -1;
- for (int itm = 0; itm < m_doc->nodeEdit.selNode().count(); ++itm)
+ for (int itm = 0; itm < nodeSelection.count(); ++itm)
{
FPoint np;
- int clRe = m_doc->nodeEdit.selNode().at(itm);
+ int clRe = nodeSelection.at(itm);
if (m_doc->nodeEdit.isContourLine())
np = currItem->ContourLine.point(clRe);
else
@@ -1608,15 +1611,16 @@
if ((m_doc->appMode == modeEditClip) && (m_doc->nodeEdit.hasNodeSelected()))
{
int storedClRe = m_doc->nodeEdit.clre();
- if ((m_doc->nodeEdit.selNode().count() != 0) && (m_doc->nodeEdit.edPoints()))
+ const auto& nodeSelection = m_doc->nodeEdit.selNode();
+ if ((nodeSelection.count() != 0) && (m_doc->nodeEdit.edPoints()))
{
QPolygonF poly;
if ((currItem->imageFlippedV() && (!m_doc->nodeEdit.isContourLine())) && (currItem->isSymbol() || currItem->isGroup()))
moveBy *= -1;
- for (int itm = 0; itm < m_doc->nodeEdit.selNode().count(); ++itm)
+ for (int itm = 0; itm < nodeSelection.count(); ++itm)
{
FPoint np;
- int clRe = m_doc->nodeEdit.selNode().at(itm);
+ int clRe = nodeSelection.at(itm);
if (m_doc->nodeEdit.isContourLine())
np = currItem->ContourLine.point(clRe);
else
Modified: trunk/Scribus/scribus/canvasmode_nodeedit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22909&path=/trunk/Scribus/scribus/canvasmode_nodeedit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_nodeedit.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_nodeedit.cpp Thu Mar 21 17:37:28 2019
@@ -151,10 +151,10 @@
p->setPen(QPen(Qt::red, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
cli.point(m_doc->nodeEdit.clre(), &x, &y);
p->drawPoint(QPointF(x, y));
- QList<int>::Iterator itm;
- for (itm = m_doc->nodeEdit.selNode().begin(); itm != m_doc->nodeEdit.selNode().end(); ++itm)
- {
- cli.point((*itm), &x, &y);
+ const auto& selectedNodes = m_doc->nodeEdit.selNode();
+ for (int i = 0; i < selectedNodes.count(); ++i)
+ {
+ cli.point(i, &x, &y);
p->drawPoint(QPointF(x, y));
}
}
@@ -203,21 +203,20 @@
}
}
}
- for (int a = 0; a < Clip.size(); ++a)
- {
- if (Clip.isMarker(a))
+ for (int i = 0; i < Clip.size(); ++i)
+ {
+ if (Clip.isMarker(i))
continue;
- const FPoint& np = Clip.point(a);
+ const FPoint& np = Clip.point(i);
FPoint npf2 = np.transformPoint(pm2, false);
- if ((Sele.contains(npf2.x(), npf2.y())) && ((a == 0) || (((a-2) % 4) == 0)))
- {
- if (a == 0)
+ if ((Sele.contains(npf2.x(), npf2.y())) && ((i == 0) || (((i - 2) % 4) == 0)))
+ {
+ if (i == 0)
firstPoint = true;
- if ((firstPoint) && (a == Clip.size() - 2) && (!currItem->asPolyLine()))
+ if ((firstPoint) && (i == Clip.size() - 2) && (!currItem->asPolyLine()))
continue;
- m_doc->nodeEdit.setClre(a);
- m_doc->nodeEdit.selNode().append(a);
- m_doc->nodeEdit.update(Clip.pointQF(a));
+ m_doc->nodeEdit.selectNode(i);
+ m_doc->nodeEdit.update(Clip.pointQF(i));
}
}
currItem->update();
@@ -419,7 +418,7 @@
ScItemState<QPair<FPointArray, FPointArray> > *state = nullptr;
state = m_doc->nodeEdit.finishTransaction1(currItem);
- if (m_doc->nodeEdit.hasNodeSelected() && (m_doc->nodeEdit.selNode().count() == 1))
+ if (m_doc->nodeEdit.hasNodeSelected() && (m_doc->nodeEdit.selectionCount() == 1))
{
//FIXME:av
FPoint newP = m_canvas->globalToCanvas(m->globalPos());
@@ -541,7 +540,7 @@
{
if (m->modifiers() != Qt::ShiftModifier)
m_doc->nodeEdit.selNode().clear();
- m_doc->nodeEdit.selNode().append(i);
+ m_doc->nodeEdit.selectNode(i);
}
m_doc->nodeEdit.update(Clip.pointQF(i));
pfound = true;
@@ -946,7 +945,7 @@
currItem->update();
m_view->DrawNew();
}
- if ((m_doc->nodeEdit.selNode().count() != 0) || ((m_doc->nodeEdit.segP1() != -1) && (m_doc->nodeEdit.segP2() != -1)) || (m_doc->nodeEdit.hasNodeSelected() && (!m_doc->nodeEdit.edPoints())))
+ if ((m_doc->nodeEdit.selectionCount() != 0) || ((m_doc->nodeEdit.segP1() != -1) && (m_doc->nodeEdit.segP2() != -1)) || (m_doc->nodeEdit.hasNodeSelected() && (!m_doc->nodeEdit.edPoints())))
{
m_Mxp = m->x();
m_Myp = m->y();
@@ -1100,10 +1099,10 @@
}
else
{
- if ((m_doc->nodeEdit.selNode().count() != 0) && (m_doc->nodeEdit.edPoints()))
+ if ((m_doc->nodeEdit.selectionCount() != 0) && (m_doc->nodeEdit.edPoints()))
{
int storedClRe = m_doc->nodeEdit.clre();
- if (m_doc->nodeEdit.selNode().count() == 1)
+ if (m_doc->nodeEdit.selectionCount() == 1)
{
npf = m_canvas->globalToCanvas(m->globalPos());
double nx = npf.x();
@@ -1192,9 +1191,10 @@
if (currItem->imageFlippedV())
np.setY(np.y() * -1);
}
- for (int itm = 0; itm < m_doc->nodeEdit.selNode().count(); ++itm)
- {
- m_doc->nodeEdit.setClre(m_doc->nodeEdit.selNode().at(itm));
+ const auto& nodeSelection = m_doc->nodeEdit.selNode();
+ for (int itm = 0; itm < nodeSelection.count(); ++itm)
+ {
+ m_doc->nodeEdit.setClre(nodeSelection.at(itm));
if (m_doc->nodeEdit.isContourLine())
npf = currItem->ContourLine.point(m_doc->nodeEdit.clre()) + np;
else
Modified: trunk/Scribus/scribus/nodeeditcontext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22909&path=/trunk/Scribus/scribus/nodeeditcontext.cpp
==============================================================================
--- trunk/Scribus/scribus/nodeeditcontext.cpp (original)
+++ trunk/Scribus/scribus/nodeeditcontext.cpp Thu Mar 21 17:37:28 2019
@@ -21,7 +21,7 @@
{
}
-bool NodeEditContext::hasNodeSelected()
+bool NodeEditContext::hasNodeSelected() const
{
return m_ClRe != -1;
}
@@ -31,6 +31,17 @@
{
m_ClRe = -1;
m_SelNode.clear();
+}
+
+void NodeEditContext::selectNode(int i)
+{
+ m_ClRe = i;
+ m_SelNode.append(i);
+}
+
+int NodeEditContext::selectionCount() const
+{
+ return m_SelNode.count();
}
void NodeEditContext::reset()
Modified: trunk/Scribus/scribus/nodeeditcontext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22909&path=/trunk/Scribus/scribus/nodeeditcontext.h
==============================================================================
--- trunk/Scribus/scribus/nodeeditcontext.h (original)
+++ trunk/Scribus/scribus/nodeeditcontext.h Thu Mar 21 17:37:28 2019
@@ -40,6 +40,7 @@
{
public:
NodeEditContext();
+
bool isContourLine() { return m_isContourLine; }
void setIsContourLine(bool b) { m_isContourLine = b; }
int clre() { return m_ClRe; }
@@ -54,9 +55,13 @@
void setEdPoints(bool b) { m_EdPoints = b; }
bool moveSym() { return m_MoveSym; }
void setMoveSym(bool b) { m_MoveSym = b; }
+
QList<int>& selNode() { return m_SelNode; }
- bool hasNodeSelected();
+ bool hasNodeSelected() const;
void deselect();
+ void selectNode(int i);
+ int selectionCount() const;
+
void reset();
void setPreviewMode(bool mode);
bool previewMode() { return m_preview; }
Modified: trunk/Scribus/scribus/ui/nodeeditpalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22909&path=/trunk/Scribus/scribus/ui/nodeeditpalette.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/nodeeditpalette.cpp (original)
+++ trunk/Scribus/scribus/ui/nodeeditpalette.cpp Thu Mar 21 17:37:28 2019
@@ -11,7 +11,7 @@
#include "pageitem.h"
#include "scpage.h"
#include "scribusdoc.h"
-#include "scribusview.h"
+#include "scribusview.h"
#include "selection.h"
#include "undomanager.h"
#include "undostate.h"
@@ -684,7 +684,7 @@
Clip = m_doc->m_Selection->itemAt(0)->ContourLine;
else
Clip = m_doc->m_Selection->itemAt(0)->PoLine;
- if (m_doc->nodeEdit.selNode().count() != 0)
+ if (m_doc->nodeEdit.selectionCount() != 0)
np = Clip.point(m_doc->nodeEdit.selNode().at(0));
if (AbsMode->isChecked())
{
@@ -765,7 +765,7 @@
if (m_doc == nullptr)
return;
bool setter = have;
- if (m_doc->nodeEdit.selNode().count() > 1)
+ if (m_doc->nodeEdit.selectionCount() > 1)
{
XSpin->setEnabled(false);
YSpin->setEnabled(false);
More information about the scribus-commit
mailing list