src/addObjectDialog.cpp

changeset 1217
314e12e23c3a
parent 1011
4fdd74a04790
child 1219
8e39b5d7c562
--- a/src/addObjectDialog.cpp	Thu Jan 04 19:40:52 2018 +0200
+++ b/src/addObjectDialog.cpp	Thu Jan 04 19:44:26 2018 +0200
@@ -37,24 +37,24 @@
 
 // =============================================================================
 //
-AddObjectDialog::AddObjectDialog (const LDObjectType type, LDObject* obj, QWidget* parent) :
-	QDialog (parent)
+AddObjectDialog::AddObjectDialog(const LDObjectType type, LDObject* obj, QWidget* parent) :
+	QDialog(parent)
 {
-	setlocale (LC_ALL, "C");
+	setlocale(LC_ALL, "C");
 
 	int coordCount = 0;
-	QString typeName = LDObject::typeName (type);
+	QString typeName = LDObject::typeName(type);
 
-	switch (type)
+	switch(type)
 	{
 		case OBJ_Comment:
 		{
 			le_comment = new QLineEdit;
 
 			if (obj)
-				le_comment->setText (static_cast<LDComment*> (obj)->text());
+				le_comment->setText(static_cast<LDComment*>(obj)->text());
 
-			le_comment->setMinimumWidth (384);
+			le_comment->setMinimumWidth(384);
 		} break;
 
 		case OBJ_Line:
@@ -75,51 +75,51 @@
 
 		case OBJ_Bfc:
 		{
-			rb_bfcType = new RadioGroup ("Statement", {}, 0, Qt::Vertical);
+			rb_bfcType = new RadioGroup("Statement", {}, 0, Qt::Vertical);
 
-			for_enum (BfcStatement, i)
+			for_enum(BfcStatement, i)
 			{
 				// Separate these in two columns
-				if (int (i) == int (BfcStatement::NumValues) / 2)
+				if (int(i) == int(BfcStatement::NumValues) / 2)
 					rb_bfcType->rowBreak();
 
-				rb_bfcType->addButton (LDBfc::statementToString (i));
+				rb_bfcType->addButton(LDBfc::statementToString(i));
 			}
 
 			if (obj)
-				rb_bfcType->setValue ((int) static_cast<LDBfc*> (obj)->statement());
+				rb_bfcType->setValue((int) static_cast<LDBfc*>(obj)->statement());
 		} break;
 
 		case OBJ_SubfileReference:
 		{
 			coordCount = 3;
 			tw_subfileList = new QTreeWidget();
-			tw_subfileList->setHeaderLabel (tr ("Primitives"));
-			populatePrimitivesTree (tw_subfileList, (obj ? static_cast<LDSubfileReference*> (obj)->fileInfo()->name() : ""));
+			tw_subfileList->setHeaderLabel(tr("Primitives"));
+			populatePrimitivesTree(tw_subfileList,(obj ? static_cast<LDSubfileReference*>(obj)->fileInfo()->name() : ""));
 
-			connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged()));
-			lb_subfileName = new QLabel ("File:");
+			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());
+				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));
+			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);
+	QPixmap icon = GetIcon(format("add-%1", typeName));
+	LDObject* defaults = LDObject::getDefault(type);
 
 	lb_typeIcon = new QLabel;
-	lb_typeIcon->setPixmap (icon);
+	lb_typeIcon->setPixmap(icon);
 
 	// Show a color edit dialog for the types that actually use the color
 	if (defaults->isColored())
@@ -130,22 +130,22 @@
 			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()));
+		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);
+		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);
+	layout->addWidget(lb_typeIcon, 0, 0);
 
-	switch (type)
+	switch(type)
 	{
 		case OBJ_Line:
 		case OBJ_CondLine:
@@ -156,26 +156,26 @@
 			{
 				for (int i = 0; i < coordCount / 3; ++i)
 				{
-					obj->vertex (i).apply ([&](Axis ax, double value)
+					obj->vertex(i).apply([&](Axis ax, double value)
 					{
-						dsb_coords[(i * 3) + ax]->setValue (value);
+						dsb_coords[(i * 3) + ax]->setValue(value);
 					});
 				}
 			}
 			break;
 
 		case OBJ_Comment:
-			layout->addWidget (le_comment, 0, 1);
+			layout->addWidget(le_comment, 0, 1);
 			break;
 
 		case OBJ_Bfc:
-			layout->addWidget (rb_bfcType, 0, 1);
+			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);
+			layout->addWidget(tw_subfileList, 1, 1, 1, 2);
+			layout->addWidget(lb_subfileName, 2, 1);
+			layout->addWidget(le_subfileName, 2, 2);
 			break;
 
 		default:
@@ -184,65 +184,65 @@
 
 	if (defaults->hasMatrix())
 	{
-		LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj);
-		QLabel* lb_matrix = new QLabel ("Matrix:");
+		LDMatrixObject* mo = dynamic_cast<LDMatrixObject*>(obj);
+		QLabel* lb_matrix = new QLabel("Matrix:");
 		le_matrix = new QLineEdit;
-		// le_matrix->setValidator (new QDoubleValidator);
+		// le_matrix->setValidator(new QDoubleValidator);
 		Matrix defaultMatrix = IdentityMatrix;
 
 		if (mo)
 		{
-			mo->position().apply ([&](Axis ax, double value)
+			mo->position().apply([&](Axis ax, double value)
 			{
-				dsb_coords[ax]->setValue (value);
+				dsb_coords[ax]->setValue(value);
 			});
 
 			defaultMatrix = mo->transform();
 		}
 
-		le_matrix->setText (defaultMatrix.toString());
-		layout->addWidget (lb_matrix, 4, 1);
-		layout->addWidget (le_matrix, 4, 2, 1, 3);
+		le_matrix->setText(defaultMatrix.toString());
+		layout->addWidget(lb_matrix, 4, 1);
+		layout->addWidget(le_matrix, 4, 2, 1, 3);
 	}
 
 	if (defaults->isColored())
-		layout->addWidget (pb_color, 1, 0);
+		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));
+			qCoordLayout->addWidget(dsb_coords[i],(i / 3),(i % 3));
 
-		layout->addLayout (qCoordLayout, 0, 1, (coordCount / 3), 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);
+	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)
+void AddObjectDialog::setButtonBackground(QPushButton* button, LDColor color)
 {
-	button->setIcon (GetIcon ("palette"));
-	button->setAutoFillBackground (true);
+	button->setIcon(GetIcon("palette"));
+	button->setAutoFillBackground(true);
 
 	if (color.isValid())
-		button->setStyleSheet (format ("background-color: %1", color.hexcode()));
+		button->setStyleSheet(format("background-color: %1", color.hexcode()));
 }
 
 // =============================================================================
 // =============================================================================
 QString AddObjectDialog::currentSubfileName()
 {
-	PrimitiveTreeItem* item = static_cast<PrimitiveTreeItem*> (tw_subfileList->currentItem());
+	PrimitiveTreeItem* item = static_cast<PrimitiveTreeItem*>(tw_subfileList->currentItem());
 
 	if (item->primitive() == nullptr)
 		return ""; // selected a heading
@@ -254,8 +254,8 @@
 // =============================================================================
 void AddObjectDialog::slot_colorButtonClicked()
 {
-	ColorSelector::selectColor (this, m_color, m_color);
-	setButtonBackground (pb_color, m_color);
+	ColorSelector::selectColor(this, m_color, m_color);
+	setButtonBackground(pb_color, m_color);
 }
 
 // =============================================================================
@@ -265,26 +265,26 @@
 	QString name = currentSubfileName();
 
 	if (name.length() > 0)
-		le_subfileName->setText (name);
+		le_subfileName->setText(name);
 }
 
 // =============================================================================
 // =============================================================================
 template<typename T>
-static T* InitObject (LDObject*& obj)
+static T* InitObject(LDObject*& obj)
 {
 	if (obj == nullptr)
 		obj = new T;
 
-	return static_cast<T*> (obj);
+	return static_cast<T*>(obj);
 }
 
 // =============================================================================
 // =============================================================================
 #include "documentmanager.h"
-void AddObjectDialog::staticDialog (const LDObjectType type, LDObject* obj)
+void AddObjectDialog::staticDialog(const LDObjectType type, LDObject* obj)
 {
-	setlocale (LC_ALL, "C");
+	setlocale(LC_ALL, "C");
 
 	// FIXME: Redirect to Edit Raw
 	if (obj and obj->type() == OBJ_Error)
@@ -295,7 +295,7 @@
 
 	const bool newObject = (obj == nullptr);
 	Matrix transform = IdentityMatrix;
-	AddObjectDialog dlg (type, obj);
+	AddObjectDialog dlg(type, obj);
 
 	if (obj and obj->type() != type)
 		return;
@@ -305,7 +305,7 @@
 
 	if (type == OBJ_SubfileReference)
 	{
-		QStringList matrixstrvals = dlg.le_matrix->text().split (" ", QString::SkipEmptyParts);
+		QStringList matrixstrvals = dlg.le_matrix->text().split(" ", QString::SkipEmptyParts);
 
 		if (matrixstrvals.size() == 9)
 		{
@@ -315,16 +315,16 @@
 			for (QString val : matrixstrvals)
 				matrixvals[i++] = val.toFloat();
 
-			transform = Matrix (matrixvals);
+			transform = Matrix(matrixvals);
 		}
 	}
 
-	switch (type)
+	switch(type)
 	{
 		case OBJ_Comment:
 		{
-			LDComment* comm = InitObject<LDComment> (obj);
-			comm->setText (dlg.le_comment->text());
+			LDComment* comm = InitObject<LDComment>(obj);
+			comm->setText(dlg.le_comment->text());
 		}
 		break;
 
@@ -334,27 +334,27 @@
 		case OBJ_CondLine:
 		{
 			if (not obj)
-				obj = LDObject::getDefault (type);
+				obj = LDObject::getDefault(type);
 
 			for (int i = 0; i < obj->numVertices(); ++i)
 			{
 				Vertex v;
 
-				v.apply ([&](Axis ax, double& value)
+				v.apply([&](Axis ax, double& value)
 				{
 					value = dlg.dsb_coords[(i * 3) + ax]->value();
 				});
 
-				obj->setVertex (i, v);
+				obj->setVertex(i, v);
 			}
 		} break;
 
 		case OBJ_Bfc:
 		{
-			LDBfc* bfc = InitObject<LDBfc> (obj);
+			LDBfc* bfc = InitObject<LDBfc>(obj);
 			int value = dlg.rb_bfcType->value();
-			if (value == qBound (0, value, int (BfcStatement::NumValues) - 1))
-				bfc->setStatement (BfcStatement (dlg.rb_bfcType->value()));
+			if (value == qBound(0, value, int(BfcStatement::NumValues) - 1))
+				bfc->setStatement(BfcStatement(dlg.rb_bfcType->value()));
 		} break;
 
 		case OBJ_SubfileReference:
@@ -364,21 +364,21 @@
 			if (name.length() == 0)
 				return; // no subfile filename
 
-			LDDocument* document = g_win->documents()->getDocumentByName (name);
+			LDDocument* document = g_win->documents()->getDocumentByName(name);
 
 			if (not document)
 			{
-				Critical (format ("Couldn't open `%1': %2", name, strerror (errno)));
+				Critical(format("Couldn't open `%1': %2", name, strerror(errno)));
 				return;
 			}
 
-			LDSubfileReference* ref = InitObject<LDSubfileReference> (obj);
+			LDSubfileReference* ref = InitObject<LDSubfileReference>(obj);
 
-			for_axes (ax)
-				ref->setCoordinate (ax, dlg.dsb_coords[ax]->value());
+			for_axes(ax)
+				ref->setCoordinate(ax, dlg.dsb_coords[ax]->value());
 
-			ref->setTransform (transform);
-			ref->setFileInfo (document);
+			ref->setTransform(transform);
+			ref->setFileInfo(document);
 		} break;
 
 		default:
@@ -386,12 +386,12 @@
 	}
 
 	if (obj->isColored())
-		obj->setColor (dlg.m_color);
+		obj->setColor(dlg.m_color);
 
 	if (newObject)
 	{
 		int idx = g_win->suggestInsertPoint();
-		g_win->currentDocument()->insertObj (idx, obj);
+		g_win->currentDocument()->insertObj(idx, obj);
 	}
 
 	g_win->refresh();

mercurial