more work on 8-primitives

Sat, 24 Mar 2018 16:40:12 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 16:40:12 +0200
changeset 1340
ea1b3ea9a3ca
parent 1339
1f342d5abc85
child 1341
b68adf1b4641

more work on 8-primitives

src/lddocument.cpp file | annotate | diff | comparison | revisions
src/lddocument.h file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
src/widgets/headeredit.cpp file | annotate | diff | comparison | revisions
--- a/src/lddocument.cpp	Sat Mar 24 16:33:23 2018 +0200
+++ b/src/lddocument.cpp	Sat Mar 24 16:40:12 2018 +0200
@@ -571,3 +571,11 @@
 {
 	m_verticesOutdated = true;
 }
+
+decltype(LDHeader::license) LDHeader::defaultLicense()
+{
+	if (config::useCaLicense())
+		return LDHeader::CaLicense;
+	else
+		return LDHeader::UnspecifiedLicense;
+}
--- a/src/lddocument.h	Sat Mar 24 16:33:23 2018 +0200
+++ b/src/lddocument.h	Sat Mar 24 16:40:12 2018 +0200
@@ -65,6 +65,7 @@
 		CaLicense,
 		NonCaLicense
 	} license = UnspecifiedLicense;
+	static decltype(license) defaultLicense();
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(QFlags<LDHeader::Qualifier>)
--- a/src/primitives.cpp	Sat Mar 24 16:33:23 2018 +0200
+++ b/src/primitives.cpp	Sat Mar 24 16:40:12 2018 +0200
@@ -471,33 +471,35 @@
 	else
 		description = format("%1 %2", PrimitiveModel::typeName(spec.type), fraction);
 
-	// Prepend "Hi-Res" if 48/ primitive.
+	// Prepend "Hi-Res" or "Lo-Res" as appropriate.
 	if (spec.divisions == HighResolution)
 		description.insert (0, "Hi-Res ");
+	else if (spec.divisions == LowResolution)
+		description.insert (0, "Lo-Res ");
 
 	LDDocument* document = m_window->newDocument();
 	document->setDefaultName(fileName);
 
-	QString author = APPNAME;
-	QString license = "";
-	bool hires = (spec.divisions == HighResolution);
-
 	if (not config::defaultName().isEmpty())
 	{
-		license = preferredLicenseText();
-		author = format("%1 [%2]", config::defaultName(), config::defaultUser());
+		document->header.license = LDHeader::defaultLicense();
+		document->header.author = format("%1 [%2]", config::defaultName(), config::defaultUser());
+	}
+	else
+	{
+		document->header.author = APPNAME;
 	}
 
 	document->setFrozen(false);
-	document->history()->setIgnoring(false);
 	document->header.name = fileName;
 	document->header.description = description;
-	document->header.author = author;
 
-	if (hires)
+	if (spec.divisions == HighResolution)
 		document->header.type = LDHeader::Primitive_48;
+	else if (spec.divisions == LowResolution)
+		document->header.type = LDHeader::Primitive_8;
 	else
-		document->header.type = LDHeader::Primitive_8;
+		document->header.type = LDHeader::Primitive;
 
 	if (config::useCaLicense())
 		document->header.license = LDHeader::CaLicense;
@@ -506,7 +508,7 @@
 
 	document->setWinding(CounterClockwise);
 	spec.generateBody(*document);
-	document->addHistoryStep();
+	document->history()->setIgnoring(false);
 	return document;
 }
 
--- a/src/widgets/headeredit.cpp	Sat Mar 24 16:33:23 2018 +0200
+++ b/src/widgets/headeredit.cpp	Sat Mar 24 16:40:12 2018 +0200
@@ -187,17 +187,21 @@
 	LDHeader* header = &document->header;
 	this->m_model = document;
 	this->m_header = header;
-	this->ui.description->setText(header->description);
-	this->ui.author->setText(header->author);
-	this->ui.category->setCurrentIndex(::categories.indexOf(header->category));
-	this->ui.license->setCurrentIndex(static_cast<int>(header->license));
-	this->ui.alias->setChecked(header->qualfiers & LDHeader::Alias);
-	this->ui.physicalColor->setChecked(header->qualfiers & LDHeader::Physical_Color);
-	this->ui.flexibleSection->setChecked(header->qualfiers & LDHeader::Flexible_Section);
-	this->ui.cmdline->setText(header->cmdline);
-	this->ui.winding->setCurrentIndex(document->winding());
-	this->ui.keywords->document()->setPlainText(header->keywords);
-	this->ui.help->document()->setPlainText(header->help);
+	if (document->header.type != LDHeader::NoHeader)
+	{
+		this->ui.description->setText(header->description);
+		this->ui.author->setText(header->author);
+		this->ui.category->setCurrentIndex(::categories.indexOf(header->category));
+		this->ui.license->setCurrentIndex(static_cast<int>(header->license));
+		this->ui.alias->setChecked(header->qualfiers & LDHeader::Alias);
+		this->ui.physicalColor->setChecked(header->qualfiers & LDHeader::Physical_Color);
+		this->ui.flexibleSection->setChecked(header->qualfiers & LDHeader::Flexible_Section);
+		this->ui.cmdline->setText(header->cmdline);
+		this->ui.winding->setCurrentIndex(document->winding());
+		this->ui.keywords->document()->setPlainText(header->keywords);
+		this->ui.help->document()->setPlainText(header->help);
+		this->ui.type->setCurrentIndex(static_cast<int>(document->header.type) - 1);
+	}
 	this->headerHistoryModel->setHeader(header);
 	this->setEnabled(this->hasValidHeader());
 }

mercurial