# HG changeset patch # User Santeri Piippo # Date 1389600459 -7200 # Node ID 622c49e6034837e0ea13ad10e8b9fda9415715f5 # Parent 928365840d0d3e23942bef54ee27c8bec1cab0ef - refactoring diff -r 928365840d0d -r 622c49e60348 src/addObjectDialog.cc --- a/src/addObjectDialog.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/addObjectDialog.cc Mon Jan 13 10:07:39 2014 +0200 @@ -199,7 +199,7 @@ { for (int i = 0; i < coordCount / 3; ++i) for (int j = 0; j < 3; ++j) - dsb_coords[ (i * 3) + j]->setValue (obj->getVertex (i).coord (j)); + dsb_coords[ (i * 3) + j]->setValue (obj->getVertex (i).getCoordinate (j)); } break; @@ -239,7 +239,7 @@ defaultMatrix = mo->getTransform(); } - le_matrix->setText (defaultMatrix.stringRep()); + le_matrix->setText (defaultMatrix.toString()); layout->addWidget (lb_matrix, 4, 1); layout->addWidget (le_matrix, 4, 2, 1, 3); } diff -r 928365840d0d -r 622c49e60348 src/config.cc --- a/src/config.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/config.cc Mon Jan 13 10:07:39 2014 +0200 @@ -41,7 +41,7 @@ Config* g_configPointers[MAX_CONFIG]; static int g_cfgPointerCursor = 0; static QMap g_configsByName; -static QList g_configs; +static QList g_configs; // ============================================================================= // Get the QSettings object. @@ -163,10 +163,10 @@ // ----------------------------------------------------------------------------- #undef IMPLEMENT_CONFIG -#define IMPLEMENT_CONFIG(NAME) \ - NAME##Config* NAME##Config::getByName (QString name) \ - { \ - return getConfigByName (name, NAME); \ +#define IMPLEMENT_CONFIG(NAME) \ + NAME##Config* NAME##Config::getByName (QString name) \ + { \ + return getConfigByName (name, E##NAME##Type); \ } IMPLEMENT_CONFIG (Int) @@ -175,3 +175,4 @@ IMPLEMENT_CONFIG (Float) IMPLEMENT_CONFIG (List) IMPLEMENT_CONFIG (KeySequence) +IMPLEMENT_CONFIG (Vertex) diff -r 928365840d0d -r 622c49e60348 src/config.h --- a/src/config.h Mon Jan 13 00:02:43 2014 +0200 +++ b/src/config.h Mon Jan 13 10:07:39 2014 +0200 @@ -20,6 +20,7 @@ #define LDFORGE_CONFIG_H #include "property.h" +#include "types.h" // ============================================================================= #include @@ -47,12 +48,13 @@ public: enum Type { - Int, - String, - Float, - Bool, - KeySequence, - List, + EIntType, + EStringType, + EFloatType, + EBoolType, + EKeySequenceType, + EListType, + EVertexType, }; using IntType = int; @@ -61,6 +63,7 @@ using BoolType = bool; using KeySequenceType = QKeySequence; using ListType = QList; + using VertexType = Vertex; Config (QString name); @@ -101,14 +104,14 @@ return *m_valueptr; \ } \ \ - inline void setValue (ValueType val) \ + inline void setValue (ValueType val) \ { \ *m_valueptr = val; \ } \ \ - virtual Config::Type getType() const \ + virtual Config::Type getType() const \ { \ - return Config::NAME; \ + return Config::E##NAME##Type; \ } \ \ virtual void resetValue() \ @@ -123,7 +126,7 @@ \ virtual bool isDefault() const \ { \ - return *m_valueptr == m_default; \ + return *m_valueptr == m_default; \ } \ \ virtual void loadFromVariant (const QVariant& val) \ @@ -133,17 +136,17 @@ \ virtual QVariant toVariant() const \ { \ - return QVariant::fromValue (*m_valueptr); \ + return QVariant::fromValue (*m_valueptr); \ } \ \ - virtual QVariant getDefaultAsVariant() const \ + virtual QVariant getDefaultAsVariant() const \ { \ return QVariant::fromValue (m_default); \ } \ \ static NAME##Config* getByName (QString name); \ \ -private: \ +private: \ ValueType* m_valueptr; \ ValueType m_default; @@ -183,4 +186,10 @@ IMPLEMENT_CONFIG (List) }; +// ============================================================================= +class VertexConfig : public Config +{ + IMPLEMENT_CONFIG (Vertex) +}; + #endif // LDFORGE_CONFIG_H diff -r 928365840d0d -r 622c49e60348 src/document.cc --- a/src/document.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/document.cc Mon Jan 13 10:07:39 2014 +0200 @@ -28,6 +28,7 @@ #include "history.h" #include "dialogs.h" #include "gldraw.h" +#include "misc/invokationDeferer.h" #include "moc_document.cpp" cfg (String, io_ldpath, ""); @@ -127,7 +128,7 @@ setSavePosition (-1); setListItem (null); setHistory (new History); - m_History->setFile (this); + m_History->setDocument (this); } // ============================================================================= diff -r 928365840d0d -r 622c49e60348 src/gldraw.cc --- a/src/gldraw.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/gldraw.cc Mon Jan 13 10:07:39 2014 +0200 @@ -674,7 +674,7 @@ // Draw their coordinates paint.setPen (textpen); - paint.drawText (blip.x(), blip.y() - 8, poly3d[i].stringRep (true)); + paint.drawText (blip.x(), blip.y() - 8, poly3d[i].toString (true)); } // Draw line lenghts and angle info if appropriate diff -r 928365840d0d -r 622c49e60348 src/gui.cc --- a/src/gui.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/gui.cc Mon Jan 13 10:07:39 2014 +0200 @@ -354,7 +354,7 @@ if (i != 0) descr += ", "; - descr += obj->getVertex (i).stringRep (true); + descr += obj->getVertex (i).toString (true); } } break; @@ -365,14 +365,14 @@ case LDObject::EVertex: { - descr = static_cast (obj)->pos.stringRep (true); + descr = static_cast (obj)->pos.toString (true); } break; case LDObject::ESubfile: { LDSubfile* ref = static_cast (obj); - descr = fmt ("%1 %2, (", ref->getFileInfo()->getDisplayName(), ref->getPosition().stringRep (true)); + descr = fmt ("%1 %2, (", ref->getFileInfo()->getDisplayName(), ref->getPosition().toString (true)); for (int i = 0; i < 9; ++i) descr += fmt ("%1%2", ref->getTransform()[i], (i != 8) ? " " : ""); diff -r 928365840d0d -r 622c49e60348 src/history.cc --- a/src/history.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/history.cc Mon Jan 13 10:07:39 2014 +0200 @@ -24,12 +24,12 @@ #include "gldraw.h" // ============================================================================= -// ----------------------------------------------------------------------------- +// History::History() : m_Position (-1) {} // ============================================================================= -// ----------------------------------------------------------------------------- +// void History::undo() { if (m_changesets.isEmpty() || getPosition() == -1) @@ -55,7 +55,7 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void History::redo() { if (getPosition() == m_changesets.size()) @@ -76,7 +76,7 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void History::clear() { for (Changeset set : m_changesets) @@ -88,7 +88,7 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void History::addStep() { if (m_currentChangeset.isEmpty()) @@ -112,7 +112,7 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void History::add (AbstractHistoryEntry* entry) { if (isIgnoring()) @@ -127,48 +127,48 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void AddHistory::undo() const { - LDObject* obj = getParent()->getFile()->getObject (getIndex()); + LDObject* obj = getParent()->getDocument()->getObject (getIndex()); obj->deleteSelf(); } // ============================================================================= -// ----------------------------------------------------------------------------- +// void AddHistory::redo() const { LDObject* obj = parseLine (getCode()); - getParent()->getFile()->insertObj (getIndex(), obj); + getParent()->getDocument()->insertObj (getIndex(), obj); g_win->R()->compileObject (obj); } // ============================================================================= -// ----------------------------------------------------------------------------- +// DelHistory::DelHistory (int idx, LDObject* obj) : m_Index (idx), m_Code (obj->raw()) {} // ============================================================================= // heh -// ----------------------------------------------------------------------------- +// void DelHistory::undo() const { LDObject* obj = parseLine (getCode()); - getParent()->getFile()->insertObj (getIndex(), obj); + getParent()->getDocument()->insertObj (getIndex(), obj); g_win->R()->compileObject (obj); } // ============================================================================= -// ----------------------------------------------------------------------------- +// void DelHistory::redo() const { - LDObject* obj = getParent()->getFile()->getObject (getIndex()); + LDObject* obj = getParent()->getDocument()->getObject (getIndex()); obj->deleteSelf(); } // ============================================================================= -// ----------------------------------------------------------------------------- +// void EditHistory::undo() const { LDObject* obj = getCurrentDocument()->getObject (getIndex()); @@ -178,7 +178,7 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void EditHistory::redo() const { LDObject* obj = getCurrentDocument()->getObject (getIndex()); @@ -188,13 +188,15 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void SwapHistory::undo() const { LDObject::fromID (a)->swap (LDObject::fromID (b)); } +// ============================================================================= +// void SwapHistory::redo() const { - undo(); // :v + undo(); } \ No newline at end of file diff -r 928365840d0d -r 622c49e60348 src/history.h --- a/src/history.h Mon Jan 13 00:02:43 2014 +0200 +++ b/src/history.h Mon Jan 13 10:07:39 2014 +0200 @@ -22,32 +22,40 @@ #include "main.h" #include "ldtypes.h" -#define IMPLEMENT_HISTORY_TYPE(N) \ - virtual ~N##History(){} \ - virtual void undo() const override; \ - virtual void redo() const override; \ - virtual History::Type getType() const override { return History::N; } \ - virtual const char* getTypeName() const { return #N; } +#define IMPLEMENT_HISTORY_TYPE(N) \ + virtual ~N##History() {} \ + virtual void undo() const override; \ + virtual void redo() const override; \ + \ + virtual History::EHistoryType getType() const override \ + { \ + return History::E##N##History; \ + } \ + \ + virtual QString getTypeName() const \ + { \ + return #N; \ + } class AbstractHistoryEntry; // ============================================================================= class History { - PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) - PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) + PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) + PROPERTY (public, LDDocument*, Document, NO_OPS, STOCK_WRITE) PROPERTY (public, bool, Ignoring, BOOL_OPS, STOCK_WRITE) public: typedef QList Changeset; - enum Type + enum EHistoryType { - Del, - Edit, - Add, - Move, - Swap, + EDelHistory, + EEditHistory, + EAddHistory, + EMoveHistory, + ESwapHistory, }; History(); @@ -88,18 +96,10 @@ public: virtual ~AbstractHistoryEntry() {} - virtual void undo() const {} - virtual void redo() const {} - - virtual History::Type getType() const - { - return (History::Type) 0; - } - - virtual const char* getTypeName() const - { - return ""; - } + virtual void undo() const = 0; + virtual void redo() const = 0; + virtual History::EHistoryType getType() const = 0; + virtual QString getTypeName() const = 0; }; // ============================================================================= @@ -107,7 +107,7 @@ // ============================================================================= class DelHistory : public AbstractHistoryEntry { - PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) + PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) public: @@ -120,9 +120,9 @@ // ============================================================================= class EditHistory : public AbstractHistoryEntry { - PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) - PROPERTY (private, QString, OldCode, NO_OPS, STOCK_WRITE) - PROPERTY (private, QString, NewCode, NO_OPS, STOCK_WRITE) + PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) + PROPERTY (private, QString, OldCode, NO_OPS, STOCK_WRITE) + PROPERTY (private, QString, NewCode, NO_OPS, STOCK_WRITE) public: IMPLEMENT_HISTORY_TYPE (Edit) @@ -138,7 +138,7 @@ // ============================================================================= class AddHistory : public AbstractHistoryEntry { - PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) + PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) public: diff -r 928365840d0d -r 622c49e60348 src/ldtypes.cc --- a/src/ldtypes.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/ldtypes.cc Mon Jan 13 10:07:39 2014 +0200 @@ -88,7 +88,7 @@ QString LDSubfile::raw() const { QString val = fmt ("1 %1 %2 ", getColor(), getPosition()); - val += getTransform().stringRep(); + val += getTransform().toString(); val += ' '; val += getFileInfo()->getName(); return val; diff -r 928365840d0d -r 622c49e60348 src/misc.cc --- a/src/misc.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/misc.cc Mon Jan 13 10:07:39 2014 +0200 @@ -25,17 +25,16 @@ #include "dialogs.h" #include "document.h" #include "ui_rotpoint.h" -#include "moc_misc.cpp" - #include "misc/documentPointer.cc" #include "misc/ringFinder.cc" +#include "misc/invokationDeferer.cc" // Prime number table. const int g_primes[NUM_PRIMES] = { - 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, - 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, + 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, @@ -85,40 +84,38 @@ 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, }; -static const int32 g_e10[] = +static const long g_e10[] = { - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000, + 1l, + 10l, + 100l, + 1000l, + 10000l, + 100000l, + 1000000l, + 10000000l, + 100000000l, + 1000000000l, }; // ============================================================================= // ----------------------------------------------------------------------------- // Grid stuff -cfg (Int, grid, Grid::Medium); -cfg (Float, grid_coarse_x, 5.0f); -cfg (Float, grid_coarse_y, 5.0f); -cfg (Float, grid_coarse_z, 5.0f); -cfg (Float, grid_coarse_angle, 45.0f); -cfg (Float, grid_medium_x, 1.0f); -cfg (Float, grid_medium_y, 1.0f); -cfg (Float, grid_medium_z, 1.0f); -cfg (Float, grid_medium_angle, 22.5f); -cfg (Float, grid_fine_x, 0.1f); -cfg (Float, grid_fine_y, 0.1f); -cfg (Float, grid_fine_z, 0.1f); -cfg (Float, grid_fine_angle, 7.5f); -cfg (Int, edit_rotpoint, 0); -cfg (Float, edit_rotpoint_x, 0.0f); // TODO: make a VertexConfig and use it here -cfg (Float, edit_rotpoint_y, 0.0f); -cfg (Float, edit_rotpoint_z, 0.0f); +cfg (Int, grid, Grid::Medium); +cfg (Float, grid_coarse_x, 5.0f); +cfg (Float, grid_coarse_y, 5.0f); +cfg (Float, grid_coarse_z, 5.0f); +cfg (Float, grid_coarse_angle, 45.0f); +cfg (Float, grid_medium_x, 1.0f); +cfg (Float, grid_medium_y, 1.0f); +cfg (Float, grid_medium_z, 1.0f); +cfg (Float, grid_medium_angle, 22.5f); +cfg (Float, grid_fine_x, 0.1f); +cfg (Float, grid_fine_y, 0.1f); +cfg (Float, grid_fine_z, 0.1f); +cfg (Float, grid_fine_angle, 7.5f); +cfg (Int, edit_rotpoint, 0); +cfg (Vertex, edit_customrotpoint, g_origin); const gridinfo g_GridInfo[3] = { @@ -195,7 +192,7 @@ if (numer <= prime || denom <= prime) continue; - if ( (numer % prime == 0) && (denom % prime == 0)) + if ((numer % prime == 0) && (denom % prime == 0)) { numer /= prime; denom /= prime; @@ -211,9 +208,9 @@ // ----------------------------------------------------------------------------- Vertex rotPoint (const LDObjectList& objs) { - switch (edit_rotpoint) + switch ((ERotationPoint) edit_rotpoint) { - case ObjectOrigin: + case EObjectOrigin: { LDBoundingBox box; @@ -229,14 +226,14 @@ return box.center(); } - case WorldOrigin: + case EWorldOrigin: { return g_origin; } - case CustomPoint: + case ECustomPoint: { - return Vertex (edit_rotpoint_x, edit_rotpoint_y, edit_rotpoint_z); + return edit_customrotpoint; } } @@ -251,36 +248,36 @@ Ui::RotPointUI ui; ui.setupUi (dlg); - switch (edit_rotpoint) + switch ((ERotationPoint) edit_rotpoint) { - case ObjectOrigin: + case EObjectOrigin: ui.objectPoint->setChecked (true); break; - case WorldOrigin: + case EWorldOrigin: ui.worldPoint->setChecked (true); break; - case CustomPoint: + case ECustomPoint: ui.customPoint->setChecked (true); break; } - ui.customX->setValue (edit_rotpoint_x); - ui.customY->setValue (edit_rotpoint_y); - ui.customZ->setValue (edit_rotpoint_z); + ui.customX->setValue (edit_customrotpoint.x()); + ui.customY->setValue (edit_customrotpoint.y()); + ui.customZ->setValue (edit_customrotpoint.z()); if (!dlg->exec()) return; edit_rotpoint = - (ui.objectPoint->isChecked()) ? ObjectOrigin : - (ui.worldPoint->isChecked()) ? WorldOrigin : - CustomPoint; + (ui.objectPoint->isChecked()) ? EObjectOrigin : + (ui.worldPoint->isChecked()) ? EWorldOrigin : + ECustomPoint; - edit_rotpoint_x = ui.customX->value(); - edit_rotpoint_y = ui.customY->value(); - edit_rotpoint_z = ui.customZ->value(); + edit_customrotpoint.x() = ui.customX->value(); + edit_customrotpoint.y() = ui.customY->value(); + edit_customrotpoint.z() = ui.customZ->value(); } // ============================================================================= @@ -301,34 +298,4 @@ { assert (decimals >= 0 && decimals < (signed) (sizeof g_e10 / sizeof *g_e10)); a = round (a * g_e10[decimals]) / g_e10[decimals]; -} - -// ============================================================================= -// ----------------------------------------------------------------------------- -InvokationDeferer* g_invokationDeferer = new InvokationDeferer(); - -InvokationDeferer::InvokationDeferer (QObject* parent) : QObject (parent) -{ - connect (this, SIGNAL (functionAdded()), this, SLOT (invokeFunctions()), - Qt::QueuedConnection); -} - -void InvokationDeferer::addFunctionCall (InvokationDeferer::FunctionType func) -{ - m_funcs << func; - removeDuplicates (m_funcs); - emit functionAdded(); -} - -void InvokationDeferer::invokeFunctions() -{ - for (FunctionType func : m_funcs) - (*func)(); - - m_funcs.clear(); -} - -void invokeLater (InvokationDeferer::FunctionType func) -{ - g_invokationDeferer->addFunctionCall (func); } \ No newline at end of file diff -r 928365840d0d -r 622c49e60348 src/misc.h --- a/src/misc.h Mon Jan 13 00:02:43 2014 +0200 +++ b/src/misc.h Mon Jan 13 10:07:39 2014 +0200 @@ -60,11 +60,11 @@ } // ============================================================================= -enum RotationPoint +enum ERotationPoint { - ObjectOrigin, - WorldOrigin, - CustomPoint + EObjectOrigin, + EWorldOrigin, + ECustomPoint }; Vertex rotPoint (const LDObjectList& objs); @@ -92,29 +92,6 @@ } // ----------------------------------------------------------------------------- -class InvokationDeferer : public QObject -{ - Q_OBJECT - - public: - using FunctionType = void(*)(); - - explicit InvokationDeferer (QObject* parent = 0); - void addFunctionCall (FunctionType func); - - signals: - void functionAdded(); - - private: - QList m_funcs; - - private slots: - void invokeFunctions(); -}; - -void invokeLater (InvokationDeferer::FunctionType func); - -// ----------------------------------------------------------------------------- // Plural expression template static inline const char* plural (T n) { diff -r 928365840d0d -r 622c49e60348 src/types.cc --- a/src/types.cc Mon Jan 13 00:02:43 2014 +0200 +++ b/src/types.cc Mon Jan 13 10:07:39 2014 +0200 @@ -74,26 +74,26 @@ Vertex mid; for_axes (ax) - mid[ax] = (m_coords[ax] + other[ax]) / 2; + mid[ax] = (getCoordinate (ax) + other[ax]) / 2; return mid; } // ============================================================================= // ----------------------------------------------------------------------------- -QString Vertex::stringRep (bool mangled) const +QString Vertex::toString (bool mangled) const { QString fmtstr = "%1 %2 %3"; if (mangled) fmtstr = "(%1, %2, %3)"; - return fmt (fmtstr, coord (X), coord (Y), coord (Z)); + return fmt (fmtstr, x(), y(), z()); } // ============================================================================= // ----------------------------------------------------------------------------- -void Vertex::transform (Matrix matr, Vertex pos) +void Vertex::transform (const Matrix& matr, const Vertex& pos) { double x2 = (matr[0] * x()) + (matr[1] * y()) + (matr[2] * z()) + pos[X]; double y2 = (matr[3] * x()) + (matr[4] * y()) + (matr[5] * z()) + pos[Y]; @@ -120,33 +120,11 @@ // ============================================================================= // ----------------------------------------------------------------------------- -double& Vertex::operator[] (const Axis ax) -{ - return coord ( (int) ax); -} - -const double& Vertex::operator[] (const Axis ax) const -{ - return coord ( (int) ax); -} - -double& Vertex::operator[] (const int ax) -{ - return coord (ax); -} - -const double& Vertex::operator[] (const int ax) const -{ - return coord (ax); -} - -// ============================================================================= -// ----------------------------------------------------------------------------- bool Vertex::operator== (const Vertex& other) const { - return coord (X) == other[X] && - coord (Y) == other[Y] && - coord (Z) == other[Z]; + return getCoordinate (X) == other[X] && + getCoordinate (Y) == other[Y] && + getCoordinate (Z) == other[Z]; } // ============================================================================= @@ -191,19 +169,19 @@ if (operator== (other)) return false; - if (coord (X) < other[X]) + if (getCoordinate (X) < other[X]) return true; - if (coord (X) > other[X]) + if (getCoordinate (X) > other[X]) return false; - if (coord (Y) < other[Y]) + if (getCoordinate (Y) < other[Y]) return true; - if (coord (Y) > other[Y]) + if (getCoordinate (Y) > other[Y]) return false; - return coord (Z) < other[Z]; + return getCoordinate (Z) < other[Z]; } // ============================================================================= @@ -245,7 +223,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -QString Matrix::stringRep() const +QString Matrix::toString() const { QString val; diff -r 928365840d0d -r 622c49e60348 src/types.h --- a/src/types.h Mon Jan 13 00:02:43 2014 +0200 +++ b/src/types.h Mon Jan 13 10:07:39 2014 +0200 @@ -22,8 +22,8 @@ #include #include #include -#include -#include "main.h" +#include +#include "property.h" class LDObject; class QFile; @@ -74,7 +74,7 @@ double getDeterminant() const; Matrix mult (const Matrix& other) const; void puts() const; - QString stringRep() const; + QString toString() const; void zero(); Matrix& operator= (const Matrix& other); @@ -126,8 +126,8 @@ double distanceTo (const Vertex& other) const; Vertex midpoint (const Vertex& other); void move (const Vertex& other); - QString stringRep (bool mangled) const; - void transform (Matrix matr, Vertex pos); + QString toString (bool mangled) const; + void transform (const Matrix& matr, const Vertex& pos); Vertex& operator+= (const Vertex& other); Vertex operator+ (const Vertex& other) const; @@ -137,17 +137,33 @@ bool operator!= (const Vertex& other) const; Vertex operator-() const; int operator< (const Vertex& other) const; - double& operator[] (const Axis ax); - const double& operator[] (const Axis ax) const; - double& operator[] (const int ax); - const double& operator[] (const int ax) const; + + inline double& operator[] (const Axis ax) + { + return getCoordinate ((int) ax); + } + + inline const double& operator[] (const Axis ax) const + { + return getCoordinate ((int) ax); + } - inline double& coord (int n) + inline double& operator[] (const int ax) + { + return getCoordinate (ax); + } + + inline const double& operator[] (const int ax) const + { + return getCoordinate (ax); + } + + inline double& getCoordinate (int n) { return m_coords[n]; } - inline const double& coord (int n) const + inline const double& getCoordinate (int n) const { return m_coords[n]; } @@ -186,6 +202,8 @@ double m_coords[3]; }; +Q_DECLARE_METATYPE (Vertex) + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= @@ -204,8 +222,8 @@ StringFormatArg (int a) : m_val (QString::number (a)) {} StringFormatArg (const float& a) : m_val (QString::number (a)) {} StringFormatArg (const double& a) : m_val (QString::number (a)) {} - StringFormatArg (const Vertex& a) : m_val (a.stringRep (false)) {} - StringFormatArg (const Matrix& a) : m_val (a.stringRep()) {} + StringFormatArg (const Vertex& a) : m_val (a.toString (false)) {} + StringFormatArg (const Matrix& a) : m_val (a.toString()) {} StringFormatArg (const char* a) : m_val (a) {} StringFormatArg (const void* a)