Skip to content

Commit

Permalink
Fixes #2220, #2347 & #2416.
Browse files Browse the repository at this point in the history
Disable/enable the auto save timer based on focusInEvent/focusOutEvent of editor.
  • Loading branch information
adeas31 committed Mar 15, 2016
1 parent 19e8270 commit 1ec6313
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 100 deletions.
29 changes: 29 additions & 0 deletions OMEdit/OMEditGUI/Editors/BaseEditor.cpp
Expand Up @@ -1038,6 +1038,35 @@ QMimeData* BaseEditor::PlainTextEdit::createMimeDataFromSelection() const
return 0;
}

/*!
* \brief BaseEditor::PlainTextEdit::focusInEvent
* Reimplementation of QPlainTextEdit::focusInEvent(). Stops the auto save timer.
* \param event
*/
void BaseEditor::PlainTextEdit::focusInEvent(QFocusEvent *event)
{
mpBaseEditor->getMainWindow()->getAutoSaveTimer()->stop();
QPlainTextEdit::focusInEvent(event);
}

/*!
* \brief BaseEditor::PlainTextEdit::focusOutEvent
* Reimplementation of QPlainTextEdit::focusOutEvent(). Restarts the auto save timer.
* \param event
*/
void BaseEditor::PlainTextEdit::focusOutEvent(QFocusEvent *event)
{
/* The user might start editing the document and then minimize the OMEdit window.
* We should only start the autosavetimer when MainWindow is the active window and focusOutEvent is called.
*/
if (mpBaseEditor->getMainWindow()->isActiveWindow()) {
if (mpBaseEditor->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getEnableAutoSaveGroupBox()->isChecked()) {
mpBaseEditor->getMainWindow()->getAutoSaveTimer()->start();
}
}
QPlainTextEdit::focusOutEvent(event);
}

/*!
* \class BaseEditor
* Base class for all editors.
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Editors/BaseEditor.h
Expand Up @@ -174,6 +174,8 @@ class BaseEditor : public QWidget
virtual void resizeEvent(QResizeEvent *pEvent);
virtual void keyPressEvent(QKeyEvent *pEvent);
virtual QMimeData* createMimeDataFromSelection() const;
virtual void focusInEvent(QFocusEvent *event);
virtual void focusOutEvent(QFocusEvent *event);
};
public:
BaseEditor(MainWindow *pMainWindow);
Expand Down
77 changes: 33 additions & 44 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -273,10 +273,11 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent
}
// create the auto save timer
mpAutoSaveTimer = new QTimer(this);
mpAutoSaveTimer->setInterval(mpOptionsDialog->getGeneralSettingsPage()->getAutoSaveIntervalSpinBox()->value() * 1000);
connect(mpAutoSaveTimer, SIGNAL(timeout()), SLOT(autoSave()));
// read auto save settings
if (mpOptionsDialog->getGeneralSettingsPage()->getEnableAutoSaveGroupBox()->isChecked()) {
mpAutoSaveTimer->start(mpOptionsDialog->getGeneralSettingsPage()->getAutoSaveIntervalSpinBox()->value() * 1000);
mpAutoSaveTimer->start();
}
}

Expand Down Expand Up @@ -2100,44 +2101,14 @@ void MainWindow::documentationDockWidgetVisibilityChanged(bool visible)
}
}

/*!
* \brief MainWindow::autoSave
* Slot activated when mpAutoSaveTimer timeout SIGNAL is raised.\n
* Auto saves the classes which user has alreadys saved to a file. Classes not saved to a file are not saved.
*/
void MainWindow::autoSave()
{
// bool autoSaveForSingleClasses = mpOptionsDialog->getGeneralSettingsPage()->getEnableAutoSaveForSingleClassesCheckBox()->isChecked();
// bool autoSaveForOneFilePackages = mpOptionsDialog->getGeneralSettingsPage()->getEnableAutoSaveForOneFilePackagesCheckBox()->isChecked();
// bool autoSaveForFolderPackages = false;
// // if auto save for any class type is enabled.
// if (autoSaveForSingleClasses || autoSaveForOneFilePackages || autoSaveForFolderPackages)
// {
// foreach (LibraryTreeNode* pLibraryTreeNode, mpLibraryTreeWidget->getLibraryTreeNodesList())
// {
// if (!pLibraryTreeNode->isSaved() && !pLibraryTreeNode->getFileName().isEmpty())
// {
// // if auto save for single file class is enabled.
// if (pLibraryTreeNode->getParentName().isEmpty() && pLibraryTreeNode->childCount() == 0 && autoSaveForSingleClasses)
// {
// mpLibraryTreeWidget->saveLibraryTreeNode(pLibraryTreeNode);
// }
// // if auto save for one file package is enabled.
// else if (pLibraryTreeNode->getParentName().isEmpty() && pLibraryTreeNode->childCount() > 0 && autoSaveForOneFilePackages)
// {
// mpLibraryTreeWidget->saveLibraryTreeNode(pLibraryTreeNode);
// }
// // if auto save for folder package is enabled.
// else if (autoSaveForFolderPackages)
// {
// LibraryTreeNode *pParentLibraryTreeNode = mpLibraryTreeWidget->getLibraryTreeNode(StringHandler::getFirstWordBeforeDot(pLibraryTreeNode->getNameStructure()));
// if (pParentLibraryTreeNode)
// {
// QFileInfo fileInfo(pParentLibraryTreeNode->getFileName());
// if ((pParentLibraryTreeNode->getSaveContentsType() == LibraryTreeNode::SaveFolderStructure) || (fileInfo.fileName().compare("package.mo") == 0))
// {
// mpLibraryTreeWidget->saveLibraryTreeNode(pParentLibraryTreeNode);
// }
// }
// }
// }
// }
// }
autoSaveHelper(mpLibraryWidget->getLibraryTreeModel()->getRootLibraryTreeItem());
}

/*!
Expand Down Expand Up @@ -2733,13 +2704,31 @@ void MainWindow::createMenus()
}

/*!
Stores the window states and geometry of all Plot Windows.
*/
/*
The application window title and window icon gets corrupted when we switch between modeling & plotting perspective.
To solve this we tile the plot windows when we switch to modeling and welcome perspective. But before calling tileSubWindows() we save all
the plot windows states & geometry and then restore it when switching back to plotting view.
*/
* \brief MainWindow::autoSaveHelper
* Helper function for MainWindow::autoSave()
* \param pLibraryTreeItem
*/
void MainWindow::autoSaveHelper(LibraryTreeItem *pLibraryTreeItem)
{
for (int i = 0; i < pLibraryTreeItem->getChildren().size(); i++) {
LibraryTreeItem *pChildLibraryTreeItem = pLibraryTreeItem->child(i);
if (!pChildLibraryTreeItem->isSystemLibrary()) {
if (pChildLibraryTreeItem->isFilePathValid() && !pChildLibraryTreeItem->isSaved()) {
mpLibraryWidget->saveLibraryTreeItem(pChildLibraryTreeItem);
} else {
autoSaveHelper(pChildLibraryTreeItem);
}
}
}
}

/*!
* \brief MainWindow::storePlotWindowsStateAndGeometry
* Stores the window states and geometry of all Plot Windows.\n
* The application window title and window icon gets corrupted when we switch between modeling & plotting perspective.
* To solve this we tile the plot windows when we switch to modeling and welcome perspective. But before calling tileSubWindows() we save all
* the plot windows states & geometry and then restore it when switching back to plotting view.
*/
void MainWindow::storePlotWindowsStateAndGeometry()
{
if (mPlotWindowsStatesList.isEmpty() && mPlotWindowsGeometriesList.isEmpty()) {
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -122,6 +122,7 @@ class MainWindow : public QMainWindow
Label* getPointerXPositionLabel() {return mpPointerXPositionLabel;}
Label* getPointerYPositionLabel() {return mpPointerYPositionLabel;}
QTabBar* getPerspectiveTabBar() {return mpPerspectiveTabbar;}
QTimer* getAutoSaveTimer() {return mpAutoSaveTimer;}
QAction* getSaveAction() {return mpSaveAction;}
QAction* getSaveAsAction() {return mpSaveAsAction;}
QAction* getSaveTotalAction() {return mpSaveTotalAction;}
Expand Down Expand Up @@ -409,6 +410,7 @@ private slots:
void createActions();
void createToolbars();
void createMenus();
void autoSaveHelper(LibraryTreeItem *pLibraryTreeItem);
void storePlotWindowsStateAndGeometry();
void switchToWelcomePerspective();
void switchToModelingPerspective();
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3986,6 +3986,9 @@ bool ModelWidgetContainer::eventFilter(QObject *object, QEvent *event)
if (!object || isHidden() || qApp->activeWindow() != mpMainWindow) {
return QMdiArea::eventFilter(object, event);
}
/* If focus is set to LibraryTreeView, DocumentationViewer, QMenuBar etc. then try to validate the text because user might have
* updated the text manually.
*/
if ((event->type() == QEvent::MouseButtonPress && qobject_cast<QMenuBar*>(object)) ||
(event->type() == QEvent::FocusIn && (qobject_cast<LibraryTreeView*>(object) || qobject_cast<DocumentationViewer*>(object)))) {
ModelWidget *pModelWidget = getCurrentModelWidget();
Expand Down
78 changes: 29 additions & 49 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -149,12 +149,6 @@ void OptionsDialog::readGeneralSettings()
if (mpSettings->contains("autoSave/interval")) {
mpGeneralSettingsPage->getAutoSaveIntervalSpinBox()->setValue(mpSettings->value("autoSave/interval").toInt());
}
if (mpSettings->contains("autoSave/enableSingleClasses")) {
mpGeneralSettingsPage->getEnableAutoSaveForSingleClassesCheckBox()->setChecked(mpSettings->value("autoSave/enableSingleClasses").toBool());
}
if (mpSettings->contains("autoSave/enableOneFilePackages")) {
mpGeneralSettingsPage->getEnableAutoSaveForOneFilePackagesCheckBox()->setChecked(mpSettings->value("autoSave/enableOneFilePackages").toBool());
}
// read welcome page
if (mpSettings->contains("welcomePage/view")) {
mpGeneralSettingsPage->setWelcomePageView(mpSettings->value("welcomePage/view").toInt());
Expand Down Expand Up @@ -641,8 +635,6 @@ void OptionsDialog::saveGeneralSettings()
// save auto save
mpSettings->setValue("autoSave/enable", mpGeneralSettingsPage->getEnableAutoSaveGroupBox()->isChecked());
mpSettings->setValue("autoSave/interval", mpGeneralSettingsPage->getAutoSaveIntervalSpinBox()->value());
mpSettings->setValue("autoSave/enableSingleClasses", mpGeneralSettingsPage->getEnableAutoSaveForSingleClassesCheckBox()->isChecked());
mpSettings->setValue("autoSave/enableOneFilePackages", mpGeneralSettingsPage->getEnableAutoSaveForOneFilePackagesCheckBox()->isChecked());
mpMainWindow->toggleAutoSave();
// save welcome page
switch (mpGeneralSettingsPage->getWelcomePageView()) {
Expand Down Expand Up @@ -1283,9 +1275,6 @@ GeneralSettingsPage::GeneralSettingsPage(OptionsDialog *pOptionsDialog)
mpAutoSaveIntervalSpinBox->setValue(300);
mpAutoSaveSecondsLabel = new Label;
connect(mpAutoSaveIntervalSpinBox, SIGNAL(valueChanged(int)), SLOT(autoSaveIntervalValueChanged(int)));
mpEnableAutoSaveForSingleClassesCheckBox = new QCheckBox(tr("Enable Auto Save for single classes"));
mpEnableAutoSaveForSingleClassesCheckBox->setChecked(true);
mpEnableAutoSaveForOneFilePackagesCheckBox = new QCheckBox(tr("Enable Auto Save for one file packages (Experimental)"));
// calculate the auto save interval seconds.
autoSaveIntervalValueChanged(mpAutoSaveIntervalSpinBox->value());
// Auto Save layout
Expand All @@ -1294,8 +1283,6 @@ GeneralSettingsPage::GeneralSettingsPage(OptionsDialog *pOptionsDialog)
pAutoSaveGridLayout->addWidget(mpAutoSaveIntervalLabel, 0, 0);
pAutoSaveGridLayout->addWidget(mpAutoSaveIntervalSpinBox, 0, 1);
pAutoSaveGridLayout->addWidget(mpAutoSaveSecondsLabel, 0, 2);
pAutoSaveGridLayout->addWidget(mpEnableAutoSaveForSingleClassesCheckBox, 1, 0, 1, 3);
pAutoSaveGridLayout->addWidget(mpEnableAutoSaveForOneFilePackagesCheckBox, 2, 0, 1, 3);
mpEnableAutoSaveGroupBox->setLayout(pAutoSaveGridLayout);
// Welcome Page
mpWelcomePageGroupBox = new QGroupBox(tr("Welcome Page"));
Expand Down Expand Up @@ -1400,52 +1387,48 @@ void GeneralSettingsPage::setDefaultView(QString value)
mpDiagramViewRadioButton->setChecked(true);
}

/*!
* \brief GeneralSettingsPage::getDefaultView
* Returns the default view as QString.
* \return
*/
QString GeneralSettingsPage::getDefaultView()
{
if (mpIconViewRadioButton->isChecked())
if (mpIconViewRadioButton->isChecked()) {
return Helper::iconView;
else if (mpTextViewRadioButton->isChecked())
} else if (mpTextViewRadioButton->isChecked()) {
return Helper::textView;
else if (mpDocumentationViewRadioButton->isChecked())
} else if (mpDocumentationViewRadioButton->isChecked()) {
return Helper::documentationView;
else
} else {
return Helper::diagramView;
}
}

QGroupBox* GeneralSettingsPage::getEnableAutoSaveGroupBox()
{
return mpEnableAutoSaveGroupBox;
}

QSpinBox* GeneralSettingsPage::getAutoSaveIntervalSpinBox()
{
return mpAutoSaveIntervalSpinBox;
}

QCheckBox* GeneralSettingsPage::getEnableAutoSaveForSingleClassesCheckBox()
{
return mpEnableAutoSaveForSingleClassesCheckBox;
}

QCheckBox* GeneralSettingsPage::getEnableAutoSaveForOneFilePackagesCheckBox()
{
return mpEnableAutoSaveForOneFilePackagesCheckBox;
}

/*!
* \brief GeneralSettingsPage::getWelcomePageView
* Returns the WelcomePageWidget orientation.
* \return
*/
int GeneralSettingsPage::getWelcomePageView()
{
if (mpHorizontalViewRadioButton->isChecked())
if (mpHorizontalViewRadioButton->isChecked()) {
return 1;
else if (mpVerticalViewRadioButton->isChecked())
} else if (mpVerticalViewRadioButton->isChecked()) {
return 2;
else
} else {
return 0;
}
}

/*!
* \brief GeneralSettingsPage::setWelcomePageView
* Sets the WelcomePageWidget orientation.
* \param view
*/
void GeneralSettingsPage::setWelcomePageView(int view)
{
switch (view)
{
switch (view) {
case 2:
mpVerticalViewRadioButton->setChecked(true);
break;
Expand All @@ -1456,19 +1439,15 @@ void GeneralSettingsPage::setWelcomePageView(int view)
}
}

QCheckBox* GeneralSettingsPage::getShowLatestNewsCheckBox()
{
return mpShowLatestNewsCheckBox;
}

/*!
* \brief GeneralSettingsPage::selectWorkingDirectory
* Slot activated when mpWorkingDirectoryBrowseButton clicked signal is raised.
* Allows user to choose a new working directory.
*/
void GeneralSettingsPage::selectWorkingDirectory()
{
mpWorkingDirectoryTextBox->setText(StringHandler::getExistingDirectory(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseDirectory), NULL));
mpWorkingDirectoryTextBox->setText(StringHandler::getExistingDirectory(this, QString("%1 - %2").arg(Helper::applicationName)
.arg(Helper::chooseDirectory), NULL));
}

/*!
Expand All @@ -1478,7 +1457,8 @@ void GeneralSettingsPage::selectWorkingDirectory()
*/
void GeneralSettingsPage::selectTerminalCommand()
{
mpTerminalCommandTextBox->setText(StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseFile), NULL, NULL, NULL));
mpTerminalCommandTextBox->setText(StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName)
.arg(Helper::chooseFile), NULL, NULL, NULL));
}

/*!
Expand Down
10 changes: 3 additions & 7 deletions OMEdit/OMEditGUI/Options/OptionsDialog.h
Expand Up @@ -175,13 +175,11 @@ class GeneralSettingsPage : public QWidget
QString getModelingViewMode();
void setDefaultView(QString value);
QString getDefaultView();
QGroupBox* getEnableAutoSaveGroupBox();
QSpinBox* getAutoSaveIntervalSpinBox();
QCheckBox* getEnableAutoSaveForSingleClassesCheckBox();
QCheckBox* getEnableAutoSaveForOneFilePackagesCheckBox();
QGroupBox* getEnableAutoSaveGroupBox() {return mpEnableAutoSaveGroupBox;}
QSpinBox* getAutoSaveIntervalSpinBox() {return mpAutoSaveIntervalSpinBox;}
int getWelcomePageView();
void setWelcomePageView(int view);
QCheckBox* getShowLatestNewsCheckBox();
QCheckBox* getShowLatestNewsCheckBox() {return mpShowLatestNewsCheckBox;}
private:
OptionsDialog *mpOptionsDialog;
QGroupBox *mpGeneralSettingsGroupBox;
Expand Down Expand Up @@ -214,8 +212,6 @@ class GeneralSettingsPage : public QWidget
Label *mpAutoSaveIntervalLabel;
QSpinBox *mpAutoSaveIntervalSpinBox;
Label *mpAutoSaveSecondsLabel;
QCheckBox *mpEnableAutoSaveForSingleClassesCheckBox;
QCheckBox *mpEnableAutoSaveForOneFilePackagesCheckBox;
QGroupBox *mpWelcomePageGroupBox;
QRadioButton *mpHorizontalViewRadioButton;
QRadioButton *mpVerticalViewRadioButton;
Expand Down

0 comments on commit 1ec6313

Please sign in to comment.