Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.

Sun, 29 Jan 2017 15:25:26 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 29 Jan 2017 15:25:26 +0200
changeset 1075
711c5fff384d
parent 1074
a62f810ca26f
child 1076
55cfa9e42d70

Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/addObjectDialog.cpp file | annotate | diff | comparison | revisions
src/addObjectDialog.h file | annotate | diff | comparison | revisions
src/editmodes/selectMode.cpp file | annotate | diff | comparison | revisions
src/glRenderer.cpp file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/toolsets/basictoolset.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sun Jan 29 15:18:40 2017 +0200
+++ b/CMakeLists.txt	Sun Jan 29 15:25:26 2017 +0200
@@ -27,7 +27,6 @@
 set_source_files_properties (${CMAKE_BINARY_DIR}/configuration.cpp PROPERTIES GENERATED TRUE)
 
 set (LDFORGE_SOURCES
-	src/addObjectDialog.cpp
 	src/basics.cpp
 	src/colors.cpp
 	src/crashCatcher.cpp
@@ -82,7 +81,6 @@
 )
 
 set (LDFORGE_HEADERS
-	src/addObjectDialog.h
 	src/basics.h
 	src/colors.h
 	src/crashCatcher.h
--- a/src/addObjectDialog.cpp	Sun Jan 29 15:18:40 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,389 +0,0 @@
-/*
- *  LDForge: LDraw parts authoring CAD
- *  Copyright (C) 2013 - 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 <QCheckBox>
-#include <QDialogButtonBox>
-#include <QSpinBox>
-#include <QLabel>
-#include <QListWidget>
-#include <QTreeWidget>
-#include <QLineEdit>
-#include <QPushButton>
-#include "mainwindow.h"
-#include "addObjectDialog.h"
-#include "ldDocument.h"
-#include "colors.h"
-#include "dialogs/colorselector.h"
-#include "editHistory.h"
-#include "radioGroup.h"
-#include "matrixinput.h"
-#include "miscallenous.h"
-#include "primitives.h"
-
-// =============================================================================
-//
-AddObjectDialog::AddObjectDialog (const LDObjectType type, LDObject* obj, QWidget* parent) :
-	QDialog (parent)
-{
-	setlocale (LC_ALL, "C");
-
-	int coordCount = 0;
-	QString typeName = LDObject::typeName (type);
-
-	switch (type)
-	{
-		case OBJ_Comment:
-		{
-			le_comment = new QLineEdit;
-
-			if (obj)
-				le_comment->setText (static_cast<LDComment*> (obj)->text());
-
-			le_comment->setMinimumWidth (384);
-		} break;
-
-		case OBJ_Line:
-		{
-			coordCount = 6;
-		} break;
-
-		case OBJ_Triangle:
-		{
-			coordCount = 9;
-		} break;
-
-		case OBJ_Quad:
-		case OBJ_CondLine:
-		{
-			coordCount = 12;
-		} break;
-
-		case OBJ_Bfc:
-		{
-			rb_bfcType = new RadioGroup ("Statement", {}, 0, Qt::Vertical);
-
-			for (BfcStatement statement : iterateEnum<BfcStatement>())
-			{
-				// Separate these in two columns
-				if (int(statement) == EnumLimits<BfcStatement>::Count / 2)
-					rb_bfcType->rowBreak();
-
-				rb_bfcType->addButton (LDBfc::statementToString(statement));
-			}
-
-			if (obj)
-				rb_bfcType->setValue ((int) static_cast<LDBfc*> (obj)->statement());
-		} break;
-
-		case OBJ_SubfileReference:
-		{
-			coordCount = 3;
-			tw_subfileList = new QTreeWidget();
-			tw_subfileList->setHeaderLabel (tr ("Primitives"));
-
-			QString defaultname;
-
-			if (obj)
-				defaultname = static_cast<LDSubfileReference*> (obj)->fileInfo()->name();
-
-			g_win->primitives()->populateTreeWidget(tw_subfileList, defaultname);
-			connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged()));
-			lb_subfileName = new QLabel ("File:");
-			le_subfileName = new QLineEdit;
-			le_subfileName->setFocus();
-
-			if (obj)
-			{
-				LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj);
-				le_subfileName->setText (ref->fileInfo()->name());
-			}
-		} break;
-
-		default:
-		{
-			Critical (format ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, typeName));
-		} return;
-	}
-
-	QPixmap icon = GetIcon (format ("add-%1", typeName));
-	LDObject* defaults = LDObject::getDefault (type);
-
-	lb_typeIcon = new QLabel;
-	lb_typeIcon->setPixmap (icon);
-
-	// Show a color edit dialog for the types that actually use the color
-	if (defaults->isColored())
-	{
-		if (obj)
-			m_color = obj->color();
-		else
-			m_color = (type == OBJ_CondLine or type == OBJ_Line) ? EdgeColor : MainColor;
-
-		pb_color = new QPushButton;
-		setButtonBackground (pb_color, m_color);
-		connect (pb_color, SIGNAL (clicked()), this, SLOT (slot_colorButtonClicked()));
-	}
-
-	for (int i = 0; i < coordCount; ++i)
-	{
-		dsb_coords[i] = new QDoubleSpinBox;
-		dsb_coords[i]->setDecimals (5);
-		dsb_coords[i]->setMinimum (-10000.0);
-		dsb_coords[i]->setMaximum (10000.0);
-	}
-
-	QGridLayout* const layout = new QGridLayout;
-	layout->addWidget (lb_typeIcon, 0, 0);
-
-	switch (type)
-	{
-		case OBJ_Line:
-		case OBJ_CondLine:
-		case OBJ_Triangle:
-		case OBJ_Quad:
-			// Apply coordinates
-			if (obj)
-			{
-				for (int i = 0; i < coordCount / 3; ++i)
-				{
-					obj->vertex (i).apply ([&](Axis ax, double value)
-					{
-						dsb_coords[(i * 3) + ax]->setValue (value);
-					});
-				}
-			}
-			break;
-
-		case OBJ_Comment:
-			layout->addWidget (le_comment, 0, 1);
-			break;
-
-		case OBJ_Bfc:
-			layout->addWidget (rb_bfcType, 0, 1);
-			break;
-
-		case OBJ_SubfileReference:
-			layout->addWidget (tw_subfileList, 1, 1, 1, 2);
-			layout->addWidget (lb_subfileName, 2, 1);
-			layout->addWidget (le_subfileName, 2, 2);
-			break;
-
-		default:
-			break;
-	}
-
-	if (defaults->hasMatrix())
-	{
-		LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj);
-		QLabel* lb_matrix = new QLabel ("Matrix:");
-		matrix = new MatrixInput;
-
-		if (mo)
-		{
-			mo->position().apply ([&](Axis ax, double value)
-			{
-				dsb_coords[ax]->setValue (value);
-			});
-			matrix->setValue(mo->transformationMatrix());
-		}
-		else
-			matrix->setValue(Matrix::identity);
-
-		layout->addWidget (lb_matrix, 4, 1);
-		layout->addWidget (matrix, 4, 2, 1, 3);
-	}
-
-	if (defaults->isColored())
-		layout->addWidget (pb_color, 1, 0);
-
-	if (coordCount > 0)
-	{
-		QGridLayout* const qCoordLayout = new QGridLayout;
-
-		for (int i = 0; i < coordCount; ++i)
-			qCoordLayout->addWidget (dsb_coords[i], (i / 3), (i % 3));
-
-		layout->addLayout (qCoordLayout, 0, 1, (coordCount / 3), 3);
-	}
-
-	QDialogButtonBox* bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
-	QWidget::connect (bbx_buttons, SIGNAL (accepted()), this, SLOT (accept()));
-	QWidget::connect (bbx_buttons, SIGNAL (rejected()), this, SLOT (reject()));
-	layout->addWidget (bbx_buttons, 5, 0, 1, 4);
-	setLayout (layout);
-	setWindowTitle (format (tr ("Edit %1"), typeName));
-	setWindowIcon (icon);
-}
-
-// =============================================================================
-// =============================================================================
-void AddObjectDialog::setButtonBackground (QPushButton* button, LDColor color)
-{
-	button->setIcon (GetIcon ("palette"));
-	button->setAutoFillBackground (true);
-
-	if (color.isValid())
-		button->setStyleSheet (format ("background-color: %1", color.hexcode()));
-}
-
-// =============================================================================
-// =============================================================================
-QString AddObjectDialog::currentSubfileName()
-{
-	PrimitiveTreeItem* item = static_cast<PrimitiveTreeItem*> (tw_subfileList->currentItem());
-
-	if (item->primitive() == nullptr)
-		return ""; // selected a heading
-
-	return item->primitive()->name;
-}
-
-// =============================================================================
-// =============================================================================
-void AddObjectDialog::slot_colorButtonClicked()
-{
-	ColorSelector::selectColor (this, m_color, m_color);
-	setButtonBackground (pb_color, m_color);
-}
-
-// =============================================================================
-// =============================================================================
-void AddObjectDialog::slot_subfileTypeChanged()
-{
-	QString name = currentSubfileName();
-
-	if (not name.isEmpty())
-		le_subfileName->setText (name);
-}
-
-// =============================================================================
-// =============================================================================
-template<typename T>
-static T* InitObject (LDObject*& obj)
-{
-	if (obj == nullptr)
-		obj = new T;
-
-	return static_cast<T*> (obj);
-}
-
-// =============================================================================
-// =============================================================================
-#include "documentmanager.h"
-void AddObjectDialog::staticDialog (const LDObjectType type, LDObject* obj)
-{
-	setlocale (LC_ALL, "C");
-
-	// FIXME: Redirect to Edit Raw
-	if (obj and obj->type() == OBJ_Error)
-		return;
-
-	if (type == OBJ_Empty)
-		return; // Nothing to edit with empties
-
-	const bool newObject = (obj == nullptr);
-	Matrix transform = Matrix::identity;
-	AddObjectDialog dlg (type, obj);
-
-	if (obj and obj->type() != type)
-		return;
-
-	if (dlg.exec() == QDialog::Rejected)
-		return;
-
-	if (type == OBJ_SubfileReference)
-		transform = dlg.matrix->value();
-
-	switch (type)
-	{
-		case OBJ_Comment:
-		{
-			LDComment* comm = InitObject<LDComment> (obj);
-			comm->setText (dlg.le_comment->text());
-		}
-		break;
-
-		case OBJ_Line:
-		case OBJ_Triangle:
-		case OBJ_Quad:
-		case OBJ_CondLine:
-		{
-			if (not obj)
-				obj = LDObject::getDefault (type);
-
-			for (int i = 0; i < obj->numVertices(); ++i)
-			{
-				Vertex v;
-
-				v.apply ([&](Axis ax, double& value)
-				{
-					value = dlg.dsb_coords[(i * 3) + ax]->value();
-				});
-
-				obj->setVertex (i, v);
-			}
-		} break;
-
-		case OBJ_Bfc:
-		{
-			LDBfc* bfc = InitObject<LDBfc> (obj);
-			int value = dlg.rb_bfcType->value();
-			if (valueInEnum<BfcStatement>(value))
-				bfc->setStatement(BfcStatement(value));
-		} break;
-
-		case OBJ_SubfileReference:
-		{
-			QString name = dlg.le_subfileName->text();
-
-			if (name.isEmpty())
-				return; // no subfile filename
-
-			LDDocument* document = g_win->documents()->getDocumentByName (name);
-
-			if (not document)
-			{
-				Critical (format ("Couldn't open `%1': %2", name, strerror (errno)));
-				return;
-			}
-
-			LDSubfileReference* ref = InitObject<LDSubfileReference> (obj);
-
-			for_axes (ax)
-				ref->setCoordinate (ax, dlg.dsb_coords[ax]->value());
-
-			ref->setTransformationMatrix (transform);
-			ref->setFileInfo (document);
-		} break;
-
-		default:
-			break;
-	}
-
-	if (obj->isColored())
-		obj->setColor (dlg.m_color);
-
-	if (newObject)
-	{
-		int idx = g_win->suggestInsertPoint();
-		g_win->currentDocument()->insertObject (idx, obj);
-	}
-
-	g_win->refresh();
-}
--- a/src/addObjectDialog.h	Sun Jan 29 15:18:40 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-/*
- *  LDForge: LDraw parts authoring CAD
- *  Copyright (C) 2013 - 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 <QDialog>
-#include "ldObject.h"
-
-class QTreeWidgetItem;
-class QLineEdit;
-class RadioGroup;
-class QCheckBox;
-class QSpinBox;
-class QLabel;
-class QTreeWidget;
-class QDoubleSpinBox;
-class MatrixInput;
-
-class AddObjectDialog : public QDialog
-{
-	Q_OBJECT
-
-public:
-	AddObjectDialog (const LDObjectType type, LDObject* obj, QWidget* parent = nullptr);
-	static void staticDialog (const LDObjectType type, LDObject* obj);
-
-	QLabel* lb_typeIcon;
-
-	// Comment line edit
-	QLineEdit* le_comment;
-
-	// Coordinate edits for.. anything with coordinates, really.
-	QDoubleSpinBox* dsb_coords[12];
-
-	// Color selection dialog button
-	QPushButton* pb_color;
-
-	// BFC-related widgets
-	RadioGroup* rb_bfcType;
-
-	// Subfile stuff
-	QTreeWidget* tw_subfileList;
-	QLineEdit* le_subfileName;
-	QLabel* lb_subfileName;
-	MatrixInput* matrix;
-
-private:
-	void setButtonBackground (QPushButton* button, LDColor color);
-	QString currentSubfileName();
-
-	LDColor m_color;
-
-private slots:
-	void slot_colorButtonClicked();
-	void slot_subfileTypeChanged();
-};
--- a/src/editmodes/selectMode.cpp	Sun Jan 29 15:18:40 2017 +0200
+++ b/src/editmodes/selectMode.cpp	Sun Jan 29 15:25:26 2017 +0200
@@ -19,7 +19,6 @@
 #include <QMouseEvent>
 #include "selectMode.h"
 #include "../glRenderer.h"
-#include "../addObjectDialog.h"
 #include "../mainwindow.h"
 #include "../glRenderer.h"
 
@@ -122,7 +121,7 @@
 
 		if (obj)
 		{
-			AddObjectDialog::staticDialog (obj->type(), obj);
+			// TODO:
 			m_window->endAction();
 			return true;
 		}
--- a/src/glRenderer.cpp	Sun Jan 29 15:18:40 2017 +0200
+++ b/src/glRenderer.cpp	Sun Jan 29 15:25:26 2017 +0200
@@ -36,7 +36,6 @@
 #include "miscallenous.h"
 #include "editHistory.h"
 #include "dialogs.h"
-#include "addObjectDialog.h"
 #include "messageLog.h"
 #include "glCompiler.h"
 #include "primitives.h"
--- a/src/mainwindow.cpp	Sun Jan 29 15:18:40 2017 +0200
+++ b/src/mainwindow.cpp	Sun Jan 29 15:25:26 2017 +0200
@@ -44,7 +44,6 @@
 #include "colors.h"
 #include "editHistory.h"
 #include "radioGroup.h"
-#include "addObjectDialog.h"
 #include "messageLog.h"
 #include "ui_mainwindow.h"
 #include "primitives.h"
@@ -819,8 +818,8 @@
 //
 void MainWindow::objectListDoubleClicked (QListWidgetItem* listitem)
 {
-	LDObject* object = m_objectsInList.reverseLookup (listitem);
-	AddObjectDialog::staticDialog (object->type(), object);
+	LDObject* object = m_objectsInList.reverseLookup(listitem);
+	// TODO: ...
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
--- a/src/toolsets/basictoolset.cpp	Sun Jan 29 15:18:40 2017 +0200
+++ b/src/toolsets/basictoolset.cpp	Sun Jan 29 15:25:26 2017 +0200
@@ -22,7 +22,6 @@
 #include <QDialogButtonBox>
 #include <QTextEdit>
 #include <QVBoxLayout>
-#include "../addObjectDialog.h"
 #include "../glRenderer.h"
 #include "../ldDocument.h"
 #include "../ldObject.h"
@@ -228,37 +227,37 @@
 
 void BasicToolset::newSubfile()
 {
-	AddObjectDialog::staticDialog (OBJ_SubfileReference, nullptr);
+	// TODO:
 }
 
 void BasicToolset::newLine()
 {
-	AddObjectDialog::staticDialog (OBJ_Line, nullptr);
+	// TODO:
 }
 
 void BasicToolset::newTriangle()
 {
-	AddObjectDialog::staticDialog (OBJ_Triangle, nullptr);
+	// TODO:
 }
 
 void BasicToolset::newQuadrilateral()
 {
-	AddObjectDialog::staticDialog (OBJ_Quad, nullptr);
+	// TODO:
 }
 
 void BasicToolset::newConditionalLine()
 {
-	AddObjectDialog::staticDialog (OBJ_CondLine, nullptr);
+	// TODO:
 }
 
 void BasicToolset::newComment()
 {
-	AddObjectDialog::staticDialog (OBJ_Comment, nullptr);
+	// TODO:
 }
 
 void BasicToolset::newBFC()
 {
-	AddObjectDialog::staticDialog (OBJ_Bfc, nullptr);
+	// TODO:
 }
 
 void BasicToolset::edit()
@@ -266,7 +265,7 @@
 	if (countof(selectedObjects()) == 1)
 	{
 		LDObject* obj = *selectedObjects().begin();
-		AddObjectDialog::staticDialog (obj->type(), obj);
+		// TODO:
 	}
 }
 

mercurial