Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Rework KoSvgTextNodeEditor to KoSvgTextNodeIndex.

Wolthera van Hövell tot Westerflier037cb69ae0d4
diff --git a/libs/flake/resources/KoCssStylePreset.cpp b/libs/flake/resources/KoCssStylePreset.cpp
index c605a81001..45d8b02799 100644
--- a/libs/flake/resources/KoCssStylePreset.cpp
+++ b/libs/flake/resources/KoCssStylePreset.cpp
@@ -422,10 +422,10 @@ bool KoCssStylePreset::loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP re
if (textShape) {
setName(textShape->additionalAttribute(TITLE));
addMetaData(DESCRIPTION, textShape->additionalAttribute(DESC));
- KoSvgTextNodeEditorSP node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::KraTextStyleType);
+ KoSvgTextNodeIndex node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::KraTextStyleType);
QString styleType = STYLE_TYPE_PARAGRAPH;
- if (node->properties()) {
- KoSvgTextProperties props = *(node->properties());
+ if (node.properties()) {
+ KoSvgTextProperties props = *(node.properties());
styleType = props.property(KoSvgTextProperties::KraTextStyleType).toString();
if (props.hasProperty(KoSvgTextProperties::KraTextStyleResolution)) {
addMetaData(STORED_PPI, props.property(KoSvgTextProperties::KraTextStyleResolution));
@@ -436,7 +436,7 @@ bool KoCssStylePreset::loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP re
}
setProperties(props);
- QPair<int, int> pos = textShape->findRangeForNodeEditor(node);
+ QPair<int, int> pos = textShape->findRangeForNodeIndex(node);
pos.first = textShape->indexForPos(pos.first);
pos.second = textShape->indexForPos(pos.second);
diff --git a/libs/flake/tests/TestSvgText.cpp b/libs/flake/tests/TestSvgText.cpp
index 22fdcbe544..f73bab9976 100644
--- a/libs/flake/tests/TestSvgText.cpp
+++ b/libs/flake/tests/TestSvgText.cpp
@@ -3146,9 +3146,9 @@ void TestSvgText::testSearchingTreeIndex()
KoSvgTextShapeMarkupConverter converter(textShape);
converter.convertFromSvg(ref, QString(), QRectF(0, 0, 300, 300), 72.0);
- KoSvgTextNodeEditorSP node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::FontStyleId);
+ KoSvgTextNodeIndex node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::FontStyleId);
- QVERIFY(node->properties());
+ QVERIFY(node.properties());
}
/**
@@ -3163,8 +3163,8 @@ void TestSvgText::testRangeForTreeIndex()
KoSvgTextShapeMarkupConverter converter(textShape);
converter.convertFromSvg(ref, QString(), QRectF(0, 0, 300, 300), 72.0);
- KoSvgTextNodeEditorSP node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::FontStyleId);
- QPair<int, int> range = textShape->findRangeForNodeEditor(node);
+ KoSvgTextNodeIndex node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::FontStyleId);
+ QPair<int, int> range = textShape->findRangeForNodeIndex(node);
QCOMPARE(range.first, 10);
QCOMPARE(range.second, 15);
@@ -3182,15 +3182,15 @@ void TestSvgText::testSetPropertiesOnTreeIndex()
KoSvgTextShapeMarkupConverter converter(textShape);
converter.convertFromSvg(ref, QString(), QRectF(0, 0, 300, 300), 72.0);
- KoSvgTextNodeEditorSP node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::FontStyleId);
+ KoSvgTextNodeIndex node = textShape->findNodeEditorForPropertyId(KoSvgTextProperties::FontStyleId);
- QVERIFY(node->properties()->hasProperty(KoSvgTextProperties::FontStyleId));
+ QVERIFY(node.properties()->hasProperty(KoSvgTextProperties::FontStyleId));
- node->properties()->setProperty(KoSvgTextProperties::FontWeightId, 700);
- node->properties()->removeProperty(KoSvgTextProperties::FontStyleId);
+ node.properties()->setProperty(KoSvgTextProperties::FontWeightId, 700);
+ node.properties()->removeProperty(KoSvgTextProperties::FontStyleId);
- QVERIFY(!node->properties()->hasProperty(KoSvgTextProperties::FontStyleId));
- QVERIFY(node->properties()->hasProperty(KoSvgTextProperties::FontWeightId));
+ QVERIFY(!node.properties()->hasProperty(KoSvgTextProperties::FontStyleId));
+ QVERIFY(node.properties()->hasProperty(KoSvgTextProperties::FontWeightId));
}
void TestSvgText::testInsertTransforms_data()
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 62710b9307..9265430b32 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -84,32 +84,40 @@ private:
QPointF initialTextPosition = QPointF();
};
-class KoSvgTextNodeEditorImpl: public KoSvgTextNodeEditor
+struct KoSvgTextNodeIndex::Private {
+ Private(KisForest<KoSvgTextContentElement>::child_iterator _textElement)
+ :textElement(_textElement) {}
+ KisForest<KoSvgTextContentElement>::child_iterator textElement;
+};
+
+KoSvgTextNodeIndex::KoSvgTextNodeIndex(KisForest<KoSvgTextContentElement>::child_iterator textElement)
+ : d(new Private(textElement))
{
-public:
- KoSvgTextNodeEditorImpl(
- KisForest<KoSvgTextContentElement>::child_iterator textElement)
- : KoSvgTextNodeEditor()
- ,m_textElement(textElement) {}
- ~KoSvgTextNodeEditorImpl() {}
+}
- KoSvgTextProperties *properties() override {
- return &m_textElement->properties;
- }
+KoSvgTextNodeIndex::KoSvgTextNodeIndex(const KoSvgTextNodeIndex &rhs)
+{
+ d->textElement = rhs.d->textElement;
+}
- KoSvgText::TextOnPathInfo *textPathInfo() override {
- return &m_textElement->textPathInfo;
- }
+KoSvgTextNodeIndex::~KoSvgTextNodeIndex() {
+
+}
+
+KoSvgTextProperties *KoSvgTextNodeIndex::properties(){
+ return &d->textElement->properties;
+}
+
+KoSvgText::TextOnPathInfo *KoSvgTextNodeIndex::textPathInfo() {
+ return &d->textElement->textPathInfo;
+}
+
+KoShape *KoSvgTextNodeIndex::textPath() {
+ // TODO: implement this properly in the text-in-shape branch.
+ return nullptr;
+}
- KoShape *textPath() override {
- // TODO: implement this properly in the text-in-shape branch.
- return nullptr;
- }
-private:
- friend class KoSvgTextShape;
- KisForest<KoSvgTextContentElement>::child_iterator m_textElement;
-};
KoSvgTextShape::KoSvgTextShape()
: KoShape()
@@ -1098,32 +1106,29 @@ KisForest<KoSvgTextContentElement>::child_iterator findNodeEditorForPropertyIdIm
return parent;
}
-KoSvgTextNodeEditorSP KoSvgTextShape::findNodeEditorForPropertyId(KoSvgTextProperties::PropertyId propertyId)
+KoSvgTextNodeIndex KoSvgTextShape::findNodeEditorForPropertyId(KoSvgTextProperties::PropertyId propertyId)
{
for (auto it = d->textData.childBegin(); it != d->textData.childEnd(); it++) {
if (it->properties.hasProperty(propertyId)) {
- return KoSvgTextNodeEditorSP(new KoSvgTextNodeEditorImpl(it));
+ return KoSvgTextNodeIndex(it);
} else if (KisForestDetail::childBegin(it) != KisForestDetail::childEnd(it)) {
auto found = findNodeEditorForPropertyIdImpl(it, propertyId);
if (found != it) {
- return KoSvgTextNodeEditorSP(new KoSvgTextNodeEditorImpl(found));
+ return KoSvgTextNodeIndex(found);
}
}
}
- return KoSvgTextNodeEditorSP(new KoSvgTextNodeEditorImpl(d->textData.childBegin()));
+ return KoSvgTextNodeIndex(d->textData.childBegin());
}
-QPair<int, int> KoSvgTextShape::findRangeForNodeEditor(KoSvgTextNodeEditorSP node) const
+QPair<int, int> KoSvgTextShape::findRangeForNodeIndex(const KoSvgTextNodeIndex &node) const
{
- KoSvgTextNodeEditorImpl *nodeImpl = dynamic_cast<KoSvgTextNodeEditorImpl*>(node.data());
- if (!nodeImpl) return qMakePair(-1, -1);
-
int startIndex = 0;
int endIndex = 0;
for (auto child = d->textData.childBegin(); child != d->textData.childEnd(); child++) {
// count children
- d->startIndexOfIterator(child, nodeImpl->m_textElement, startIndex);
- endIndex = d->numChars(nodeImpl->m_textElement) + startIndex;
+ d->startIndexOfIterator(child, node.d->textElement, startIndex);
+ endIndex = d->numChars(node.d->textElement) + startIndex;
}
return qMakePair(posForIndex(startIndex), posForIndex(endIndex));
}
diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.h
index a1c580d267..f1d2af6e8b 100644
--- a/libs/flake/text/KoSvgTextShape.h
+++ b/libs/flake/text/KoSvgTextShape.h
@@ -18,9 +18,8 @@
#include <QFlags>
class KoSvgTextShapeMemento;
-class KoSvgTextNodeEditor;
+class KoSvgTextNodeIndex;
typedef QSharedPointer<KoSvgTextShapeMemento> KoSvgTextShapeMementoSP;
-typedef QSharedPointer<KoSvgTextNodeEditor> KoSvgTextNodeEditorSP;
#define KoSvgTextShape_SHAPEID "KoSvgTextShapeID"
/**
@@ -390,7 +389,7 @@ public:
* @return the nodeEditor of the first content element found with a given property id.
* @propertyId -- id to search for.
*/
- KoSvgTextNodeEditorSP findNodeEditorForPropertyId(KoSvgTextProperties::PropertyId propertyId);
+ KoSvgTextNodeIndex findNodeEditorForPropertyId(KoSvgTextProperties::PropertyId propertyId);
/**
* @brief findRangeForNodeEditor
@@ -399,7 +398,7 @@ public:
* @return A QPair<int,int> describing cursor position range encompassed by the tree index and it's children.
* Will return {-1, -1} when the tree index is invalid.
*/
- QPair<int, int> findRangeForNodeEditor(KoSvgTextNodeEditorSP node) const;
+ QPair<int, int> findRangeForNodeIndex(const KoSvgTextNodeIndex &node) const;
/*--------------- Properties ---------------*/
@@ -565,33 +564,39 @@ private:
* allow the direct editing of properties or any
* text path on the given node.
*/
-class KRITAFLAKE_EXPORT KoSvgTextNodeEditor {
+#include <KisForest.h>
+class KoSvgTextContentElement;
+class KRITAFLAKE_EXPORT KoSvgTextNodeIndex {
public:
- KoSvgTextNodeEditor () {}
- virtual ~KoSvgTextNodeEditor() {}
+ KoSvgTextNodeIndex (KisForest<KoSvgTextContentElement>::child_iterator textElement);
+ KoSvgTextNodeIndex(const KoSvgTextNodeIndex &rhs);
+ ~KoSvgTextNodeIndex();
/**
* @brief properties
* The properties for this node as a pointer.
* @return properties for this node.
*/
- virtual KoSvgTextProperties *properties() {return nullptr;}
+ KoSvgTextProperties *properties();
/**
* @brief textPathInfo
* the text path info for this node as a pointer.
* @return the current text path info.
*/
- virtual KoSvgText::TextOnPathInfo *textPathInfo() {return nullptr;}
+ KoSvgText::TextOnPathInfo *textPathInfo();
/**
* @brief textPath
* @return the textPath of this node, may be null.
*/
- virtual KoShape *textPath() {return nullptr;}
+ KoShape *textPath();
private:
friend class KoSvgTextShape;
+ struct Private;
+ QScopedPointer<Private> d;
+
};
class KoSvgTextShapeFactory : public KoShapeFactoryBase