Delete unused code

Wed, 20 Jul 2022 21:48:46 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 20 Jul 2022 21:48:46 +0300
changeset 338
719b909a7d2b
parent 337
5bb26aa33ad5
child 340
e17e07661f4c

Delete unused code
Remove Model legacy type alias, QTextDocument is used now instead

src/documentmanager.cpp file | annotate | diff | comparison | revisions
src/documentmanager.h file | annotate | diff | comparison | revisions
src/gl/compiler.cpp file | annotate | diff | comparison | revisions
src/gl/compiler.h file | annotate | diff | comparison | revisions
src/gl/partrenderer.cpp file | annotate | diff | comparison | revisions
src/gl/partrenderer.h file | annotate | diff | comparison | revisions
src/ldrawalgorithm.cpp file | annotate | diff | comparison | revisions
src/ldrawalgorithm.h file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/model.cpp file | annotate | diff | comparison | revisions
src/model.h file | annotate | diff | comparison | revisions
src/polygoncache.cpp file | annotate | diff | comparison | revisions
src/polygoncache.h file | annotate | diff | comparison | revisions
src/vertexmap.cpp file | annotate | diff | comparison | revisions
src/vertexmap.h file | annotate | diff | comparison | revisions
--- a/src/documentmanager.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/documentmanager.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -54,7 +54,7 @@
 	return modelId;
 }
 
-Model* DocumentManager::findDependencyByName(const ModelId modelId, const QString& name)
+QTextDocument* DocumentManager::findDependencyByName(const ModelId modelId, const QString& name)
 {
 	const auto modelsIterator = this->openModels.find(modelId);
 	if (modelsIterator != std::end(this->openModels)) {
@@ -78,7 +78,7 @@
  * @param modelId id of model to find
  * @returns model pointer or null
  */
-Model *DocumentManager::getModelById(ModelId modelId)
+QTextDocument *DocumentManager::getModelById(ModelId modelId)
 {
 	const auto iterator = this->openModels.find(modelId);
 	if (iterator != this->openModels.end())
@@ -228,7 +228,7 @@
  * @param model model to look for
  * @return id or no value if not found
  */
-std::optional<ModelId> DocumentManager::findIdForModel(const Model *model) const
+std::optional<ModelId> DocumentManager::findIdForModel(const QTextDocument *model) const
 {
 	std::optional<ModelId> result;
 	for (auto it = this->openModels.begin(); it != this->openModels.end(); ++it)
@@ -325,7 +325,7 @@
 
 void DocumentManager::makePolygonCacheForModel(const ModelId modelId)
 {
-	Model* model = this->getModelById(modelId);
+	QTextDocument* model = this->getModelById(modelId);
 	if (model != nullptr)
 	{
 		const auto modelModified = [this, model]{
@@ -358,7 +358,7 @@
 	return referencedFilePath;
 }
 
-static std::set<QString> referenceNames(const Model* model)
+static std::set<QString> referenceNames(const QTextDocument* model)
 {
 	std::set<QString> result;
 	for (const QString& line : model->toPlainText().split("\n")) {
--- a/src/documentmanager.h	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/documentmanager.h	Wed Jul 20 21:48:46 2022 +0300
@@ -48,8 +48,8 @@
 	auto begin() const { return this->openModels.begin(); }
 	auto end() const { return this->openModels.end(); }
 	ModelId newModel();
-	Model* findDependencyByName(const ModelId modelId, const QString& name);
-	Model* getModelById(ModelId modelId);
+	QTextDocument* findDependencyByName(const ModelId modelId, const QString& name);
+	QTextDocument* getModelById(ModelId modelId);
 	std::optional<ModelId> openModel(const QString& path, QTextStream& errorStream, const OpenType openType);
 	std::map<QString, QString> loadDependenciesForAllModels(const LibrariesModel &libraries);
 	void closeDocument(const ModelId modelId);
@@ -60,7 +60,7 @@
 			const LibrariesModel &libraries,
 			QTextStream &errorStream);
 	bool saveModel(const ModelId modelId, QTextStream& errors);
-	std::optional<ModelId> findIdForModel(const Model* model) const;
+	std::optional<ModelId> findIdForModel(const QTextDocument* model) const;
 	PolygonCache* getPolygonCacheForModel(ModelId modelId);
 	const ModelInfo* find(ModelId modelId) const;
 	void setModelPayload(ModelId modelId, QObject* object);
@@ -75,7 +75,7 @@
 private:
 	int modelIdCounter = 0;
 	std::map<ModelId, ModelInfo> openModels;
-	void collectReferences(QSet<QString> &referenced, const QString& name, const Model* model);
+	void collectReferences(QSet<QString> &referenced, const QString& name, const QTextDocument* model);
 	void updateDependencies(ModelInfo* model);
 	void prune();
 	void makePolygonCacheForModel(const ModelId modelId);
--- a/src/gl/compiler.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/gl/compiler.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -222,7 +222,7 @@
 }
 
 template<typename Fn>
-void iterateModelPolygons(Model* model, DocumentManager* context, Fn&& fn)
+void iterateModelPolygons(QTextDocument* model, DocumentManager* context, Fn&& fn)
 {
 	PolygonCache* const cache = findPolygonCacheForModel(model, context);
 	if (cache != nullptr) {
@@ -260,7 +260,7 @@
 /**
  * @brief Computes the minimum bounding box for a model
  */
-BoundingBox gl::boundingBoxForModel(Model* model, DocumentManager* context)
+BoundingBox gl::boundingBoxForModel(QTextDocument* model, DocumentManager* context)
 {
 	BoundingBox result = emptyBoundingBox;
 	iterateModelPolygons(model, context, [&](const PolygonElement& polygon)
@@ -277,7 +277,7 @@
  */
 void gl::build(
 	gl::ModelShaders* shaders,
-	Model* model,
+	QTextDocument* model,
 	const ColorTable& colorTable,
 	DocumentManager* context,
 	const gl::RenderPreferences& preferences)
--- a/src/gl/compiler.h	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/gl/compiler.h	Wed Jul 20 21:48:46 2022 +0300
@@ -72,7 +72,7 @@
 	};
 
 	void build(ModelShaders* shaders,
-		Model* model,
+		QTextDocument* model,
 		const ColorTable& colorTable,
 		DocumentManager* context,
 		const RenderPreferences& preferences);
@@ -114,7 +114,7 @@
 		setShaderUniform(shaders, uniformName, value.x, value.y, value.z, value.w);
 	}
 
-	BoundingBox boundingBoxForModel(Model* model, DocumentManager* context);
+	BoundingBox boundingBoxForModel(QTextDocument* model, DocumentManager* context);
 }
 
 #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); }
--- a/src/gl/partrenderer.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/gl/partrenderer.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -35,7 +35,7 @@
 static constexpr double MAX_ZOOM = 3.0;
 
 PartRenderer::PartRenderer(
-	Model* model,
+	QTextDocument* model,
 	DocumentManager* documents,
 	const ColorTable& colorTable,
 	QWidget* parent) :
--- a/src/gl/partrenderer.h	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/gl/partrenderer.h	Wed Jul 20 21:48:46 2022 +0300
@@ -9,7 +9,7 @@
 class PartRenderer final : public QOpenGLWidget
 {
 	Q_OBJECT
-	Model* const model;
+	QTextDocument* const model;
 	DocumentManager* const documents;
 	const ColorTable& colorTable;
 	BoundingBox boundingBox;
@@ -32,7 +32,7 @@
 	bool frozen = false;
 public:
 	PartRenderer(
-		Model* model,
+		QTextDocument* model,
 		DocumentManager* documents,
 		const ColorTable& colorTable,
 		QWidget* parent = nullptr);
--- a/src/ldrawalgorithm.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/ldrawalgorithm.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -18,7 +18,7 @@
 	return result;
 }
 
-std::vector<ModelAction> ldraw::makeUnofficial(const Model* model)
+std::vector<ModelAction> ldraw::makeUnofficial(const QTextDocument* model)
 {
 	std::vector<ModelAction> actions;
 	constexpr int ldrawOrgLinePosition = 3;
--- a/src/ldrawalgorithm.h	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/ldrawalgorithm.h	Wed Jul 20 21:48:46 2022 +0300
@@ -15,7 +15,7 @@
 		const Quadrilateral& q,
 		ldraw::Diagonal diagonal);
 
-	std::vector<ModelAction> makeUnofficial(const Model *model);
+	std::vector<ModelAction> makeUnofficial(const QTextDocument *model);
 
 	constexpr float circleAngle(unsigned int divisions, unsigned int i)
 	{
--- a/src/main.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/main.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -53,7 +53,7 @@
 	std::unique_ptr<AxesLayer> axesLayer;
 	std::unique_ptr<GridLayer> gridLayer;
 	std::unique_ptr<QTextCursor> textcursor;
-	Model* model;
+	QTextDocument* model;
 };
 
 class Signal final : public QObject
@@ -169,16 +169,6 @@
 	}
 }
 
-static Model* currentModelBody(Ui_MainWindow* ui, DocumentManager* documents)
-{
-	if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
-		return documents->getModelById(activeSubWindow->modelId);
-	}
-	else {
-		return nullptr;
-	}
-}
-
 static std::optional<ModelId> findCurrentModelId(Ui_MainWindow* ui)
 {
 	ModelSubWindow* activeSubWindow = qobject_cast<ModelSubWindow*>(ui->mdiArea->activeSubWindow());
@@ -332,15 +322,6 @@
 	}
 }
 
-static QFont monospace()
-{
-	QFont font{"Monospace"};
-	font.setStyleHint(QFont::TypeWriter);
-	font.setPointSize(10);
-	font.setFixedPitch(true);
-	return font;
-}
-
 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b)
 {
 	return a.row() < b.row();
@@ -409,17 +390,6 @@
 	return subWindow;
 }
 
-static QSet<ElementId> resolveIdsFromSelection(const ModelData* data)
-{
-//	const auto selection = data->itemSelectionModel->selection();
-	QSet<ElementId> selectedIndexes;
-/*	for (const QModelIndex& qindex : selection.indexes()) {
-		const std::size_t row = unsigned_cast(qindex.row());
-		selectedIndexes.insert(data->model->idAt(row));
-	}
-*/	return selectedIndexes;
-}
-
 int main(int argc, char *argv[])
 {
 	doQtRegistrations();
@@ -469,7 +439,7 @@
 		}
 	};
 	const auto executeAction = [&](
-		Model* model, const ModelAction& action
+		QTextDocument* model, const ModelAction& action
 	) {
 		std::visit(overloaded{
 			[model](const AppendToModel& action){
@@ -519,7 +489,7 @@
 		updateRecentlyOpenedDocumentsMenu();
 	};
 	const auto openModelForEditing = [&](const ModelId modelId){
-		Model* model = documents.getModelById(modelId);
+		QTextDocument* model = documents.getModelById(modelId);
 		if (model != nullptr) {
 			ModelData* data = new ModelData(&documents);
 			data->tools = std::make_unique<EditTools>();
@@ -756,7 +726,7 @@
 		&QAction::triggered,
 		[&]{
 			if (ModelData* data = currentModelData(&ui, &documents)) {
-				Model* const model = data->model;
+				QTextDocument* const model = data->model;
 				for (const ModelAction& action : ldraw::makeUnofficial(model)) {
 					executeAction(model, action);
 				}
--- a/src/model.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/model.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -179,7 +179,7 @@
  * @brief Sets the path to the model
  * @param path New path to use
  */
-void updateHeaderNameField(Model& model, const QString &name)
+void updateHeaderNameField(QTextDocument& model, const QString &name)
 {
 #if 0
 	// Update the "Name: 1234.dat" comment
--- a/src/model.h	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/model.h	Wed Jul 20 21:48:46 2022 +0300
@@ -21,9 +21,7 @@
 #include <memory>
 #include "src/basics.h"
 #include "src/colors.h"
-
 #include <QTextDocument>
-using Model = QTextDocument;
 
 struct SubfileReference
 {
--- a/src/polygoncache.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/polygoncache.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -4,7 +4,7 @@
 #include "src/polygoncache.h"
 #include "src/parser.h"
 
-Model* resolve(const QString& name, const ModelId callingModelId, DocumentManager* documents)
+QTextDocument* resolve(const QString& name, const ModelId callingModelId, DocumentManager* documents)
 {
 	return documents->findDependencyByName(callingModelId, name);
 }
@@ -19,7 +19,7 @@
 	return element;
 }
 
-PolygonCache* findPolygonCacheForModel(Model* model, DocumentManager* context)
+PolygonCache* findPolygonCacheForModel(QTextDocument* model, DocumentManager* context)
 {
 	std::optional<ModelId> modelId = context->findIdForModel(model);
 	if (modelId.has_value()) {
@@ -74,7 +74,7 @@
 	}
 }
 
-static Model* findDependency(const SubfileReference& ref, GetPolygonsContext* context)
+static QTextDocument* findDependency(const SubfileReference& ref, GetPolygonsContext* context)
 {
 	return context->documents->findDependencyByName(context->modelId, ref.name);
 }
@@ -118,7 +118,7 @@
 			add({line5.value, line5.value.color});
 		},
 		[&add, context, &reserve](const LineType1& line1) {
-			Model* const dependency = findDependency(line1.value, context);
+			QTextDocument* const dependency = findDependency(line1.value, context);
 			if (PolygonCache* cache = (dependency != nullptr)
 				? findPolygonCacheForModel(dependency, context->documents)
 				: nullptr
@@ -144,7 +144,7 @@
 }
 
 static std::vector<WithId<PolygonElement>> inlinePolygons(
-	const Model* model,
+	const QTextDocument* model,
 	GetPolygonsContext* context)
 {
 	Winding winding = NoWinding;
@@ -169,7 +169,7 @@
 	return result;
 }
 
-void recacheIfNeeded(PolygonCache *cache, Model *model, DocumentManager *documents)
+void recacheIfNeeded(PolygonCache *cache, QTextDocument *model, DocumentManager *documents)
 {
 	if (cache->needRecache)
 	{
--- a/src/polygoncache.h	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/polygoncache.h	Wed Jul 20 21:48:46 2022 +0300
@@ -19,6 +19,6 @@
 
 void recacheIfNeeded(
 	PolygonCache* cache,
-	Model* model,
+	QTextDocument* model,
 	class DocumentManager* documents);
 PolygonCache* findPolygonCacheForModel(QTextDocument* model, DocumentManager* context);
--- a/src/vertexmap.cpp	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/vertexmap.cpp	Wed Jul 20 21:48:46 2022 +0300
@@ -10,7 +10,7 @@
 	});
 }
 
-VertexMap::VertexMap(const Model *model) :
+VertexMap::VertexMap(const QTextDocument *model) :
 	model{model}
 {
 	this->build();
--- a/src/vertexmap.h	Wed Jul 20 21:35:55 2022 +0300
+++ b/src/vertexmap.h	Wed Jul 20 21:48:46 2022 +0300
@@ -19,13 +19,13 @@
 		glm::mat4 transform;
 	};
 	using ApplyFunction = std::function<void(const glm::vec3&, const VertexInfo&)>;
-	VertexMap(const Model *model);
+	VertexMap(const QTextDocument *model);
 	Q_SLOT void build();
 	void apply(ApplyFunction fn) const;
 Q_SIGNALS:
 	Q_SIGNAL void verticesChanged();
 private:
-	const Model* const model;
+	const QTextDocument* const model;
 	QSet<hash_t> vertexHashes;
 	std::vector<glm::vec3> vertices;
 	std::map<hash_t, VertexInfo> map;

mercurial