Commit aec0352a authored by Tyler Wilson's avatar Tyler Wilson
Browse files

The recent projects file menu now works. Fixes #4492.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@8281 41f8697f-d340-4b68-9986-7bafba869bb8
parent a87d0325
Loading
Loading
Loading
Loading
+158 −13
Original line number Diff line number Diff line
@@ -22,16 +22,23 @@
 */
#include "IpceMainWindow.h"

#include <QtDebug>

#include <QApplication>
#include <QColor>
#include <QDebug>
#include <QDockWidget>
#include <QMap>
#include <QMapIterator>
#include <QMdiArea>
#include <QObject>
#include <QRegExp>
#include <QStringList>
#include <QtWidgets>
#include <QSettings>
#include <QSize>
#include <QStatusBar>
#include <QStringList>
#include <QDateTime>
#include <QTreeView>
#include <QVariant>

@@ -149,8 +156,6 @@ namespace Isis {

    m_warningsDock->raise();

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

    setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
    setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
@@ -557,6 +562,8 @@ namespace Isis {
    connect(activateWhatsThisAct, SIGNAL(triggered()), this, SLOT(enterWhatsThisMode()));

    m_helpMenuActions.append(activateWhatsThisAct);

    readSettings(m_directory->project() );
  }


@@ -606,25 +613,120 @@ namespace Isis {
   * @internal
   *   @history 2016-11-09 Ian Humphrey - Settings are now written according to the loaded project.
   *                           References #4358.
   *   @history 2017-10-17 Tyler Wilson Added a [recent projects] group for the saving and
   *                           restoring of recently opened projects.  References #4492.
   */
  void IpceMainWindow::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(
    QSettings projectSettings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + project->name() + ".config")
          .expanded(),
        QSettings::NativeFormat);

    settings.setValue("geometry", saveGeometry());
    settings.setValue("windowState", saveState());
    settings.setValue("size", size());
    settings.setValue("pos", pos());
    QSettings globalSettings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + "Project.config")
          .expanded(),
        QSettings::NativeFormat);

    projectSettings.setValue("geometry", saveGeometry());
    projectSettings.setValue("windowState", saveState());
    projectSettings.setValue("size", size());
    projectSettings.setValue("pos", pos());

    projectSettings.setValue("maxThreadCount", m_maxThreadCount);

    globalSettings.setValue("maxThreadCount", m_maxThreadCount);
    globalSettings.setValue("maxRecentProjects",m_maxRecentProjects);

    globalSettings.beginGroup("recent_projects");
    QStringList keys = globalSettings.allKeys();
    QMap<QString,QString> recentProjects;

    foreach (QString key,keys) {

      recentProjects[key]=globalSettings.value(key).toString();

    }

    QList<QString> projectPaths = recentProjects.values();

    if (keys.count() >= m_maxRecentProjects) {

      //Clear out the recent projects before repopulating this group
      globalSettings.remove("");



      //If the currently open project is a project that has been saved and is not within the current
      //list of recently open projects, then remove the oldest project from the list.
      if (!project->projectPath().contains("tmpProject") && !projectPaths.contains(project->projectPath()) ) {
        QString s=keys.first();
        recentProjects.remove( s );
      }

      //If the currently open project is already contained within the list,
      //then remove the earlier reference.
      if (projectPaths.contains(project->projectPath())) {
        QString key = recentProjects.key(project->projectPath());
        recentProjects.remove(key);

      }

      QMap<QString,QString>::iterator i;

      //Iterate through the recentProjects QMap and set the <key,val> pairs.
      for (i=recentProjects.begin();i!=recentProjects.end();i++) {

          globalSettings.setValue(i.key(),i.value());


      }

      //Get a unique time value for generating a key
      long t0 = QDateTime::currentMSecsSinceEpoch();
      QString projName = project->name();



      QString t0String=QString::number(t0);   

      //Save the project location
      if (!project->projectPath().contains("tmpProject") ) {
              globalSettings.setValue(t0String+"%%%%%"+projName,project->projectPath());                            


      }

    }

    //The numer of recent open projects is less than m_maxRecentProjects
    else {

      long t0 = QDateTime::currentMSecsSinceEpoch();     
      QString projName = project->name();
      QString t0String=QString::number(t0);  

      if (!project->projectPath().contains("tmpProject") && !projectPaths.contains( project->projectPath() ) ) {
        globalSettings.setValue(t0String+"%%%%%"+projName,project->projectPath());      
      }

    }


    globalSettings.endGroup();






    settings.setValue("maxThreadCount", m_maxThreadCount);
  }


@@ -640,6 +742,7 @@ namespace Isis {
   *
   * @internal
   *   @history Ian Humphrey - Settings are now read on a project name basis. References #4358.
   *   @history Tyler Wilson 2017-11-02 - Settings now read recent projects.  References #4492.
   */
  void IpceMainWindow::readSettings(Project *project) {
    // Ensure that the Project pointer is not NULL
@@ -652,16 +755,58 @@ namespace Isis {
    }
    else {     
      setWindowTitle( project->name() );
      QString projName = project->name();
      setWindowTitle(projName );
    }
    QString appName = QApplication::applicationName();

    QSettings settings(
        FileName("$HOME/.Isis/" + appName + "/" + appName + "_" + project->name() + ".config")
          .expanded(),
        QSettings::NativeFormat);
        .expanded(), QSettings::NativeFormat);

    restoreGeometry(settings.value("geometry").toByteArray());
    restoreState(settings.value("windowState").toByteArray());

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

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

    foreach (QString key, keys) {
      QString childKey = "recent_projects/"+key;
      QString projectPath = settings.value(key).toString();
      QString projectName = projectPath.split("/").last();
      projectPathList.append(projectPath) ;
      projectNameList.append(projectName);
    }

    settings.endGroup();

    QStringList projectPathReverseList;

    for (int i = projectPathList.count()-1;i>=0;i--) {
      projectPathReverseList.append(projectPathList[i]);
    }

    QStringList projectPathListTruncated;

    int i =0;

    foreach (QString proj,projectPathReverseList) {
      if (i <= m_maxRecentProjects) {
        projectPathListTruncated.append(proj);
        i++;
      }
      else
        break;
     }


    m_directory->setRecentProjectsList(projectPathListTruncated);
    m_directory->updateRecentProjects();

    // 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.
@@ -671,6 +816,7 @@ namespace Isis {
    resize(settings.value("size", QSize(800, 600)).toSize());
    m_maxThreadCount = settings.value("maxThreadCount", m_maxThreadCount).toInt();
    applyMaxThreadCount();

  }


@@ -699,7 +845,6 @@ namespace Isis {
    m_directory->project()->clear();
    writeSettings(m_directory->project());
    QMainWindow::closeEvent(event);

  }


+4 −0
Original line number Diff line number Diff line
@@ -101,6 +101,9 @@ namespace Isis {
   *   @history 2017-08-09 Marjorie Hahn - Hard-coded the size of the icons in the toolbar to 
   *                           temporarily fix the shift in size when switching between views 
   *                           until docked widgets are implemented. Fixes #5084.
   *   @history 2017-11-02 Tyler Wilson - Added the ability to read/write settings for recent
   *                            projects.  Also re-implemented the functionality for loading
   *                            recent projects in IPCE.  Fixes #4492.
   */
  class IpceMainWindow : public QMainWindow {
      Q_OBJECT
@@ -160,6 +163,7 @@ namespace Isis {
       *   should perform a best-guess for best perfomance.
       */
      int m_maxThreadCount;
      const int m_maxRecentProjects = 5;

      QToolBar *m_permToolBar; //!< The toolbar for actions that rarely need to be changed.
      QToolBar *m_activeToolBar; //<! The toolbar for the actions of the current tool.
+5 −4
Original line number Diff line number Diff line
@@ -63,9 +63,10 @@ namespace Isis {

  bool CnetEditorViewWorkOrder::isExecutable(ControlList * controls) {

    if (controls->count() >= 1)
      return true;
    else

    if (controls) {
      return (controls->count() >= 1);
    }
    return false;
  }

+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ namespace Isis {
   *   @history 2017-07-25 Cole Neubauer - Added project()->setClean call #4969
   *   @history 2017-08-11 Cole Neubauer - Removed isUndoable and set parent member variable
   *                          Fixes #5064
   *   @history 2017-11-02  Tyler Wilson - Added a null pointer check on the ControList *controls
   *                          pointer in the isExecutable(...) function to prevent potential
   *                          segfaults.  References #4492.
   */
  class CnetEditorViewWorkOrder : public WorkOrder {
      Q_OBJECT
+4 −0
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ namespace Isis {
   * @return @b bool True if the number of images is greater than 0 and less than 50.
   */
  bool CubeDnViewWorkOrder::isExecutable(ImageList *images) {
    if (!images)
      return false;
    return (images->count() > 0 && images->count() < 50);
  }

@@ -91,6 +93,8 @@ namespace Isis {
   * @return @b bool True if the number of shapes is greater than 0 and less than 20.
   */
  bool CubeDnViewWorkOrder::isExecutable(ShapeList *shapes) {
    if (!shapes)
      return false;
    return (shapes->count() > 0 && shapes->count() < 20);
  }

Loading