Commit cfe3d265 authored by Makayla Shepherd's avatar Makayla Shepherd
Browse files

1. QSettings now saves to the project directory if the user saves the project....

1. QSettings now saves to the project directory if the user saves the project. If they have not saved the project it defaults to ~/.Isis/ipce/ipce.config. 2. ipce is now maximized if this is the first instance of ipce. 3. Cancelling the OpenProjectDialog no longer causes an error.
parent c727e361
Loading
Loading
Loading
Loading
+90 −61
Original line number Diff line number Diff line
@@ -504,10 +504,13 @@ namespace Isis {
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    QString appName = QApplication::applicationName();
    QSettings projectSettings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + project->name() + ".config")
          .expanded(),
        QSettings::NativeFormat);
    
    QString filePath = project->newProjectRoot() + "/ipce.config";  
    if (project->isTemporaryProject()) {
      filePath = "$HOME/.Isis/" + appName + "/ipce.config";
    }
        
    QSettings projectSettings(FileName(filePath).expanded(), QSettings::NativeFormat);

    QSettings globalSettings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + "Project.config")
@@ -515,9 +518,14 @@ namespace Isis {
        QSettings::NativeFormat);

    projectSettings.setValue("geometry", QVariant(geometry()));
    
    // If we try to restore a state when we don't have the cubes for a view it could cause a crash
    // Therefore we only want to save the state if we are NOT saving to the default area
    if (!project->isTemporaryProject()) {
      projectSettings.setValue("windowState", saveState());
//  projectSettings.setValue("size", size());
//  projectSettings.setValue("pos", pos());
    }
    projectSettings.sync();


    projectSettings.setValue("maxThreadCount", m_maxThreadCount);

@@ -587,6 +595,7 @@ namespace Isis {
      }
    }
    globalSettings.endGroup();
    globalSettings.sync();
  }


@@ -606,6 +615,8 @@ namespace Isis {
   *   @history Tyler Wilson 2017-11-13 - Commented out a resize call near the end because it
   *                                      was messing with the positions of widgets after a
   *                                      project was loaded.  Fixes #5075.
   *   @history Makayla Shepherd 2018-06-10 - Settings are read from the project root ipce.config.
   *                If that does not exist then we read from .Isis/ipce/ipce.config.
   */
  void IpceMainWindow::readSettings(Project *project) {
    // Ensure that the Project pointer is not NULL
@@ -614,20 +625,46 @@ namespace Isis {
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    
    // Set the path of the settings file
    // The default is to assume that the project has an ipce.config in it
    // If the file does not exist then we read settings from .Isis/ipce/ipce.config
    QString appName = QApplication::applicationName();
    QString filePath = project->projectRoot() + "/ipce.config";
    
    bool setFullScreen = false;
    if (!FileName(filePath).fileExists()) {
      filePath = "$HOME/.Isis/" + appName + "/ipce.config";
      
    QSettings settings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + project->name() + ".config")
          .expanded(), QSettings::NativeFormat);
      // If the $HOME/.Isis/ipce/ipce.config does not exist then we want ipce to show up in 
      // in full screen. Meaning the default geometry is full screen
      if (!FileName(filePath).fileExists()) {
        setFullScreen = true;
      }
    }
    
    // General settings
    if (project->name() == "Project") {
      setWindowTitle("ipce");
    }
    else {
      setWindowTitle( project->name() );
    }

    
    QSettings settings(FileName(filePath).expanded(), QSettings::NativeFormat);

    if (!setFullScreen) {
      setGeometry(settings.value("geometry").value<QRect>());
      restoreState(settings.value("windowState").toByteArray());
    }
    else {
      this->showMaximized();
    }

    QStringList projectNameList;
    QStringList projectPathList;
    settings.beginGroup("recent_projects");
    QStringList keys = settings.allKeys();

    QRegExp underscore("%%%%%");

    foreach (QString key, keys) {
@@ -641,6 +678,7 @@ namespace Isis {
    settings.endGroup();

    QStringList projectPathReverseList;

    for (int i = projectPathList.count()-1;i>=0;i--) {
      projectPathReverseList.append(projectPathList[i]);
    }
@@ -658,28 +696,19 @@ namespace Isis {
        break;
     }


    m_directory->setRecentProjectsList(projectPathListTruncated);
    m_directory->updateRecentProjects();
      m_maxThreadCount = settings.value("maxThreadCount", m_maxThreadCount).toInt();
      applyMaxThreadCount();
    }
    //  Project specific settings
    else {
      setWindowTitle( project->name() );
      if (settings.contains("geometry")) {
        setGeometry(settings.value("geometry").value<QRect>()); 
      }
      if (settings.contains("windowState")) {
        restoreState(settings.value("windowState").toByteArray()); 
      }

    // The geom/state isn't enough for main windows to correctly remember
    //   their position and size, so let's restore those on top of
    //   the geom and state.
      if (!settings.value("pos").toPoint().isNull()) {
    if (!settings.value("pos").toPoint().isNull())
      move(settings.value("pos").toPoint());
      }
    }

    m_maxThreadCount = settings.value("maxThreadCount", m_maxThreadCount).toInt();
    applyMaxThreadCount();

  }


+5 −0
Original line number Diff line number Diff line
@@ -145,6 +145,11 @@ namespace Isis {
   *   @history 2018-06-15 Tracie Sucharski - Fixed break to recent projects.  The readSettings
   *                           must be called before initializeActions to get the recent projects
   *                           from the config file.
   *   @history 2018-06-20 Makayla Shepherd - ipce now defaults to full screen if there is not an
   *                           ipce.config in the project or in ~/.Isis/ipce.
   *   @history 2018-06-20 Makayla Shepherd - Stopped saving the state of a temporary project.
   *   @history 2018-06-20 Makayla Shepherd - Save and Save As now save the geometry and state of 
   *                           the project.
   *  
   */
  class IpceMainWindow : public QMainWindow {
+5 −6
Original line number Diff line number Diff line
@@ -1386,8 +1386,7 @@ namespace Isis {
      }
    }
    m_isOpen = true;
    // TODO: TLS 2018-06-07  Why writeSettings here?
    //writeSettings();

    emit projectLoaded(this);
  }

@@ -2190,12 +2189,13 @@ namespace Isis {
                                                            QString("."));

      if ( !newDestination.isEmpty() ) {
        m_isTemporaryProject = false;
        save( QFileInfo(newDestination + "/").absolutePath() );
        
        
        // delete the temporary project
        deleteAllProjectFiles();
        relocateProjectRoot(newDestination);
        m_isTemporaryProject = false;
       
        // 2014-03-14 kle This is a lame kludge because we think that relocateProjectRoot is not
        // working properly. For example, when we save a new project and try to view a control net
@@ -2217,7 +2217,6 @@ namespace Isis {
      }

      save(m_projectRoot->absolutePath(), false);
      // if (newDestination != )
    }

    return saveDialogCompleted;
+4 −12
Original line number Diff line number Diff line
@@ -255,17 +255,8 @@ namespace Isis {
   *                           the wrong place on the project tree. Fixes #5274.
   *  @history 2018-06-06 Kaitlyn Lee - activeControlModified() calls setClean(false) to enable the save
   *                           button when the active control net is modified, i.e. a point is modified.
   *  
   *  !!!!!!!!!!!!!   Delete following history entry when project save/restore geometry/state
   *                   implemented
   *  !!!!!!!!!!!!!!!
   *  @history 2018-06-08 Tracie Sucharski - Quick fix for the project save/restore prototype: The
   *                          changes made to readSettings, writeSettings cause following problem:
   *                          save project with view, close view and exit, the project
   *                          geometry/state is saved on closeEvent instead of project save. Quickly
   *                          added signal when project is saved, so the writeSettings can happen
   *                          for project.  This will be cleaned up when save/restore is fully
   *                          implemented.
   *  @history 2018-06-14 Makayla Shepherd - Save and Save As now save the geometry and state of 
   *                           the project.
   *  
   */
  class Project : public QObject {
@@ -488,8 +479,9 @@ namespace Isis {

      /**
       * Emitted when project is saved.
       *
       * receivers: IpceMainWindow
       */

      void projectSaved(Project *);

      /**