added Save As function

Mon, 18 Mar 2013 13:16:21 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 18 Mar 2013 13:16:21 +0200
changeset 28
208adc847377
parent 27
2ba799d294bc
child 29
55406ce7446e

added Save As function

file.cpp file | annotate | diff | comparison | revisions
file.h file | annotate | diff | comparison | revisions
gldraw.cpp file | annotate | diff | comparison | revisions
gldraw.h file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
--- a/file.cpp	Mon Mar 18 12:24:16 2013 +0200
+++ b/file.cpp	Mon Mar 18 13:16:21 2013 +0200
@@ -154,13 +154,13 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void OpenFile::save (str zPath) {
+bool OpenFile::save (str zPath) {
 	if (!~zPath)
 		zPath = zFileName;
 	
 	FILE* fp = fopen (zPath, "w");
 	if (!fp)
-		return;
+		return false;
 	
 	// Write all entries now
 	for (ulong i = 0; i < objects.size(); ++i) {
@@ -173,6 +173,7 @@
 	}
 	
 	fclose (fp);
+	return true;
 }
 
 // =============================================================================
--- a/file.h	Mon Mar 18 12:24:16 2013 +0200
+++ b/file.h	Mon Mar 18 13:16:21 2013 +0200
@@ -20,7 +20,7 @@
 	void close ();
 	
 	// Saves this file to disk.
-	void save (str zPath = "");
+	bool save (str zPath = "");
 };
 
 // Close all current loaded files and start off blank.
--- a/gldraw.cpp	Mon Mar 18 12:24:16 2013 +0200
+++ b/gldraw.cpp	Mon Mar 18 13:16:21 2013 +0200
@@ -68,7 +68,7 @@
 	}
 	
 	for (ulong i = 0; i < g_CurrentFile->objects.size(); i++)
-		CompileOneObject (g_CurrentFile->objects[i]);
+		compileOneObject (g_CurrentFile->objects[i]);
 	
 	glEndList ();
 }
@@ -76,7 +76,7 @@
 #define GL_VERTEX(V) \
 	glVertex3d (V.x, V.y, V.z);
 
-void renderer::CompileOneObject (LDObject* obj) {
+void renderer::compileOneObject (LDObject* obj) {
 	if (!obj)
 		return;
 	
@@ -121,7 +121,7 @@
 	}
 }
 
-void renderer::ClampAngle (double& fAngle) {
+void renderer::clampAngle (double& fAngle) {
 	while (fAngle < 0)
 		fAngle += 360.0;
 	while (fAngle > 360.0)
@@ -135,15 +135,15 @@
 	if (event->buttons () & Qt::LeftButton) {
 		fRotX = fRotX + (dy);
 		fRotY = fRotY + (dx);
-		ClampAngle (fRotX);
-		ClampAngle (fRotY);
+		clampAngle (fRotX);
+		clampAngle (fRotY);
 	}
 	
 	if (event->buttons () & Qt::RightButton) {
 		fRotX = fRotX + (dy);
 		fRotZ = fRotZ + (dx);
-		ClampAngle (fRotX);
-		ClampAngle (fRotZ);
+		clampAngle (fRotX);
+		clampAngle (fRotZ);
 	}
 	
 	if (event->buttons () & Qt::MidButton) {
--- a/gldraw.h	Mon Mar 18 12:24:16 2013 +0200
+++ b/gldraw.h	Mon Mar 18 13:16:21 2013 +0200
@@ -25,8 +25,8 @@
 
 private:
 	GLuint objlist;
-	void CompileOneObject (LDObject* obj);
-	void ClampAngle (double& fAngle);
+	void compileOneObject (LDObject* obj);
+	void clampAngle (double& fAngle);
 };
 
 #endif // __GLDRAW_H__
\ No newline at end of file
--- a/gui.cpp	Mon Mar 18 12:24:16 2013 +0200
+++ b/gui.cpp	Mon Mar 18 13:16:21 2013 +0200
@@ -89,7 +89,6 @@
 	
 	// things not implemented yet
 	QAction* qaDisabledActions[] = {
-		qAct_saveAs,
 		qAct_newSubfile,
 		qAct_newTriangle,
 		qAct_newQuad,
@@ -197,10 +196,12 @@
 }
 
 void ForgeWindow::slot_open () {
-	str name = QFileDialog::getOpenFileName (this, "Open File",
-		"", "LDraw files (*.dat *.ldr)").toStdString().c_str();
+	str zName;
+	zName += QFileDialog::getOpenFileName (this, "Open File",
+		"", "LDraw files (*.dat *.ldr)");
 	
-	openMainFile (name);
+	if (~zName)
+		openMainFile (zName);
 }
 
 void ForgeWindow::slot_save () {
@@ -208,7 +209,12 @@
 }
 
 void ForgeWindow::slot_saveAs () {
+	str zName;
+	zName += QFileDialog::getSaveFileName (this, "Save As",
+		"", "LDraw files (*.dat *.ldr)");
 	
+	if (~zName && g_CurrentFile->save (zName))
+		g_CurrentFile->zFileName = zName;
 }
 
 void ForgeWindow::slot_exit () {

mercurial