File indexing completed on 2025-01-26 04:05:00
0001 /* 0002 * SPDX-FileCopyrightText: 2006-2010 Thomas Zander <zander@kde.org> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 #ifndef MOCKSHAPES_H 0006 #define MOCKSHAPES_H 0007 0008 #include <KoSelectedShapesProxySimple.h> 0009 #include <KoShapeGroup.h> 0010 #include <KoCanvasBase.h> 0011 #include <KoShapeControllerBase.h> 0012 #include <KoShapeContainerModel.h> 0013 #include <QPainter> 0014 #include "KoShapeManager.h" 0015 #include "FlakeDebug.h" 0016 #include "KoSnapData.h" 0017 #include "KoUnit.h" 0018 0019 #include "kritaflake_export.h" 0020 #include "kis_assert.h" 0021 0022 0023 class KRITAFLAKE_EXPORT MockShape : public KoShape 0024 { 0025 public: 0026 MockShape() : paintedCount(0) {} 0027 void paint(QPainter &painter) const override { 0028 Q_UNUSED(painter); 0029 //qDebug() << "Shape" << kBacktrace( 10 ); 0030 paintedCount++; 0031 } 0032 mutable int paintedCount; 0033 }; 0034 0035 #include <SimpleShapeContainerModel.h> 0036 0037 class KRITAFLAKE_EXPORT MockContainer : public KoShapeContainer 0038 { 0039 public: 0040 MockContainer(KoShapeContainerModel *model = new SimpleShapeContainerModel()) : KoShapeContainer(model), paintedCount(0) {} 0041 void paintComponent(QPainter &painter) const override { 0042 Q_UNUSED(painter); 0043 //qDebug() << "Container:" << kBacktrace( 10 ); 0044 paintedCount++; 0045 } 0046 0047 mutable int paintedCount; 0048 0049 bool contains(KoShape *shape) const { 0050 return shapes().contains(shape); 0051 } 0052 0053 void setAssociatedRootShapeManager(KoShapeManager *shapeManager) 0054 { 0055 SimpleShapeContainerModel *model = dynamic_cast<SimpleShapeContainerModel*>(this->model()); 0056 KIS_SAFE_ASSERT_RECOVER_RETURN(model); 0057 model->setAssociatedRootShapeManager(shapeManager); 0058 } 0059 0060 KoShapeManager* associatedRootShapeManager() const 0061 { 0062 SimpleShapeContainerModel *model = dynamic_cast<SimpleShapeContainerModel*>(this->model()); 0063 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(model, 0); 0064 return model->associatedRootShapeManager(); 0065 } 0066 0067 }; 0068 0069 class KRITAFLAKE_EXPORT MockGroup : public KoShapeGroup 0070 { 0071 void paintComponent(QPainter &painter) const override { 0072 Q_UNUSED(painter); 0073 paintedCount++; 0074 } 0075 public: 0076 bool contains(KoShape *shape) const { 0077 return shapes().contains(shape); 0078 } 0079 0080 mutable int paintedCount; 0081 }; 0082 0083 class KoToolProxy; 0084 0085 class KRITAFLAKE_EXPORT MockShapeController : public KoShapeControllerBase 0086 { 0087 public: 0088 QRectF documentRectInPixels() const override { 0089 return QRectF(0,0,100,100); 0090 } 0091 0092 qreal pixelsPerInch() const override { 0093 return 72.0; 0094 } 0095 }; 0096 0097 class KRITAFLAKE_EXPORT MockCanvas : public KoCanvasBase 0098 { 0099 Q_OBJECT 0100 public: 0101 MockCanvas(KoShapeControllerBase *aKoShapeControllerBase =0)//made for TestSnapStrategy.cpp 0102 : KoCanvasBase(aKoShapeControllerBase), 0103 m_shapeManager(new KoShapeManager(this)), 0104 m_selectedShapesProxy(new KoSelectedShapesProxySimple(m_shapeManager.data())) 0105 { 0106 } 0107 0108 ~MockCanvas() override {} 0109 void setHorz(qreal pHorz){ 0110 m_horz = pHorz; 0111 } 0112 void setVert(qreal pVert){ 0113 m_vert = pVert; 0114 } 0115 void gridSize(QPointF *offset, QSizeF *spacing) const override { 0116 Q_UNUSED(offset); 0117 0118 spacing->setWidth(m_horz); 0119 spacing->setHeight(m_vert); 0120 } 0121 bool snapToGrid() const override { 0122 return true; 0123 } 0124 void addCommand(KUndo2Command*) override { } 0125 KoShapeManager *shapeManager() const override { 0126 return m_shapeManager.data(); 0127 } 0128 KoSelectedShapesProxy *selectedShapesProxy() const override { 0129 return m_selectedShapesProxy.data(); 0130 } 0131 void updateCanvas(const QRectF&) override {} 0132 KoToolProxy * toolProxy() const override { 0133 return 0; 0134 } 0135 const KoViewConverter *viewConverter() const override { 0136 return 0; 0137 } 0138 KoViewConverter *viewConverter() override { 0139 return 0; 0140 } 0141 QWidget* canvasWidget() override { 0142 return 0; 0143 } 0144 const QWidget* canvasWidget() const override { 0145 return 0; 0146 } 0147 KoUnit unit() const override { 0148 return KoUnit(KoUnit::Millimeter); 0149 } 0150 void setCursor(const QCursor &) override {} 0151 private: 0152 QScopedPointer<KoShapeManager> m_shapeManager; 0153 QScopedPointer<KoSelectedShapesProxy> m_selectedShapesProxy; 0154 qreal m_horz; 0155 qreal m_vert; 0156 }; 0157 0158 class KRITAFLAKE_EXPORT MockContainerModel : public KoShapeContainerModel 0159 { 0160 public: 0161 MockContainerModel() { 0162 resetCounts(); 0163 } 0164 0165 /// reimplemented 0166 void add(KoShape *child) override { 0167 m_children.append(child); // note that we explicitly do not check for duplicates here! 0168 } 0169 /// reimplemented 0170 void remove(KoShape *child) override { 0171 m_children.removeAll(child); 0172 } 0173 0174 /// reimplemented 0175 void setClipped(const KoShape *, bool) override { } // ignored 0176 /// reimplemented 0177 bool isClipped(const KoShape *) const override { 0178 return false; 0179 }// ignored 0180 /// reimplemented 0181 int count() const override { 0182 return m_children.count(); 0183 } 0184 /// reimplemented 0185 QList<KoShape*> shapes() const override { 0186 return m_children; 0187 } 0188 /// reimplemented 0189 void containerChanged(KoShapeContainer *, KoShape::ChangeType) override { 0190 m_containerChangedCalled++; 0191 } 0192 /// reimplemented 0193 void proposeMove(KoShape *, QPointF &) override { 0194 m_proposeMoveCalled++; 0195 } 0196 /// reimplemented 0197 void childChanged(KoShape *, KoShape::ChangeType) override { 0198 m_childChangedCalled++; 0199 } 0200 void setInheritsTransform(const KoShape *, bool) override { 0201 } 0202 bool inheritsTransform(const KoShape *) const override { 0203 return false; 0204 } 0205 0206 int containerChangedCalled() const { 0207 return m_containerChangedCalled; 0208 } 0209 int childChangedCalled() const { 0210 return m_childChangedCalled; 0211 } 0212 int proposeMoveCalled() const { 0213 return m_proposeMoveCalled; 0214 } 0215 0216 void resetCounts() { 0217 m_containerChangedCalled = 0; 0218 m_childChangedCalled = 0; 0219 m_proposeMoveCalled = 0; 0220 } 0221 0222 private: 0223 QList<KoShape*> m_children; 0224 int m_containerChangedCalled, m_childChangedCalled, m_proposeMoveCalled; 0225 }; 0226 0227 #endif