Commit 3bc09260 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

cnetsuite properly restores the main window's display state according to the...

cnetsuite properly restores the main window's display state according to the currently loaded project's name. Also works when no project is loaded. Fixes #4358.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@7223 41f8697f-d340-4b68-9986-7bafba869bb8
parent 9a0e5009
Loading
Loading
Loading
Loading
+48 −16
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ namespace Isis {
   *                             because if there were warnings and errors, they were not
   *                             being output to the Warnings widget since the project is loaded
   *                             before the GUI is constructed.  Fixes #4488
   *
   *   @history 2016-11-09 Ian Humphrey - Added default readSettings() call to load initial
   *                           default project window state. References #4358.
   */
  CNetSuiteMainWindow::CNetSuiteMainWindow(QWidget *parent) :
      QMainWindow(parent) {
@@ -136,10 +137,9 @@ namespace Isis {

    warningsDock->raise();

    // Read settings from the default project, "Project"
    readSettings(m_directory->project());

//  readSettings();

    resize(800, 600);
    setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
    setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
    setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
@@ -161,6 +161,10 @@ namespace Isis {
    m_activeToolBar = new QToolBar(this);
    m_toolPad = new QToolBar(this);

    m_permToolBar->setObjectName("PermanentToolBar");
    m_activeToolBar->setObjectName("ActiveToolBar");
    m_toolPad->setObjectName("ToolPad");

    addToolBar(m_permToolBar);
    addToolBar(m_activeToolBar);
    addToolBar(m_toolPad);
@@ -515,21 +519,33 @@ namespace Isis {
   * config file. This allows us to restore the settings when we
   * create another main window (the next time this program is run).
   * 
   * The config file used is $HOME/.Isis/$APPNAME/$APPNAME.config
   * The state will be saved according to the currently loaded project and its name.
   *
   * When no project is loaded (i.e. the default "Project" is open), the config file used is
   * $HOME/.Isis/$APPNAME/$APPNAME_Project.config.
   * When a project, ProjectName, is loaded, the config file used is
   * $HOME/.Isis/$APPNAME/$APPNAME_ProjectName.config.
   * 
   * @param[in] project Pointer to the project that is currently loaded (default is "Project")
   *
   * @internal
   *   @history 2016-11-09 Ian Humphrey - Settings are now written according to the loaded project.
   *                           References #4358.
   */
  void CNetSuiteMainWindow::writeSettings() {
  void CNetSuiteMainWindow::writeSettings(const Project *project) const {
    // Ensure that we are not using a NULL pointer   
    if (!project) { 
      QString msg = "Cannot write settings with a NULL Project pointer.";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    QString appName = QApplication::applicationName();
    QSettings settings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + ".config")
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + project->name() + ".config")
          .expanded(),
        QSettings::NativeFormat);

    settings.setValue("geometry", saveGeometry());
    // TODO 2016-08-03 TLS  saveState giving the following errors:
    //QMainWindow::saveState(): 'objectName' not set for QToolBar 0x1d79070 ''
    //QMainWindow::saveState(): 'objectName' not set for QToolBar 0x1d5bea0 ''
    //QMainWindow::saveState(): 'objectName' not set for QToolBar 0x19aa7f0 ''
//  settings.setValue("windowState", saveState());
    settings.setValue("windowState", saveState());
    settings.setValue("size", size());
    settings.setValue("pos", pos());

@@ -540,15 +556,31 @@ namespace Isis {
  /**
   * Read the window positioning and state information from the config file.
   *
   * The config file read is $HOME/.Isis/$APPNAME/$APPNAME.config
   * When running cnetsuite without opening a project, the config file read is
   * $HOME/.Isis/$APPNAME/$APPNAME_Project.config
   * Otherwise, when running cnetsuite and opening a project (ProjectName), the config file read is
   * $HOME/.Isis/$APPNAME/$APPNAME_ProjectName.config
   *
   * @param[in] project (Project *) The project that was loaded.
   *
   * @internal
   *   @history Ian Humphrey - Settings are now read on a project name basis. References #4358.
   */
  void CNetSuiteMainWindow::readSettings(Project *project) {
    // Ensure that the Project pointer is not NULL
    if (!project) {
      QString msg = "Cannot read settings with a NULL Project pointer.";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    if (project->name() == "Project") {
      setWindowTitle("cnetsuite");
    }
    else {
      setWindowTitle( project->name() );
    }
    QString appName = QApplication::applicationName();
    QSettings settings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + ".config")
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + project->name() + ".config")
          .expanded(),
        QSettings::NativeFormat);

@@ -572,7 +604,7 @@ namespace Isis {
   * state information before forwarding the event to the QMainWindow.
   */
  void CNetSuiteMainWindow::closeEvent(QCloseEvent *event) {
    writeSettings();
    writeSettings(m_directory->project());
    QMainWindow::closeEvent(event);
  }

+10 −1
Original line number Diff line number Diff line
@@ -70,6 +70,15 @@ namespace Isis {
   *                          GUI, and it wasn't outputting warnings/errors to the warnings/error tab
   *                          when the project was loaded because it was being called before the GUI
   *                          was created.  Fixes #4488.  References #4526, ##4487.
   *   @history 2016-11-09 Ian Humphrey - Modified readSettings() and writeSettings() to take in
   *                           Project pointers to be used to properly read and write settings
   *                           for the CNetSuiteMainWindow. Note that when running cnetsuite without
   *                           opening a Project, the config file cnetsuite_Project.config is used.
   *                           Otherwise, when a project is open, the config file
   *                           cnetsuite_ProjectName will be used to restore window geom.
   *                           The m_permToolBar, m_activeToolBar, and m_toolPad now have object
   *                           names set, so the saveState() call within writeSettings() now works.
   *                           Fixes #4358.
   */
  class CNetSuiteMainWindow : public QMainWindow {
      Q_OBJECT
@@ -105,7 +114,7 @@ namespace Isis {

      void applyMaxThreadCount();
      void createMenus();
      void writeSettings();
      void writeSettings(const Project *project) const;

      void initializeActions();

+3 −1
Original line number Diff line number Diff line
@@ -44,7 +44,9 @@ int main(int argc, char *argv[]) {

    CNetSuiteMainWindow *mainWindow = new CNetSuiteMainWindow();

    mainWindow->showMaximized();
    // We do not want a showMaximized call, as that will negate the settings read during the main
    // window's initialization. References #4358.
    mainWindow->show();
    int status = app->exec();

    delete mainWindow;
+7 −0
Original line number Diff line number Diff line
@@ -16,5 +16,12 @@
    <change name="Ken Edmundson" date="2012-04-03">
      Original version
    </change>
    <change name="Ian Humphrey" date="2016-11-09">
      The main window state is now saved properly when running cnetsuite. If running cnetsuite
      without opening a project, the config files are saved as cnetsuite_Project.config (Project is
      the default project name). Otherwise, when a project is loaded, config files are saved as
      cnetsuite_ProjectName.config, where ProjectName is the name of the loaded project.
      Fixes #4358.
    </change>
  </history>
</application>