Sfoglia il codice sorgente

Added default name to save file

Rémi Synave 2 anni fa
parent
commit
ad2bbce7e9
2 ha cambiato i file con 10 aggiunte e 8 eliminazioni
  1. 7 8
      dsl/MainWindow.cpp
  2. 3 0
      dsl/MainWindow.hpp

+ 7 - 8
dsl/MainWindow.cpp

@@ -4,6 +4,7 @@
 #include <QMenuBar>
 #include <QFileDialog>
 #include <QUrl>
+#include <QFileInfo>
 
 #include <QDebug>
 
@@ -32,12 +33,11 @@ MainWindow::MainWindow ()
 void
 MainWindow::open ()
 {
-  QString filename = QFileDialog::getOpenFileName (this,
+  filename = QFileDialog::getOpenFileName (this,
 						   QObject::
 						   tr ("Open image file"),
 						   QDir::currentPath (),
 						   QObject::tr("Images files (*.jpg *.png);;All files (*.*)"));
-  
   QDir::setCurrent(QString(filename).remove(QUrl(filename).fileName()));
   wa->loadImage (filename.toStdString ());
   setFixedSize (wa->geometry().width(), wa->geometry().height()+wa->geometry().y());
@@ -46,14 +46,13 @@ MainWindow::open ()
 void
 MainWindow::save ()
 {
-  //QFileInfo
-  QString filename = QFileDialog::getSaveFileName (this,
+  QString fileToSave = QFileDialog::getSaveFileName (this,
 						   QObject::tr ("Save file"),
-						   QDir::currentPath ().append("/test.json"),
+						   QDir::currentPath ().append("/").append(QFileInfo(filename).baseName()).append(".json"),
 						   QObject::tr("JSON file (*.json);;All files (*.*)"));
-  if(!filename.endsWith(".json"))
-    filename.append(".json");
-  wa->saveStrengthLine (filename.toStdString ());
+  if(!fileToSave.endsWith(".json"))
+    fileToSave.append(".json");
+  wa->saveStrengthLine (fileToSave.toStdString ());
 }
 
 

+ 3 - 0
dsl/MainWindow.hpp

@@ -4,6 +4,7 @@
 #include <QMainWindow>
 #include <QAction>
 #include <QMenu>
+#include <QString>
 
 #include "WorkArea.hpp"
 
@@ -22,6 +23,8 @@ private:
 
   WorkArea *wa;
 
+  QString filename;
+
   void createActions ();
   void createMenus ();