- did stuff to types, fixed primitive listing

Wed, 08 Jan 2014 23:52:25 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 08 Jan 2014 23:52:25 +0200
changeset 610
f8244301110d
parent 609
a8dc74a809c6
child 611
6679e47b019f

- did stuff to types, fixed primitive listing

src/gui_actions.cc file | annotate | diff | comparison | revisions
src/primitives.cc file | annotate | diff | comparison | revisions
src/types.cc file | annotate | diff | comparison | revisions
src/types.h file | annotate | diff | comparison | revisions
--- a/src/gui_actions.cc	Wed Jan 08 21:43:46 2014 +0200
+++ b/src/gui_actions.cc	Wed Jan 08 23:52:25 2014 +0200
@@ -713,7 +713,7 @@
 	QString			parentpath = getCurrentDocument()->getFullPath();
 
 	// BFC type of the new subfile - it shall inherit the BFC type of the parent document
-	LDBFC::Type	bfctype = LDBFC::NoCertify;
+	LDBFC::Type		bfctype = LDBFC::NoCertify;
 
 	// Dirname of the new subfile
 	QString			subdirname = dirname (parentpath);
@@ -722,19 +722,19 @@
 	QString			subtitle;
 
 	// Comment containing the title of the parent document
-	LDComment*	titleobj = dynamic_cast<LDComment*> (getCurrentDocument()->getObject (0));
+	LDComment*		titleobj = dynamic_cast<LDComment*> (getCurrentDocument()->getObject (0));
 
 	// License text for the subfile
 	QString			license = getLicenseText (ld_defaultlicense);
 
 	// LDraw code body of the new subfile (i.e. code of the selection)
-	QStringList	code;
+	QStringList		code;
 
 	// Full path of the subfile to be
 	QString			fullsubname;
 
 	// Where to insert the subfile reference?
-	int			refidx = selection()[0]->getIndex();
+	int				refidx = selection()[0]->getIndex();
 
 	// Determine title of subfile
 	if (titleobj != null)
--- a/src/primitives.cc	Wed Jan 08 21:43:46 2014 +0200
+++ b/src/primitives.cc	Wed Jan 08 23:52:25 2014 +0200
@@ -137,7 +137,7 @@
 		QString fname = m_files[m_i];
 		QFile f (fname);
 
-		if (f.open (QIODevice::ReadOnly))
+		if (!f.open (QIODevice::ReadOnly))
 			continue;
 
 		Primitive info;
@@ -151,7 +151,7 @@
 
 		info.title = info.title.simplified();
 
-		if (info.title[0] == '0')
+		if (Q_LIKELY (info.title[0] == '0'))
 		{
 			info.title.remove (0, 1);  // remove 0
 			info.title = info.title.simplified();
--- a/src/types.cc	Wed Jan 08 21:43:46 2014 +0200
+++ b/src/types.cc	Wed Jan 08 23:52:25 2014 +0200
@@ -269,7 +269,7 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-Matrix Matrix::mult (Matrix other) const
+Matrix Matrix::mult (const Matrix& other) const
 {
 	Matrix val;
 	val.zero();
@@ -284,7 +284,7 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-Matrix& Matrix::operator= (Matrix other)
+Matrix& Matrix::operator= (const Matrix& other)
 {
 	memcpy (&m_vals[0], &other.m_vals[0], sizeof m_vals);
 	return *this;
@@ -315,58 +315,6 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-StringFormatArg::StringFormatArg (const QString& v)
-{
-	m_val = v;
-}
-
-StringFormatArg::StringFormatArg (const char& v)
-{
-	m_val = v;
-}
-
-StringFormatArg::StringFormatArg (const uchar& v)
-{
-	m_val = v;
-}
-
-StringFormatArg::StringFormatArg (const QChar& v)
-{
-	m_val = v;
-}
-
-StringFormatArg::StringFormatArg (const float& v)
-{
-	m_val = QString::number (v);
-}
-
-StringFormatArg::StringFormatArg (const double& v)
-{
-	m_val = QString::number (v);
-}
-
-StringFormatArg::StringFormatArg (const Vertex& v)
-{
-	m_val = v.stringRep (false);
-}
-
-StringFormatArg::StringFormatArg (const Matrix& v)
-{
-	m_val = v.stringRep();
-}
-
-StringFormatArg::StringFormatArg (const char* v)
-{
-	m_val = v;
-}
-
-StringFormatArg::StringFormatArg (const void* v)
-{
-	m_val.sprintf ("%p", v);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
 LDBoundingBox::LDBoundingBox()
 {
 	reset();
--- a/src/types.h	Wed Jan 08 21:43:46 2014 +0200
+++ b/src/types.h	Wed Jan 08 23:52:25 2014 +0200
@@ -67,11 +67,11 @@
 		Matrix (double vals[]);
 
 		double			getDeterminant() const;
-		Matrix			mult (Matrix other) const;
-		void				puts() const;
-		QString				stringRep() const;
-		void				zero();
-		Matrix&			operator= (Matrix other);
+		Matrix			mult (const Matrix& other) const;
+		void			puts() const;
+		QString			stringRep() const;
+		void			zero();
+		Matrix&			operator= (const Matrix& other);
 
 		inline double& val (int idx)
 		{
@@ -83,7 +83,7 @@
 			return m_vals[idx];
 		}
 
-		inline Matrix operator* (Matrix other) const
+		inline Matrix operator* (const Matrix& other) const
 		{
 			return mult (other);
 		}
@@ -192,57 +192,46 @@
 class StringFormatArg
 {
 	public:
-		StringFormatArg (const QString& v);
-		StringFormatArg (const char& v);
-		StringFormatArg (const uchar& v);
-		StringFormatArg (const QChar& v);
-
-#define NUMERIC_FORMAT_ARG(T,C) \
-	StringFormatArg (const T& v) { \
-		char valstr[32]; \
-		sprintf (valstr, "%" #C, v); \
-		m_val = valstr; \
-	}
+		StringFormatArg (const QString& a) : m_val (a) {}
+		StringFormatArg (const char& a) : m_val (a) {}
+		StringFormatArg (const uchar& a) : m_val (a) {}
+		StringFormatArg (const QChar& a) : m_val (a) {}
+		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 char* a) : m_val (a) {}
 
-		NUMERIC_FORMAT_ARG (int, d)
-		NUMERIC_FORMAT_ARG (short, d)
-		NUMERIC_FORMAT_ARG (long, ld)
-		NUMERIC_FORMAT_ARG (uint, u)
-		NUMERIC_FORMAT_ARG (ushort, u)
-		NUMERIC_FORMAT_ARG (ulong, lu)
+		StringFormatArg (const void* a)
+		{
+			m_val.sprintf ("%p", a);
+		}
 
-		StringFormatArg (const float& v);
-		StringFormatArg (const double& v);
-		StringFormatArg (const Vertex& v);
-		StringFormatArg (const Matrix& v);
-		StringFormatArg (const char* v);
-		StringFormatArg (const void* v);
-
-		template<class T> StringFormatArg (const QList<T>& v)
+		template<class T> StringFormatArg (const QList<T>& a)
 		{
 			m_val = "{ ";
 
-			int i = 0;
-
-			for (const T& it : v)
+			for (const T& it : a)
 			{
-				if (i++)
+				if (&it != &a.first())
 					m_val += ", ";
 
 				StringFormatArg arg (it);
 				m_val += arg.value();
 			}
 
-			if (i)
+			if (!a.isEmpty())
 				m_val += " ";
 
 			m_val += "}";
 		}
 
-		QString value() const
+		inline QString value() const
 		{
 			return m_val;
 		}
+
 	private:
 		QString m_val;
 };
@@ -255,9 +244,9 @@
 // =============================================================================
 class LDBoundingBox
 {
-	PROPERTY (private,	bool,		Empty,	BOOL_OPS,	STOCK_WRITE)
-	PROPERTY (private,	Vertex,	Vertex0,	NO_OPS,		STOCK_WRITE)
-	PROPERTY (private,	Vertex,	Vertex1,	NO_OPS,		STOCK_WRITE)
+	PROPERTY (private,	bool,		Empty,		BOOL_OPS,	STOCK_WRITE)
+	PROPERTY (private,	Vertex,		Vertex0,	NO_OPS,		STOCK_WRITE)
+	PROPERTY (private,	Vertex,		Vertex1,	NO_OPS,		STOCK_WRITE)
 
 	public:
 		LDBoundingBox();

mercurial