Added PROPERTY macro for easier exposed member variable management

Sun, 19 May 2013 03:42:25 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 19 May 2013 03:42:25 +0300
changeset 223
4f95d7f2e9ef
parent 222
fddd36a6526c
child 224
805bf9ef9529

Added PROPERTY macro for easier exposed member variable management

src/bbox.cpp file | annotate | diff | comparison | revisions
src/bbox.h file | annotate | diff | comparison | revisions
src/common.h file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
src/labeledwidget.h file | annotate | diff | comparison | revisions
src/ldtypes.h file | annotate | diff | comparison | revisions
src/misc.cpp file | annotate | diff | comparison | revisions
src/misc.h file | annotate | diff | comparison | revisions
--- a/src/bbox.cpp	Sun May 19 02:55:29 2013 +0300
+++ b/src/bbox.cpp	Sun May 19 03:42:25 2013 +0300
@@ -159,9 +159,4 @@
 		(m_v0[X] + m_v1[X]) / 2,
 		(m_v0[Y] + m_v1[Y]) / 2,
 		(m_v0[Z] + m_v1[Z]) / 2);
-}
-
-// =============================================================================
-bool bbox::empty() const {
-	return m_empty;
 }
\ No newline at end of file
--- a/src/bbox.h	Sun May 19 02:55:29 2013 +0300
+++ b/src/bbox.h	Sun May 19 03:42:25 2013 +0300
@@ -30,6 +30,10 @@
 // v0 is the minimum vertex, v1 is the maximum vertex.
 // =============================================================================
 class bbox {
+	READ_PROPERTY (bool, empty)
+	READ_PROPERTY (vertex, v0)
+	READ_PROPERTY (vertex, v1)
+	
 public:
 	bbox ();
 	void reset ();
@@ -38,7 +42,6 @@
 	void calcObject (LDObject* obj);
 	void calcVertex (vertex v);
 	vertex center () const;
-	bool empty () const;
 	
 	bbox& operator<< (LDObject* obj) {
 		calcObject (obj);
@@ -49,13 +52,6 @@
 		calcVertex (v);
 		return *this;
 	}
-	
-	const vertex& v0 () { return m_v0; }
-	const vertex& v1 () { return m_v1; }
-	
-private:
-	vertex m_v0, m_v1;
-	bool m_empty;
 };
 
 #endif // BBOX_H
\ No newline at end of file
--- a/src/common.h	Sun May 19 02:55:29 2013 +0300
+++ b/src/common.h	Sun May 19 03:42:25 2013 +0300
@@ -72,6 +72,18 @@
 #define NDEBUG // remove asserts
 #endif // RELEASE
 
+// Read-only, private property with a get accessor
+#define READ_PROPERTY(T, GET) \
+private: \
+	T m_##GET; \
+public: \
+	const T& GET () const { return m_##GET; } \
+
+// Read/write private property with get and set accessors
+#define PROPERTY(T, GET, SET) \
+	READ_PROPERTY(T, GET) \
+	void SET (T val) { m_##GET = val; }
+
 #ifdef null
 #undef null
 #endif // null
--- a/src/gldraw.cpp	Sun May 19 02:55:29 2013 +0300
+++ b/src/gldraw.cpp	Sun May 19 03:42:25 2013 +0300
@@ -98,7 +98,7 @@
 	m_picking = m_rangepick = false;
 	m_camera = (GL::Camera) gl_camera.value;
 	m_drawToolTip = false;
-	m_editmode = Select;
+	m_editMode = Select;
 	m_rectdraw = false;
 	
 	m_toolTipTimer = new QTimer (this);
@@ -513,7 +513,7 @@
 			textSize.height (), Qt::AlignCenter, text);
 		
 		// If we're drawing, draw the vertices onto the screen.
-		if (m_editmode == Draw) {
+		if (m_editMode == Draw) {
 			ushort numverts;
 			
 			if (!m_rectdraw)
@@ -911,7 +911,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void GLRenderer::mousePressEvent (QMouseEvent* ev) {
-	if (ev->buttons () & Qt::LeftButton && !(m_lastButtons && Qt::LeftButton))
+	if (ev->buttons () & Qt::LeftButton)
 		m_totalmove = 0;
 	
 	if (ev->modifiers () & Qt::ShiftModifier) {
@@ -1161,7 +1161,7 @@
 		break;
 	}
 	
-	m_editmode = mode;
+	m_editMode = mode;
 	
 	g_win->updateEditModeActions ();
 	update ();
--- a/src/gldraw.h	Sun May 19 02:55:29 2013 +0300
+++ b/src/gldraw.h	Sun May 19 03:42:25 2013 +0300
@@ -41,6 +41,9 @@
 class GLRenderer : public QGLWidget {
 	Q_OBJECT
 	
+	PROPERTY (double, zoom, setZoom)
+	READ_PROPERTY (bool, picking)
+	
 public:
 	enum Camera { Top, Front, Left, Bottom, Back, Right, Free };
 	enum EditMode { Select, Draw };
@@ -56,11 +59,10 @@
 	void		compileObject		(LDObject* obj);
 	void		compileAllObjects	();
 	double		depthValue			() const;
-	EditMode	editMode			() const { return m_editmode; }
+	EditMode	editMode			() const { return m_editMode; }
 	void		endDraw				(bool accept);
 	QColor		getMainColor		();
 	void		hardRefresh		();
-	bool		picking				() const { return m_picking; }
 	void		refresh			();
 	void		resetAngles		();
 	uchar*		screencap			(ushort& w, ushort& h);
@@ -69,8 +71,6 @@
 	void		setDepthValue		(double depth);
 	void		setEditMode		(const EditMode mode);
 	void		setupOverlay		();
-	void		setZoom				(const double zoom) { m_zoom = zoom; }
-	double		zoom				() const { return m_zoom; }
 	
 	static void	deleteLists			(LDObject* obj);
 
@@ -93,15 +93,15 @@
 	Qt::KeyboardModifiers m_keymods;
 	ulong m_totalmove;
 	vertex m_hoverpos;
-	double m_virtWidth, m_virtHeight, m_rotX, m_rotY, m_rotZ, m_panX, m_panY, m_zoom;
-	bool m_darkbg, m_picking, m_rangepick, m_addpick, m_drawToolTip, m_screencap;
+	double m_virtWidth, m_virtHeight, m_rotX, m_rotY, m_rotZ, m_panX, m_panY;
+	bool m_darkbg, m_rangepick, m_addpick, m_drawToolTip, m_screencap;
 	QPoint m_pos, m_rangeStart;
 	QPen m_thinBorderPen, m_thickBorderPen;
 	Camera m_camera, m_toolTipCamera;
 	uint m_axeslist;
 	ushort m_width, m_height;
 	std::vector<vertex> m_drawedVerts;
-	EditMode m_editmode;
+	EditMode m_editMode;
 	bool m_rectdraw;
 	QColor m_bgcolor;
 	
--- a/src/labeledwidget.h	Sun May 19 02:55:29 2013 +0300
+++ b/src/labeledwidget.h	Sun May 19 03:42:25 2013 +0300
@@ -19,6 +19,7 @@
 #ifndef LABELEDWIDGET_H
 #define LABELEDWIDGET_H
 
+#include "common.h"
 #include <QLabel>
 #include <QBoxLayout>
 
@@ -28,6 +29,9 @@
 // Convenience class for a widget with a label beside it.
 // =============================================================================
 template<class R> class LabeledWidget : public QWidget {
+	PROPERTY (QLabel*, label, setLabel)
+	PROPERTY (R*, widget, setWidget)
+	
 public:
 	explicit LabeledWidget (const char* labelstr, QWidget* parent = null) : QWidget (parent) {
 		m_widget = new R (this);
@@ -45,12 +49,7 @@
 		commonInit ("");
 	}
 	
-	R* widget () const { return m_widget; }
 	R* w () const { return m_widget; }
-	QLabel* label () const { return m_label; }
-	QLabel* l () const { return m_label; }
-	void setWidget (R* widget) { m_widget = widget; }
-	void setLabel (QLabel* label) { m_label = label; }
 	operator R* () { return m_widget; }
 	
 private:
@@ -64,8 +63,6 @@
 		setLayout (m_layout);
 	}
 	
-	R* m_widget;
-	QLabel* m_label;
 	QHBoxLayout* m_layout;
 };
 
--- a/src/ldtypes.h	Sun May 19 02:55:29 2013 +0300
+++ b/src/ldtypes.h	Sun May 19 03:42:25 2013 +0300
@@ -77,6 +77,9 @@
 // sub-classes based on this enumerator.
 // =============================================================================
 class LDObject {
+	PROPERTY (bool, hidden, setHidden)
+	PROPERTY (bool, selected, setSelected)
+	
 public:
 	// Object type codes. Codes are sorted in order of significance.
 	enum Type {
@@ -131,7 +134,7 @@
 	
 	// Replace this LDObject with another LDObject. This method deletes the
 	// object and any pointers to it become invalid.
-    void replace (LDObject* replacement);
+	void replace (LDObject* replacement);
 	
 	// Swap this object with another.
 	void swap (LDObject* other);
@@ -160,21 +163,14 @@
 	// Object list entry for this object
 	QListWidgetItem* qObjListEntry;
 	
-	bool					hidden			() const { return m_hidden; }
 	virtual bool			hasMatrix		() const { return false; }
 	virtual HistoryEntry*	invert			();
 	LDObject*				next			() const;
 	LDObject*				prev			() const;
-	void					setHidden		(const bool hidden) { m_hidden = hidden; }
-	bool					selected		() const { return m_selected; }
-	void					setSelected	(bool selected) { m_selected = selected; }
 
 protected:
 	bool m_glinit;
 	friend class GLRenderer;
-
-private:
-	bool m_hidden, m_selected;
 };
 
 // =============================================================================
--- a/src/misc.cpp	Sun May 19 02:55:29 2013 +0300
+++ b/src/misc.cpp	Sun May 19 03:42:25 2013 +0300
@@ -132,12 +132,12 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 // Float to string. Removes trailing zeroes and is locale-independant.
-str ftoa (double fCoord) {
+str ftoa (double num) {
 	// Disable the locale first so that the decimal point will not
 	// turn into anything weird (like commas)
 	setlocale (LC_NUMERIC, "C");
 	
-	str zRep = fmt ("%f", fCoord);
+	str zRep = fmt ("%f", num);
 	
 	// Remove trailing zeroes
 	while (zRep[~zRep - 1] == '0')
--- a/src/misc.h	Sun May 19 02:55:29 2013 +0300
+++ b/src/misc.h	Sun May 19 03:42:25 2013 +0300
@@ -34,7 +34,7 @@
 bool isNumber (str& tok);
 
 // Converts a float value to a string value.
-str ftoa (double fCoord);
+str ftoa (double num);
 
 // Simplifies the given fraction.
 void simplify (short& numer, short& denom);

mercurial