File indexing completed on 2024-05-05 12:57:33
0001 /* 0002 * Copyright (C) 2010-2015 by Stephen Allewell 0003 * steve.allewell@gmail.com 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 */ 0010 0011 #ifndef StitchData_H 0012 #define StitchData_H 0013 0014 #include <QList> 0015 #include <QListIterator> 0016 #include <QMap> 0017 #include <QPoint> 0018 #include <QRect> 0019 #include <QSharedDataPointer> 0020 #include <QVector> 0021 0022 #include "Stitch.h" 0023 0024 class FlossUsage 0025 { 0026 public: 0027 FlossUsage(); 0028 0029 double totalLength() const; 0030 double stitchLength() const; 0031 int totalStitches() const; 0032 int stitchCount() const; 0033 0034 QMap<Stitch::Type, int> stitchCounts; 0035 QMap<Stitch::Type, double> stitchLengths; 0036 int backstitchCount; 0037 double backstitchLength; 0038 }; 0039 0040 class StitchData 0041 { 0042 public: 0043 enum Rotation { Rotate90, Rotate180, Rotate270 }; 0044 0045 StitchData(); 0046 ~StitchData(); 0047 0048 void clear(); 0049 0050 int width() const; 0051 int height() const; 0052 0053 void resize(int, int); 0054 void insertColumns(int, int); 0055 void insertRows(int, int); 0056 void removeColumns(int, int); 0057 void removeRows(int, int); 0058 0059 QRect extents() const; 0060 void movePattern(int dx, int dy); 0061 void mirror(Qt::Orientation); 0062 void rotate(Rotation); 0063 0064 void addStitch(const QPoint &, Stitch::Type, int); 0065 Stitch *findStitch(const QPoint &, Stitch::Type, int); 0066 void deleteStitch(const QPoint &, Stitch::Type, int); 0067 0068 StitchQueue *stitchQueueAt(int, int); 0069 StitchQueue *stitchQueueAt(const QPoint &); 0070 StitchQueue *takeStitchQueueAt(int, int); 0071 StitchQueue *takeStitchQueueAt(const QPoint &); 0072 StitchQueue *replaceStitchQueueAt(int, int, StitchQueue *); 0073 StitchQueue *replaceStitchQueueAt(const QPoint &, StitchQueue *); 0074 0075 void addBackstitch(const QPoint &, const QPoint &, int); 0076 void addBackstitch(Backstitch *); 0077 Backstitch *findBackstitch(const QPoint &, const QPoint &, int); 0078 Backstitch *takeBackstitch(const QPoint &, const QPoint &, int); 0079 Backstitch *takeBackstitch(Backstitch *); 0080 0081 void addFrenchKnot(const QPoint &, int); 0082 void addFrenchKnot(Knot *); 0083 Knot *findKnot(const QPoint &, int); 0084 Knot *takeFrenchKnot(const QPoint &, int); 0085 Knot *takeFrenchKnot(Knot *); 0086 0087 QList<Backstitch *> &backstitches(); 0088 QList<Knot *> &knots(); 0089 0090 QListIterator<Backstitch *> backstitchIterator(); 0091 QMutableListIterator<Backstitch *> mutableBackstitchIterator(); 0092 QListIterator<Knot *> knotIterator(); 0093 QMutableListIterator<Knot *> mutableKnotIterator(); 0094 0095 QMap<int, FlossUsage> flossUsage(); 0096 0097 friend QDataStream &operator<<(QDataStream &, const StitchData &); 0098 friend QDataStream &operator>>(QDataStream &, StitchData &); 0099 0100 private: 0101 void deleteStitches(); 0102 void invertQueue(Qt::Orientation, StitchQueue *); 0103 void rotateQueue(Rotation, StitchQueue *); 0104 int index(int, int) const; 0105 int index(const QPoint &) const; 0106 bool isValid(int x, int y) const; 0107 0108 static const int version = 103; 0109 0110 int m_width; 0111 int m_height; 0112 0113 QVector<StitchQueue *> m_stitches; 0114 QList<Backstitch *> m_backstitches; 0115 QList<Knot *> m_knots; 0116 }; 0117 0118 QDataStream &operator<<(QDataStream &, const StitchData &); 0119 QDataStream &operator>>(QDataStream &, StitchData &); 0120 0121 #endif // StitchData_H