Matrices are now input with 9 spinboxes instead of a MLCad-style line edit

Sat, 28 Jan 2017 17:45:00 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 28 Jan 2017 17:45:00 +0200
changeset 1071
ff4639b672ae
parent 1070
292c64cb2a75
child 1072
9ce9496427f2

Matrices are now input with 9 spinboxes instead of a MLCad-style line edit

CMakeLists.txt file | annotate | diff | comparison | revisions
src/addObjectDialog.cpp file | annotate | diff | comparison | revisions
src/addObjectDialog.h file | annotate | diff | comparison | revisions
src/matrixinput.cpp file | annotate | diff | comparison | revisions
src/matrixinput.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sat Jan 28 17:23:04 2017 +0200
+++ b/CMakeLists.txt	Sat Jan 28 17:45:00 2017 +0200
@@ -47,6 +47,7 @@
 	src/main.cpp
 	src/mainwindow.cpp
 	src/mathfunctions.cpp
+	src/matrixinput.cpp
 	src/messageLog.cpp
 	src/miscallenous.cpp
 	src/partdownloader.cpp
@@ -104,6 +105,7 @@
 	src/main.h
 	src/mainwindow.h
 	src/mathfunctions.h
+	src/matrixinput.h
 	src/messageLog.h
 	src/miscallenous.h
 	src/partdownloader.h
--- a/src/addObjectDialog.cpp	Sat Jan 28 17:23:04 2017 +0200
+++ b/src/addObjectDialog.cpp	Sat Jan 28 17:45:00 2017 +0200
@@ -32,6 +32,7 @@
 #include "dialogs/colorselector.h"
 #include "editHistory.h"
 #include "radioGroup.h"
+#include "matrixinput.h"
 #include "miscallenous.h"
 #include "primitives.h"
 
@@ -191,9 +192,7 @@
 	{
 		LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj);
 		QLabel* lb_matrix = new QLabel ("Matrix:");
-		le_matrix = new QLineEdit;
-		// le_matrix->setValidator (new QDoubleValidator);
-		Matrix defaultMatrix = Matrix::identity;
+		matrix = new MatrixInput;
 
 		if (mo)
 		{
@@ -201,13 +200,13 @@
 			{
 				dsb_coords[ax]->setValue (value);
 			});
-
-			defaultMatrix = mo->transformationMatrix();
+			matrix->setValue(mo->transformationMatrix());
 		}
+		else
+			matrix->setValue(Matrix::identity);
 
-		le_matrix->setText (defaultMatrix.toString());
 		layout->addWidget (lb_matrix, 4, 1);
-		layout->addWidget (le_matrix, 4, 2, 1, 3);
+		layout->addWidget (matrix, 4, 2, 1, 3);
 	}
 
 	if (defaults->isColored())
@@ -309,17 +308,7 @@
 		return;
 
 	if (type == OBJ_SubfileReference)
-	{
-		QStringList stringValues = dlg.le_matrix->text().split (" ", QString::SkipEmptyParts);
-
-		if (countof(stringValues) == 9)
-		{
-			int i = 0;
-
-			for (QString stringValue : stringValues)
-				transform.value(i++) = stringValue.toFloat();
-		}
-	}
+		transform = dlg.matrix->value();
 
 	switch (type)
 	{
--- a/src/addObjectDialog.h	Sat Jan 28 17:23:04 2017 +0200
+++ b/src/addObjectDialog.h	Sat Jan 28 17:45:00 2017 +0200
@@ -28,6 +28,7 @@
 class QLabel;
 class QTreeWidget;
 class QDoubleSpinBox;
+class MatrixInput;
 
 class AddObjectDialog : public QDialog
 {
@@ -55,7 +56,7 @@
 	QTreeWidget* tw_subfileList;
 	QLineEdit* le_subfileName;
 	QLabel* lb_subfileName;
-	QLineEdit* le_matrix;
+	MatrixInput* matrix;
 
 private:
 	void setButtonBackground (QPushButton* button, LDColor color);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/matrixinput.cpp	Sat Jan 28 17:45:00 2017 +0200
@@ -0,0 +1,118 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2017 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QGridLayout>
+#include "matrixinput.h"
+
+MatrixInput::MatrixInput(QWidget *parent) : QWidget(parent)
+{
+	QGridLayout* layout = new QGridLayout {this};
+	setLayout(layout);
+
+	for (int i = 0; i < 3; ++i)
+	for (int j = 0; j < 3; ++j)
+	{
+		_spinboxes[i * 3 + j] = new QDoubleSpinBox {this};
+		layout->addWidget(_spinboxes[i * 3 + j], i, j);
+	}
+}
+
+int MatrixInput::decimals() const
+{
+	return _spinboxes[0]->decimals();
+}
+
+double MatrixInput::maximum() const
+{
+	return _spinboxes[0]->maximum();
+}
+
+double MatrixInput::minimum() const
+{
+	return _spinboxes[0]->minimum();
+}
+
+QString MatrixInput::prefix() const
+{
+	return _spinboxes[0]->prefix();
+}
+
+void MatrixInput::setDecimals(int precision)
+{
+	for (QDoubleSpinBox* spinbox : _spinboxes)
+		spinbox->setDecimals(precision);
+}
+
+void MatrixInput::setMaximum(double maximum)
+{
+	for (QDoubleSpinBox* spinbox : _spinboxes)
+		spinbox->setMaximum(maximum);
+}
+
+void MatrixInput::setMinimum(double minimum)
+{
+	for (QDoubleSpinBox* spinbox : _spinboxes)
+		spinbox->setMinimum(minimum);
+}
+
+void MatrixInput::setPrefix(const QString& prefix)
+{
+	for (QDoubleSpinBox* spinbox : _spinboxes)
+		spinbox->setPrefix(prefix);
+}
+
+void MatrixInput::setRange(double minimum, double maximum)
+{
+	for (QDoubleSpinBox* spinbox : _spinboxes)
+		spinbox->setRange(minimum, maximum);
+}
+
+void MatrixInput::setSingleStep(double singleStep)
+{
+	for (QDoubleSpinBox* spinbox : _spinboxes)
+		spinbox->setSingleStep(singleStep);
+}
+
+void MatrixInput::setSuffix(const QString& suffix)
+{
+	for (QDoubleSpinBox* spinbox : _spinboxes)
+		spinbox->setSuffix(suffix);
+}
+
+QString MatrixInput::suffix()
+{
+	return _spinboxes[0]->suffix();
+}
+
+void MatrixInput::setValue(const Matrix& value)
+{
+	for (int i = 0; i < 3; ++i)
+	for (int j = 0; j < 3; ++j)
+		_spinboxes[i * 3 + j]->setValue(value(i, j));
+}
+
+Matrix MatrixInput::value()
+{
+	Matrix result;
+
+	for (int i = 0; i < 3; ++i)
+	for (int j = 0; j < 3; ++j)
+		result(i, j) = _spinboxes[i * 3 + j]->value();
+
+	return result;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/matrixinput.h	Sat Jan 28 17:45:00 2017 +0200
@@ -0,0 +1,49 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2017 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include "main.h"
+#include <QDoubleSpinBox>
+
+/*
+ * Models a 3×3 array of spinboxes for matrix input.
+ */
+class MatrixInput : public QWidget
+{
+	Q_OBJECT
+
+public:
+	explicit MatrixInput(QWidget *parent = 0);
+	int decimals() const;
+	double maximum() const;
+	double minimum() const;
+	QString prefix() const;
+	void setDecimals(int precision);
+	void setMaximum(double maximum);
+	void setMinimum(double minimum);
+	void setPrefix(const QString& prefix);
+	void setRange(double minimum, double maximum);
+	void setSingleStep(double singleStep);
+	void setSuffix(const QString& suffix);
+	QString suffix();
+	void setValue(const Matrix& value);
+	Matrix value();
+
+private:
+	QDoubleSpinBox* _spinboxes[9];
+};

mercurial