Replaced uses of 'x.size()' with 'length(x)'

Sat, 28 Jan 2017 14:01:19 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 28 Jan 2017 14:01:19 +0200
changeset 1063
1f15c52c11f6
parent 1062
4119185b56ca
child 1064
4c7a353cf583

Replaced uses of 'x.size()' with 'length(x)'

src/addObjectDialog.cpp file | annotate | diff | comparison | revisions
src/basics.h file | annotate | diff | comparison | revisions
src/colors.cpp file | annotate | diff | comparison | revisions
src/dialogs/configdialog.cpp file | annotate | diff | comparison | revisions
src/documentloader.cpp file | annotate | diff | comparison | revisions
src/documentmanager.cpp file | annotate | diff | comparison | revisions
src/editHistory.cpp file | annotate | diff | comparison | revisions
src/editmodes/abstractEditMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/circleMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/curvemode.cpp file | annotate | diff | comparison | revisions
src/editmodes/drawMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/linePathMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/magicWandMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/rectangleMode.cpp file | annotate | diff | comparison | revisions
src/glCompiler.cpp file | annotate | diff | comparison | revisions
src/ldDocument.cpp file | annotate | diff | comparison | revisions
src/ldObject.cpp file | annotate | diff | comparison | revisions
src/ldobjectiterator.h file | annotate | diff | comparison | revisions
src/ldpaths.cpp file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/messageLog.cpp file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
src/ringFinder.cpp file | annotate | diff | comparison | revisions
src/toolsets/algorithmtoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/basictoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/filetoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/movetoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/viewtoolset.cpp file | annotate | diff | comparison | revisions
src/types/matrix.cpp file | annotate | diff | comparison | revisions
--- a/src/addObjectDialog.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/addObjectDialog.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -312,7 +312,7 @@
 	{
 		QStringList matrixstrvals = dlg.le_matrix->text().split (" ", QString::SkipEmptyParts);
 
-		if (matrixstrvals.size() == 9)
+		if (length(matrixstrvals) == 9)
 		{
 			double matrixvals[9];
 			int i = 0;
--- a/src/basics.h	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/basics.h	Sat Jan 28 14:01:19 2017 +0200
@@ -225,7 +225,7 @@
 
 static inline int length(const QString& string)
 {
-	return string.size();
+	return string.length();
 }
 
 template<typename T>
@@ -233,3 +233,15 @@
 {
 	return vector.size();
 }
+
+template<typename T>
+int length(const QList<T>& vector)
+{
+	return vector.size();
+}
+
+template<typename T>
+int length(const std::initializer_list<T>& vector)
+{
+	return vector.size();
+}
--- a/src/colors.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/colors.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -378,7 +378,7 @@
  */
 bool LDConfigParser::getToken(QString& tokenText, int position)
 {
-	if (position >= m_tokens.size())
+	if (position >= length(m_tokens))
 	{
 		return false;
 	}
@@ -399,7 +399,7 @@
  */
 bool LDConfigParser::findToken(int& tokenPosition, QString needle, int args)
 {
-	for (int i = 0; i < (m_tokens.size() - args); ++i)
+	for (int i = 0; i < (length(m_tokens) - args); ++i)
 	{
 		if (m_tokens[i] == needle)
 		{
--- a/src/dialogs/configdialog.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/dialogs/configdialog.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -411,7 +411,7 @@
 	{
 		ColorToolbarItem newentry (value, nullptr);
 		item = getSelectedQuickColor();
-		int idx = (item) ? getItemRow (item, quickColorItems) + 1 : quickColorItems.size();
+		int idx = (item) ? getItemRow (item, quickColorItems) + 1 : length(quickColorItems);
 		quickColors.insert (idx, newentry);
 		entry = &quickColors[idx];
 	}
@@ -446,7 +446,7 @@
 	int idx = getItemRow (item, quickColorItems);
 	int dest = up ? (idx - 1) : (idx + 1);
 
-	if (dest < 0 or dest >= quickColorItems.size())
+	if (dest < 0 or dest >= length(quickColorItems))
 		return; // destination out of bounds
 
 	qSwap (quickColors[dest], quickColors[idx]);
@@ -460,7 +460,7 @@
 void ConfigDialog::slot_addColorSeparator()
 {
 	quickColors << ColorToolbarItem::makeSeparator();
-	updateQuickColorList (&quickColors[quickColors.size() - 1]);
+	updateQuickColorList (&quickColors[length(quickColors) - 1]);
 }
 
 //
@@ -555,7 +555,7 @@
 {
 	QList<ShortcutListItem*> sel = getShortcutSelection();
 
-	if (sel.size() < 1)
+	if (length(sel) < 1)
 		return;
 
 	ShortcutListItem* item = sel[0];
--- a/src/documentloader.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/documentloader.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -80,7 +80,7 @@
 		// Show a progress dialog if we're loading the main ldDocument.here so we can show progress updates and keep the
 		// WM posted that we're still here.
 		m_progressDialog = new OpenProgressDialog(qobject_cast<QWidget*>(parent()));
-		m_progressDialog->setNumLines (m_lines.size());
+		m_progressDialog->setNumLines (length(m_lines));
 		m_progressDialog->setModal (true);
 		m_progressDialog->show();
 		connect (this, SIGNAL (workDone()), m_progressDialog, SLOT (accept()));
@@ -109,7 +109,7 @@
 	// Parse up to 200 lines per iteration
 	int max = i + 200;
 
-	for (; i < max and i < (int) m_lines.size(); ++i)
+	for (; i < max and i < (int) length(m_lines); ++i)
 	{
 		QString line = m_lines[i];
 
@@ -134,7 +134,7 @@
 	if (m_progressDialog)
 		m_progressDialog->setProgress (i);
 
-	if (i >= m_lines.size() - 1)
+	if (i >= length(m_lines) - 1)
 	{
 		emit workDone();
 		m_isDone = true;
--- a/src/documentmanager.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/documentmanager.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -369,14 +369,14 @@
 	// If this file already is in the list, pop it out.
 	if (idx != -1)
 	{
-		if (idx == recentFiles.size() - 1)
+		if (idx == length(recentFiles) - 1)
 			return; // first recent file - abort and do nothing
 
 		recentFiles.removeAt (idx);
 	}
 
 	// If there's too many recent files, drop one out.
-	while (recentFiles.size() > (MaxRecentFiles - 1))
+	while (length(recentFiles) > (MaxRecentFiles - 1))
 		recentFiles.removeAt (0);
 
 	// Add the file
--- a/src/editHistory.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editHistory.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -38,7 +38,7 @@
 	const Changeset& set = changesetAt (position());
 
 	// Iterate the list in reverse and undo all actions
-	for (int i = set.size() - 1; i >= 0; --i)
+	for (int i = length(set) - 1; i >= 0; --i)
 	{
 		AbstractHistoryEntry* change = set[i];
 		change->undo();
@@ -51,7 +51,7 @@
 
 void EditHistory::redo()
 {
-	if (position() == m_changesets.size())
+	if (position() == length(m_changesets))
 		return;
 
 	setIgnoring (true);
@@ -110,7 +110,7 @@
 
 int EditHistory::size() const
 {
-	return m_changesets.size();
+	return length(m_changesets);
 }
 
 const EditHistory::Changeset& EditHistory::changesetAt (int pos) const
--- a/src/editmodes/abstractEditMode.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editmodes/abstractEditMode.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -95,7 +95,7 @@
 	if (Super::mouseReleased(data))
 		return true;
 
-	if ((data.releasedButtons & Qt::MidButton) and (m_drawedVerts.size() < 4) and (not data.mouseMoved))
+	if ((data.releasedButtons & Qt::MidButton) and (length(m_drawedVerts) < 4) and (not data.mouseMoved))
 	{
 		// Find the closest vertex to our cursor
 		double minimumDistance = 1024.0;
@@ -155,7 +155,7 @@
 
 	if (data.releasedButtons & Qt::LeftButton)
 	{
-		if (maxVertices() and m_drawedVerts.size() >= maxVertices())
+		if (maxVertices() and length(m_drawedVerts) >= maxVertices())
 			endDraw();
 		else
 			addDrawnVertex (getCursorVertex());
@@ -169,7 +169,7 @@
 {
 	int pos = m_window->suggestInsertPoint();
 
-	if (objs.size() > 0)
+	if (length(objs) > 0)
 	{
 		for (LDObject* obj : objs)
 		{
@@ -198,11 +198,11 @@
 void AbstractDrawMode::renderPolygon(QPainter& painter, const QVector<Vertex>& polygon3d,
 	bool drawLineLengths, bool drawAngles ) const
 {
-	QVector<QPoint> polygon2d (polygon3d.size());
+	QVector<QPoint> polygon2d (length(polygon3d));
 	QFontMetrics metrics = QFontMetrics(QFont());
 
 	// Convert to 2D
-	for (int i = 0; i < polygon3d.size(); ++i)
+	for (int i = 0; i < length(polygon3d); ++i)
 		polygon2d[i] = renderer()->convert3dTo2d(polygon3d[i]);
 
 	// Draw the polygon-to-be
@@ -210,21 +210,21 @@
 	painter.drawPolygon(QPolygonF{polygon2d});
 
 	// Draw vertex blips
-	for (int i = 0; i < polygon3d.size(); ++i)
+	for (int i = 0; i < length(polygon3d); ++i)
 	{
 		renderer()->drawPoint(painter, polygon2d[i]);
 		renderer()->drawBlipCoordinates(painter, polygon3d[i], polygon2d[i]);
 	}
 
 	// Draw line lenghts and angle info if appropriate
-	if (polygon3d.size() >= 2 and (drawLineLengths or drawAngles))
+	if (length(polygon3d) >= 2 and (drawLineLengths or drawAngles))
 	{
 		painter.setPen (renderer()->textPen());
 
-		for (int i = 0; i < polygon3d.size(); ++i)
+		for (int i = 0; i < length(polygon3d); ++i)
 		{
-			int j = (i + 1) % polygon3d.size();
-			int prior = (i - 1 >= 0) ? (i - 1) : (polygon3d.size() - 1);
+			int j = (i + 1) % length(polygon3d);
+			int prior = (i - 1 >= 0) ? (i - 1) : (length(polygon3d) - 1);
 
 			if (drawLineLengths)
 				drawLineLength(painter, polygon3d[i], polygon3d[j], polygon2d[i], polygon2d[j]);
--- a/src/editmodes/circleMode.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editmodes/circleMode.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -40,11 +40,11 @@
 
 double CircleMode::getCircleDrawDist (int pos) const
 {
-	if (m_drawedVerts.size() >= pos + 1)
+	if (length(m_drawedVerts) >= pos + 1)
 	{
 		Vertex v1;
 
-		if (m_drawedVerts.size() >= pos + 2)
+		if (length(m_drawedVerts) >= pos + 2)
 			v1 = m_drawedVerts[pos + 1];
 		else
 			v1 = renderer()->convert2dTo3d (renderer()->mousePosition(), false);
@@ -232,13 +232,13 @@
 	QVector<Vertex> innerverts, outerverts;
 	QVector<QPointF> innerverts2d, outerverts2d;
 	const double innerdistance (getCircleDrawDist (0));
-	const double outerdistance (m_drawedVerts.size() >= 2 ? getCircleDrawDist (1) : -1);
+	const double outerdistance (length(m_drawedVerts) >= 2 ? getCircleDrawDist (1) : -1);
 	const int divisions (m_window->ringToolHiRes() ? HighResolution : LowResolution);
 	const int segments (m_window->ringToolSegments());
 	const double angleUnit (2 * pi / divisions);
 	Axis relX, relY;
 	renderer()->getRelativeAxes (relX, relY);
-	const double angleoffset (m_drawedVerts.size() < 3 ? getAngleOffset() : m_angleOffset);
+	const double angleoffset (length(m_drawedVerts) < 3 ? getAngleOffset() : m_angleOffset);
 
 	// Calculate the preview positions of vertices
 	for (int i = 0; i < segments + 1; ++i)
@@ -307,7 +307,7 @@
 	painter.setPen (renderer()->textPen());
 	painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label);
 
-	if (m_drawedVerts.size() >= 2)
+	if (length(m_drawedVerts) >= 2)
 	{
 		painter.drawText (origin.x() - (metrics.width (label) / 2),
 			origin.y() + metrics.height(), QString::number (outerdistance));
--- a/src/editmodes/curvemode.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editmodes/curvemode.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -25,36 +25,36 @@
 
 void CurveMode::render (QPainter& painter) const
 {
-	if (m_drawedVerts.size() >= 1)
+	if (length(m_drawedVerts) >= 1)
 	{
 		Vertex curve[4];
 		QPoint curve2d[4];
 
-		for (int i = 0; i < qMin (length(curve), m_drawedVerts.size()); ++i)
+		for (int i = 0; i < qMin (length(curve), length(m_drawedVerts)); ++i)
 			curve[i] = m_drawedVerts[i];
 
 		// Factor the cursor into the preview
-		if (m_drawedVerts.size() < 4)
-			curve[m_drawedVerts.size()] = getCursorVertex();
+		if (length(m_drawedVerts) < 4)
+			curve[length(m_drawedVerts)] = getCursorVertex();
 
 		// Default the control points to the first vertex position
-		if (m_drawedVerts.size() < 2)
+		if (length(m_drawedVerts) < 2)
 			curve[2] = curve[0];
 
-		if (m_drawedVerts.size() < 3)
+		if (length(m_drawedVerts) < 3)
 			curve[3] = curve[2];
 
 		for (int i = 0; i < length(curve); ++i)
 			curve2d[i] = renderer()->convert3dTo2d (curve[i]);
 
 		painter.setPen (QColor (0, 112, 112));
-		if (m_drawedVerts.size() >= 2)
+		if (length(m_drawedVerts) >= 2)
 			painter.drawLine (curve2d[0], curve2d[2]);
 
-		if (m_drawedVerts.size() >= 3)
+		if (length(m_drawedVerts) >= 3)
 			painter.drawLine (curve2d[1], curve2d[3]);
 
-		for (int i = 0; i < qMin (length(curve), m_drawedVerts.size() + 1); ++i)
+		for (int i = 0; i < qMin (length(curve), length(m_drawedVerts) + 1); ++i)
 		{
 			if (i < 2)
 				renderer()->drawPoint (painter, curve2d[i]);
@@ -84,7 +84,7 @@
 
 void CurveMode::endDraw()
 {
-	if (m_drawedVerts.size() == 4)
+	if (length(m_drawedVerts) == 4)
 	{
 		LDObjectList objs;
 		objs << LDSpawn<LDBezierCurve> (m_drawedVerts[0], m_drawedVerts[1], m_drawedVerts[2], m_drawedVerts[3]);
--- a/src/editmodes/drawMode.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editmodes/drawMode.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -38,7 +38,7 @@
 		poly << vert;
 
 	// Draw the cursor vertex as the last one in the list.
-	if (poly.size() < 4)
+	if (length(poly) < 4)
 		poly << getCursorVertex();
 
 	renderPolygon (painter, poly, true, true);
@@ -51,7 +51,7 @@
 	{
 		if (vert == pos)
 		{
-			if (m_drawedVerts.size() >= 2)
+			if (length(m_drawedVerts) >= 2)
 				endDraw();
 
 			return true;
@@ -67,7 +67,7 @@
 	QList<Vertex>& verts = m_drawedVerts;
 	LDObjectList objs;
 
-	switch (verts.size())
+	switch (length(verts))
 	{
 		case 2:
 		{
@@ -81,13 +81,13 @@
 		case 3:
 		case 4:
 		{
-			LDObject* obj = (verts.size() == 3) ?
+			LDObject* obj = (length(verts) == 3) ?
 				static_cast<LDObject*> (LDSpawn<LDTriangle>()) :
 				static_cast<LDObject*> (LDSpawn<LDQuad>());
 
 			obj->setColor (MainColor);
 
-			for (int i = 0; i < verts.size(); ++i)
+			for (int i = 0; i < length(verts); ++i)
 				obj->setVertex (i, verts[i]);
 
 			objs << obj;
--- a/src/editmodes/linePathMode.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editmodes/linePathMode.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -35,15 +35,15 @@
 
 	painter.setPen (renderer()->textPen());
 
-	if (points.size() == points3d.size())
+	if (length(points) == length(points3d))
 	{
-		for (int i = 0; i < points.size() - 1; ++i)
+		for (int i = 0; i < length(points) - 1; ++i)
 		{
 			painter.drawLine (QLineF (points[i], points[i + 1]));
 			drawLineLength (painter, points3d[i], points3d[i + 1], points[i], points[i + 1]);
 		}
 	
-		for (int i = 0; i < points.size(); ++i)
+		for (int i = 0; i < length(points); ++i)
 		{
 			const QPointF& point = points[i];
 			renderer()->drawPoint (painter, point);
@@ -82,7 +82,7 @@
 {
 	LDObjectList objs;
 
-	for (int i = 0; i < m_drawedVerts.size() - 1; ++i)
+	for (int i = 0; i < length(m_drawedVerts) - 1; ++i)
 	{
 		LDLine* line = LDSpawn<LDLine>();
 		line->setVertex (0, m_drawedVerts[i]);
--- a/src/editmodes/magicWandMode.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editmodes/magicWandMode.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -152,7 +152,7 @@
 				}
 			}
 
-			if (matches.size() < matchesneeded)
+			if (length(matches) < matchesneeded)
 				throw 0; // Not enough matches.
 
 			// Check if a boundary gets in between the objects.
--- a/src/editmodes/rectangleMode.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/editmodes/rectangleMode.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -33,13 +33,13 @@
 
 void RectangleMode::render (QPainter& painter) const
 {
-	renderPolygon (painter, (m_drawedVerts.size() > 0) ? m_rectangleVerts :
+	renderPolygon (painter, (length(m_drawedVerts) > 0) ? m_rectangleVerts :
 		QVector<Vertex> ({renderer()->position3D()}), true, false);
 }
 
 void RectangleMode::endDraw()
 {
-	if (m_drawedVerts.size() == 2)
+	if (length(m_drawedVerts) == 2)
 	{
 		LDQuad* quad = LDSpawn<LDQuad>();
 		updateRectVerts();
@@ -72,7 +72,7 @@
 	}
 
 	Vertex v0 = m_drawedVerts[0],
-		   v1 = (m_drawedVerts.size() >= 2) ? m_drawedVerts[1] : renderer()->position3D();
+		   v1 = (length(m_drawedVerts) >= 2) ? m_drawedVerts[1] : renderer()->position3D();
 
 	const Axis localx = renderer()->getCameraAxis (false),
 			   localy = renderer()->getCameraAxis (true),
--- a/src/glCompiler.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/glCompiler.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -265,11 +265,11 @@
 	}
 
 	glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]);
-	glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW);
+	glBufferData (GL_ARRAY_BUFFER, length(vbodata) * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW);
 	glBindBuffer (GL_ARRAY_BUFFER, 0);
 	CHECK_GL_ERROR();
 	m_vboChanged[vbonum] = false;
-	m_vboSizes[vbonum] = vbodata.size();
+	m_vboSizes[vbonum] = length(vbodata);
 }
 
 
--- a/src/ldDocument.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/ldDocument.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -49,7 +49,7 @@
 {
 	m_flags |= IsBeingDestroyed;
 
-	for (int i = 0; i < m_objects.size(); ++i)
+	for (int i = 0; i < length(m_objects); ++i)
 		m_objects[i]->destroy();
 
 	delete m_history;
@@ -294,7 +294,7 @@
 		data.append (subdata);
 
 		if (sizeptr)
-			*sizeptr += subdata.size();
+			*sizeptr += length(subdata);
 	}
 
 	QFile f (path);
@@ -326,8 +326,8 @@
 //
 static void CheckTokenCount (const QStringList& tokens, int num)
 {
-	if (tokens.size() != num)
-		throw QString (format ("Bad amount of tokens, expected %1, got %2", num, tokens.size()));
+	if (length(tokens) != num)
+		throw QString (format ("Bad amount of tokens, expected %1, got %2", num, length(tokens)));
 }
 
 // =============================================================================
@@ -395,7 +395,7 @@
 	{
 		QStringList tokens = line.split (" ", QString::SkipEmptyParts);
 
-		if (tokens.size() <= 0)
+		if (length(tokens) <= 0)
 		{
 			// Line was empty, or only consisted of whitespace
 			return LDSpawn<LDEmpty>();
@@ -415,7 +415,7 @@
 				QString commentTextSimplified (commentText.simplified());
 
 				// Handle BFC statements
-				if (tokens.size() > 2 and tokens[1] == "BFC")
+				if (length(tokens) > 2 and tokens[1] == "BFC")
 				{
 					for (BfcStatement statement : iterateEnum<BfcStatement>())
 					{
@@ -434,7 +434,7 @@
 						return LDSpawn<LDBfc> (BfcStatement::NoClip);
 				}
 
-				if (tokens.size() > 2 and tokens[1] == "!LDFORGE")
+				if (length(tokens) > 2 and tokens[1] == "!LDFORGE")
 				{
 					// Handle LDForge-specific types, they're embedded into comments too
 					if (tokens[2] == "OVERLAY")
@@ -605,7 +605,7 @@
 //
 int LDDocument::addObject (LDObject* obj)
 {
-	history()->add (new AddHistoryEntry (objects().size(), obj));
+	history()->add (new AddHistoryEntry (length(objects()), obj));
 	m_objects << obj;
 	addKnownVertices (obj);
 	obj->setDocument (this);
@@ -683,7 +683,7 @@
 //
 void LDDocument::setObjectAt (int idx, LDObject* obj)
 {
-	if (idx < 0 or idx >= m_objects.size())
+	if (idx < 0 or idx >= length(m_objects))
 		return;
 
 	// Mark this change to history
@@ -708,7 +708,7 @@
 //
 LDObject* LDDocument::getObject (int pos) const
 {
-	if (pos < m_objects.size())
+	if (pos < length(m_objects))
 		return m_objects[pos];
 	else
 		return nullptr;
@@ -718,7 +718,7 @@
 //
 int LDDocument::getObjectCount() const
 {
-	return objects().size();
+	return length(objects());
 }
 
 // =============================================================================
--- a/src/ldObject.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/ldObject.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -230,7 +230,7 @@
 
 	if (idx != -1 and not others.isEmpty())
 	{
-		for (int i = 1; i < others.size(); ++i)
+		for (int i = 1; i < length(others); ++i)
 			document()->insertObject (idx + i, others[i]);
 
 		document()->setObjectAt (idx, others[0]);
--- a/src/ldobjectiterator.h	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/ldobjectiterator.h	Sat Jan 28 14:01:19 2017 +0200
@@ -40,7 +40,7 @@
 
 	bool outOfBounds() const
 	{
-		return m_i < 0 or m_i >= m_list.size();
+		return m_i < 0 or m_i >= length(m_list);
 	}
 
 	T* get() const
--- a/src/ldpaths.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/ldpaths.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -55,7 +55,7 @@
 			QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
 			QStringList contents = dir.entryList (mustHave);
 	
-			if (contents.size() == mustHave.size())
+			if (length(contents) == length(mustHave))
 				m_error = "";
 			else
 				m_error = "That is not an LDraw directory! It must<br />have LDConfig.ldr, parts/ and p/.";
--- a/src/mainwindow.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/mainwindow.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -365,7 +365,7 @@
 		obj->destroy();
 
 	refresh();
-	return selCopy.size();
+	return length(selCopy);
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
@@ -719,7 +719,7 @@
 //
 void MainWindow::spawnContextMenu (const QPoint& position)
 {
-	const bool single = (selectedObjects().size() == 1);
+	const bool single = (length(selectedObjects()) == 1);
 	LDObject* singleObj = single ? selectedObjects().first() : nullptr;
 
 	bool hasSubfiles = false;
@@ -1277,7 +1277,7 @@
 void MainWindow::closeInitialDocument()
 {
 /*
-	if (m_documents.size() == 2 and
+	if (length(m_documents) == 2 and
 		m_documents[0]->name().isEmpty() and
 		not m_documents[1]->name().isEmpty() and
 		not m_documents[0]->hasUnsavedChanges())
--- a/src/messageLog.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/messageLog.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -78,7 +78,7 @@
 void MessageManager::addLine (QString line)
 {
 	// If there's too many entries, pop the excess out
-	while (m_lines.size() >= MaxMessages)
+	while (length(m_lines) >= MaxMessages)
 		m_lines.removeFirst();
 
 	m_lines << Line (line);
@@ -100,7 +100,7 @@
 
 	bool changed = false;
 
-	for (int i = 0; i < m_lines.size(); ++i)
+	for (int i = 0; i < length(m_lines); ++i)
 	{
 		bool lineChanged;
 
--- a/src/primitives.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/primitives.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -75,7 +75,7 @@
 		}
 
 		populateCategories();
-		print(tr("%1 primitives loaded.") + "\n", m_primitives.size());
+		print(tr("%1 primitives loaded.") + "\n", length(m_primitives));
 	}
 }
 
@@ -93,7 +93,7 @@
 			{
 				m_primitives = m_activeScanner->scannedPrimitives();
 				populateCategories();
-				print(tr("%1 primitives scanned"), m_primitives.size());
+				print(tr("%1 primitives scanned"), length(m_primitives));
 				delete m_activeScanner;
 				m_activeScanner = nullptr;
 			}
--- a/src/ringFinder.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/ringFinder.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -192,8 +192,8 @@
 {
 	// If one solution has less components than the other one, it is definitely
 	// better.
-	if (getComponents().size() != other->getComponents().size())
-		return getComponents().size() < other->getComponents().size();
+	if (length(getComponents()) != length(other->getComponents()))
+		return length(getComponents()) < length(other->getComponents());
 
 	// Calculate the maximum ring number. Since the solutions have equal
 	// ring counts, the solutions with lesser maximum rings should result
@@ -201,10 +201,10 @@
 	int maxA = 0,
 		maxB = 0;
 
-	for (int i = 0; i < getComponents().size(); ++i)
+	for (const Component& component : getComponents())
 	{
-		maxA = qMax (getComponents()[i].num, maxA);
-		maxB = qMax (other->getComponents()[i].num, maxB);
+		maxA = qMax (component.num, maxA);
+		maxB = qMax (component.num, maxB);
 	}
 
 	if (maxA != maxB)
--- a/src/toolsets/algorithmtoolset.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/toolsets/algorithmtoolset.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -74,7 +74,7 @@
 
 void AlgorithmToolset::editRaw()
 {
-	if (selectedObjects().size() != 1)
+	if (length(selectedObjects()) != 1)
 		return;
 
 	LDObject* obj = selectedObjects()[0];
@@ -431,7 +431,7 @@
 
 void AlgorithmToolset::subfileSelection()
 {
-	if (selectedObjects().size() == 0)
+	if (selectedObjects().isEmpty())
 		return;
 
 	QString			parentpath (currentDocument()->fullPath());
--- a/src/toolsets/basictoolset.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/toolsets/basictoolset.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -261,11 +261,11 @@
 
 void BasicToolset::edit()
 {
-	if (selectedObjects().size() != 1)
-		return;
-
-	LDObject* obj = selectedObjects().first();
-	AddObjectDialog::staticDialog (obj->type(), obj);
+	if (length(selectedObjects()) == 1)
+	{
+		LDObject* obj = selectedObjects().first();
+		AddObjectDialog::staticDialog (obj->type(), obj);
+	}
 }
 
 void BasicToolset::modeSelect()
--- a/src/toolsets/filetoolset.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/toolsets/filetoolset.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -158,7 +158,7 @@
 		{
 			QString contents = obj->asText();
 			QByteArray data = contents.toUtf8();
-			file.write(data, data.size());
+			file.write(data, length(data));
 			file.write("\r\n", 2);
 		}
 	}
--- a/src/toolsets/movetoolset.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/toolsets/movetoolset.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -35,8 +35,8 @@
 		return;
 
 	// If we move down, we need to iterate the array in reverse order.
-	int start = up ? 0 : (objs.size() - 1);
-	int end = up ? objs.size() : -1;
+	int start = up ? 0 : (length(objs) - 1);
+	int end = up ? length(objs) : -1;
 	int increment = up ? 1 : -1;
 	QSet<LDObject*> objsToCompile;
 	LDDocument* file = objs[0]->document();
@@ -48,7 +48,7 @@
 		int idx = obj->lineNumber();
 		int target = idx + (up ? -1 : 1);
 
-		if ((up and idx == 0) or (not up and idx == file->objects().size() - 1))
+		if ((up and idx == 0) or (not up and idx == length(file->objects()) - 1))
 		{
 			// One of the objects hit the extrema. If this happens, this should be the first
 			// object to be iterated on. Thus, nothing has changed yet and it's safe to just
--- a/src/toolsets/viewtoolset.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/toolsets/viewtoolset.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -254,21 +254,20 @@
 void ViewToolset::jumpTo()
 {
 	bool ok;
-	int defval = 0;
-	LDObject* obj;
+	int defaultValue = (length(selectedObjects()) == 1) ? selectedObjects()[0]->lineNumber() : 0;
+	int index = QInputDialog::getInt (nullptr, "Go to line", "Go to line:", defaultValue, 1, currentDocument()->getObjectCount(), 1, &ok);
 
-	if (selectedObjects().size() == 1)
-		defval = selectedObjects()[0]->lineNumber();
+	if (ok)
+	{
+		LDObject *object = currentDocument()->getObject(index - 1);
 
-	int idx = QInputDialog::getInt (nullptr, "Go to line", "Go to line:", defval,
-		1, currentDocument()->getObjectCount(), 1, &ok);
-
-	if (not ok or (obj = currentDocument()->getObject (idx - 1)) == nullptr)
-		return;
-
-	currentDocument()->clearSelection();
-	obj->select();
-	m_window->updateSelection();
+		if (object)
+		{
+			currentDocument()->clearSelection();
+			object->select();
+			m_window->updateSelection();
+		}
+	}
 }
 
 void ViewToolset::randomColors()
--- a/src/types/matrix.cpp	Sat Jan 28 13:49:09 2017 +0200
+++ b/src/types/matrix.cpp	Sat Jan 28 14:01:19 2017 +0200
@@ -57,7 +57,7 @@
  */
 Matrix::Matrix (const std::initializer_list<double>& values)
 {
-	if (values.size() == 9)
+	if (length(values) == 9)
 		memcpy (&m_values[0], values.begin(), sizeof m_values);
 }
 

mercurial