Browse Source

Ajout de l'autosave pour DSL

Rémi Synave 9 months ago
parent
commit
0f6ccab5fc
2 changed files with 24 additions and 1 deletions
  1. 21 1
      dsl/MainWindow.cpp
  2. 3 0
      dsl/MainWindow.hpp

+ 21 - 1
dsl/MainWindow.cpp

@@ -52,6 +52,7 @@ MainWindow::MainWindow ()
   suffix = NULL;
   filenames = NULL;
   autoLoad = true;
+  autoSave = false;
 
   setWindowTitle (tr ("DSL - Draw Strength Line"));
 
@@ -143,7 +144,12 @@ QMessageBox::StandardButton
 MainWindow::checkModificationinProgress()
 {
   if(wa->getModificationInProgress())
-    return QMessageBox::question(this, "Modification in progress", "Do you really want to change the image ? Modifications in progress will be lost.");
+    {
+      if(autoSave)
+	this->save();
+      else
+	return QMessageBox::question(this, "Modification in progress", "Do you really want to change the image ? Modifications in progress will be lost.");
+    }
   return QMessageBox::Yes;
 }
 
@@ -198,6 +204,13 @@ MainWindow::automaticLoading ()
   automaticLoadingAct->setChecked(!autoLoad);
 }
 
+void
+MainWindow::automaticSaving ()
+{
+  autoSave = !autoSave;
+  automaticSavingAct->setChecked(!autoSave);
+}
+
 
 void
 MainWindow::readOnly ()
@@ -243,6 +256,12 @@ MainWindow::createActions ()
   automaticLoadingAct->setChecked(true);
   connect (automaticLoadingAct, &QAction::triggered, this, &MainWindow::automaticLoading);
 
+  automaticSavingAct = new QAction (tr ("&Automatic saving lines in json file"), this);
+  automaticSavingAct->setShortcut (QKeySequence(Qt::CTRL | Qt::Key_A));
+  automaticSavingAct->setCheckable(true);
+  automaticSavingAct->setChecked(false);
+  connect (automaticSavingAct, &QAction::triggered, this, &MainWindow::automaticSaving);
+
   readOnlyAct = new QAction (tr ("&Read Only"), this);
   readOnlyAct->setShortcut (QKeySequence(Qt::CTRL | Qt::Key_R));
   connect (readOnlyAct, &QAction::triggered, this, &MainWindow::readOnly);
@@ -281,6 +300,7 @@ MainWindow::createMenus ()
 
   editMenu = menuBar()->addMenu(tr("&Edit"));
   editMenu->addAction (automaticLoadingAct);
+  editMenu->addAction (automaticSavingAct);
   editMenu->addAction (readOnlyAct);
 
   imageMenu = menuBar ()->addMenu (tr ("&Image"));

+ 3 - 0
dsl/MainWindow.hpp

@@ -48,6 +48,7 @@ private:
   QAction *exportAct;
   QAction *exitAct;
   QAction *automaticLoadingAct;
+  QAction *automaticSavingAct;
   QAction *readOnlyAct;
   QAction *firstImageAct;
   QAction *previousImageAct;
@@ -62,6 +63,7 @@ private:
   QString *directoryname;
   QString *suffix;
   bool autoLoad;
+  bool autoSave;
 
   void createActions ();
   void createMenus ();
@@ -80,6 +82,7 @@ private slots:
   void nextImage ();
   void lastImage ();
   void automaticLoading ();
+  void automaticSaving ();
   void readOnly ();
   void about ();