Skip to content

Commit

Permalink
Merge e36d2b0 into ad4c9a8
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Jul 18, 2018
2 parents ad4c9a8 + e36d2b0 commit 0b41770
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 179 deletions.
74 changes: 0 additions & 74 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "centralwidget.h"
#include "checkforupdatesdialog.h"
#include "cliutils.h"
#include "coreinterface.h"
#include "guiapplication.h"
#include "guiinterface.h"
#include "guiutils.h"
#include "i18ninterface.h"
#include "mainwindow.h"
Expand All @@ -35,7 +33,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "pluginsdialog.h"
#include "preferencesdialog.h"
#include "preferencesinterface.h"
#include "viewinterface.h"
#include "windowinterface.h"
#include "windowwidget.h"

Expand All @@ -51,13 +48,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

//==============================================================================

#include <QAction>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QLocale>
#include <QMenu>
#include <QMenuBar>
#include <QRect>
#include <QSettings>
#include <QShortcut>
Expand Down Expand Up @@ -102,7 +96,6 @@ MainWindow::MainWindow(const QString &pApplicationDate) :
mFileNewMenu(0),
mViewWindowsMenu(0),
mViewSeparator(0),
mViewPlugin(0),
mDockedWindowsVisible(true),
mDockedWindowsState(QByteArray())
{
Expand Down Expand Up @@ -632,14 +625,6 @@ void MainWindow::initializeGuiPlugin(Plugin *pPlugin)
setCentralWidget(qobject_cast<CoreInterface *>(pPlugin->instance())->centralWidget());
// Note: if the Core plugin is loaded, then it means it supports the
// Core interface, so no need to check anything...

// Also keep track of GUI updates in our central widget
// Note: we cannot use the new connect() syntax since the signal is
// located in our Core plugin and that we don't know anything
// about it...

connect(static_cast<Core::CentralWidget *>(centralWidget()), SIGNAL(guiUpdated(OpenCOR::Plugin *, const QString &)),
this, SLOT(updateGui(OpenCOR::Plugin *, const QString &)));
}

// Add the plugin's window, in case we are dealing with a window plugin
Expand Down Expand Up @@ -1282,65 +1267,6 @@ void MainWindow::restart(bool pSaveSettings) const

//==============================================================================

void MainWindow::showEnableActions(const QList<QAction *> &pActions)
{
// Show/enable or hide/disable the given actions, depending on whether they
// correspond to a menu with visible/enabled or hidden/disabled actions,
// respectively

foreach (QAction *action, pActions) {
QMenu *actionMenu = action->menu();

if (actionMenu) {
QList<QAction *> actionMenuActions = actionMenu->actions();

showEnableActions(actionMenuActions);

bool showEnable = false;

foreach (QAction *actionMenuAction, actionMenuActions) {
if ( !actionMenuAction->isSeparator()
&& actionMenuAction->isVisible()) {
showEnable = true;

break;
}
}

showEnableAction(action, showEnable);
}
}
}

//==============================================================================

void MainWindow::updateGui(OpenCOR::Plugin *pViewPlugin,
const QString &pFileName)
{
// We come here as a result of our central widget having updated its GUI,
// meaning that a new view or file has been selected, so we may need to
// enable/disable and/or show/hide some menus/actions/etc.

// Keep track of our view plugin

mViewPlugin = pViewPlugin;

// Let our different plugins know that the GUI has been updated
// Note: this can be useful when a plugin (e.g. CellMLTools) offers some
// tools that may need to be enabled/disabled and shown/hidden,
// depending on which view plugin and/or file are currently active...

foreach (Plugin *plugin, mLoadedGuiPlugins)
qobject_cast<GuiInterface *>(plugin->instance())->updateGui(mViewPlugin, pFileName);

// Go through our different menus and show/hide them, depending on whether
// they have visible items

showEnableActions(mGui->menuBar->actions());
}

//==============================================================================

void MainWindow::showDockedWindows(bool pShow, bool pInitialisation)
{
// Show/hide the docked windows
Expand Down
6 changes: 0 additions & 6 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ class MainWindow : public QMainWindow
QMenu *mViewWindowsMenu;
QAction *mViewSeparator;

Plugin *mViewPlugin;

bool mDockedWindowsVisible;

QByteArray mDockedWindowsState;
Expand All @@ -134,8 +132,6 @@ class MainWindow : public QMainWindow

void restart(bool pSaveSettings) const;

void showEnableActions(const QList<QAction *> &pActions);

void showPreferencesDialog(const QString &pPluginName = QString());

void showDockedWindows(bool pShow, bool pInitialisation);
Expand All @@ -154,8 +150,6 @@ private slots:
void actionCheckForUpdatesTriggered();
void actionAboutTriggered();

void updateGui(OpenCOR::Plugin *pViewPlugin, const QString &pFileName);

void showDockedWindows(bool pShow);
void toggleDockedWindows();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ void CellmlTextViewWidget::reformat(const QString &pFileName)

mConverter.execute(Core::serialiseDomDocument(mParser.domDocument()));

editor->setContents(mConverter.output(), true);
editor->setContents(mConverter.output(), false);
editor->setCursorPosition(line, column);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void RawCellmlViewWidget::reformat(const QString &pFileName)

domDocument.setContent(editingWidget->editorWidget()->contents());

editingWidget->editorWidget()->setContents(Core::serialiseDomDocument(domDocument), true);
editingWidget->editorWidget()->setContents(Core::serialiseDomDocument(domDocument), false);
editingWidget->editorWidget()->setCursorPosition(line, column);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void RawSedmlViewWidget::reformat(const QString &pFileName)

domDocument.setContent(editingWidget->editorWidget()->contents());

editingWidget->editorWidget()->setContents(Core::serialiseDomDocument(domDocument), true);
editingWidget->editorWidget()->setContents(Core::serialiseDomDocument(domDocument), false);
editingWidget->editorWidget()->setCursorPosition(line, column);
}
}
Expand Down
94 changes: 64 additions & 30 deletions src/plugins/miscellaneous/Core/src/centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

//==============================================================================

#include <QAction>
#include <QApplication>
#include <QDesktopWidget>
#include <QDialogButtonBox>
Expand All @@ -46,6 +47,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QLabel>
#include <QLineEdit>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QMimeData>
#include <QPushButton>
#include <QRect>
Expand Down Expand Up @@ -861,15 +864,13 @@ void CentralWidget::openRemoteFile(const QString &pUrl, bool pShowWarning)
QString errorMessage;

showBusyWidget();
// Note: our call to readFileWithBusyWidget() will also show a busy
// widget, but it will also hide it while we want to keep it
// visible in case we are loading a SED-ML file / COMBINE archive.
// Indeed, such files may require further initialisation (in the
// case of the Simulation Experiment view, for example). So, we
// rely on nested calls to our busy widget to have it remain
// visible until it gets hidden in updateGui()...

if (readFileWithBusyWidget(fileNameOrUrl, fileContents, &errorMessage)) {
// Note: we don't subsequently hide our busy widget in case we are
// loading a SED-ML file / COMBINE archive. Indeed, such files may
// require further initialisation (in the case of the Simulation
// Experiment view, for example). So, instead, our busy widget
// will get hidden in updateGui()...

if (readFile(fileNameOrUrl, fileContents, &errorMessage)) {
// We were able to retrieve the contents of the remote file, so ask
// our file manager to create a new remote file

Expand Down Expand Up @@ -983,19 +984,14 @@ void CentralWidget::reloadFile(int pIndex, bool pForce)
QString errorMessage;

showBusyWidget();
// Note: our call to readFileWithBusyWidget() will also show
// a busy widget, but it will also hide it while we
// want to keep it visible in case we are reloading a
// SED-ML file / COMBINE archive. Indeed, such files
// may require further initialisation (in the case of
// the Simulation Experiment view, for example). So,
// we rely on nested calls to our busy widget to have
// it remain visible until it gets hidden in
// updateGui()...

bool res = readFileWithBusyWidget(url, fileContents, &errorMessage);

if (res) {
// Note: we don't subsequently hide our busy widget in case
// we are loading a SED-ML file / COMBINE archive.
// Indeed, such files may require further
// initialisation (in the case of the Simulation
// Experiment view, for example). So, instead, our
// busy widget will get hidden in updateGui()...

if (readFile(url, fileContents, &errorMessage)) {
writeFile(fileName, fileContents);

fileManagerInstance->reload(fileName);
Expand Down Expand Up @@ -1667,6 +1663,38 @@ void CentralWidget::setTabBarCurrentIndex(TabBarWidget *pTabBar, int pIndex)

//==============================================================================

void CentralWidget::showEnableActions(const QList<QAction *> &pActions)
{
// Show/enable or hide/disable the given actions, depending on whether they
// correspond to a menu with visible/enabled or hidden/disabled actions,
// respectively

foreach (QAction *action, pActions) {
QMenu *actionMenu = action->menu();

if (actionMenu) {
QList<QAction *> actionMenuActions = actionMenu->actions();

showEnableActions(actionMenuActions);

bool showEnable = false;

foreach (QAction *actionMenuAction, actionMenuActions) {
if ( !actionMenuAction->isSeparator()
&& actionMenuAction->isVisible()) {
showEnable = true;

break;
}
}

showEnableAction(action, showEnable);
}
}
}

//==============================================================================

void CentralWidget::updateGui()
{
TabBarWidget *tabBar = qobject_cast<TabBarWidget *>(sender());
Expand Down Expand Up @@ -1855,10 +1883,6 @@ void CentralWidget::updateGui()
updateStatusBarWidgets(QList<QWidget *>());
}

// Let people know that we are about to update the GUI

emit guiUpdated(viewPlugin, fileName);

// Replace the current view with the new one, if needed
// Note: we have to do various things depending on the platform on which we
// are as well as over which widget we are when needing to replace the
Expand Down Expand Up @@ -1897,11 +1921,21 @@ void CentralWidget::updateGui()

// Force the hiding of our busy widget (useful in some cases, e.g. when we
// open/reload a remote file)
// Note: we need to force the hiding in case we are starting OpenCOR with a
// remote SED-ML file / COMBINE archive, which result in more calls to
// showBusyWidget() than to hideBusyWidget()...

hideBusyWidget(true);
hideBusyWidget();

// Let our different plugins know that the GUI has been updated
// Note: this can be useful when a plugin (e.g. CellMLTools) offers some
// tools that may need to be enabled/disabled and shown/hidden,
// depending on which view plugin and/or file are currently active...

foreach (Plugin *plugin, mLoadedGuiPlugins)
qobject_cast<GuiInterface *>(plugin->instance())->updateGui(viewPlugin, fileName);

// Go through our different menus and show/hide them, depending on whether
// they have visible items

showEnableActions(mainWindow()->menuBar()->actions());

// Give the focus to the new view after first checking that it has a focused
// widget
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/miscellaneous/Core/src/centralwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ class CentralWidget : public Widget
bool closeFile(int pIndex, bool pForceClosing);
void closeAllFiles(bool pForceClosing);

signals:
void guiUpdated(OpenCOR::Plugin *pViewPlugin, const QString &pFileName);
void showEnableActions(const QList<QAction *> &pActions);

signals:
void atLeastOneView(bool pAtLeastOneView);

void canSave(bool pEnabled);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/miscellaneous/Core/src/commonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ bool CommonWidget::isBusyWidgetVisible() const

void CommonWidget::showBusyWidget(double pProgress)
{
// Create and show our new busy widget resized, and then disable our parent
// Create and show our new busy widget resized, and then disable our parent,
// but only if we are visible (i.e. our parent is visible)

if (++mCounter == 1) {
if (mParent->isVisible() && (++mCounter == 1)) {
mBusyWidget = new BusyWidget(mParent, pProgress);

resizeBusyWidget();
Expand Down
35 changes: 0 additions & 35 deletions src/plugins/miscellaneous/Core/src/coreguiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,41 +86,6 @@ CentralWidget * centralWidget()

//==============================================================================

bool readFileWithBusyWidget(const QString &pUrl,
QByteArray &pFileContents,
QString *pErrorMessage)
{
// Read the contents of the file, which URL is given, showing our busy
// widget

centralWidget()->showBusyWidget();

bool res = readFile(pUrl, pFileContents, pErrorMessage);

centralWidget()->hideBusyWidget();

return res;
}

//==============================================================================

bool readFileWithBusyWidget(const QString &pUrl,
QString &pFileContents,
QString *pErrorMessage)
{
// Read the contents of the file, which URL is given

QByteArray fileContents = QByteArray();

bool res = readFileWithBusyWidget(pUrl, fileContents, pErrorMessage);

pFileContents = fileContents;

return res;
}

//==============================================================================

QString allFilters(const QStringList &pFilters)
{
QStringList filters = pFilters;
Expand Down
7 changes: 0 additions & 7 deletions src/plugins/miscellaneous/Core/src/coreguiutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ class CORE_EXPORT StyledItemDelegate : public QStyledItemDelegate

CentralWidget CORE_EXPORT * centralWidget();

bool CORE_EXPORT readFileWithBusyWidget(const QString &pUrl,
QByteArray &pFileContents,
QString *pErrorMessage = 0);
bool CORE_EXPORT readFileWithBusyWidget(const QString &pUrl,
QString &pFileContents,
QString *pErrorMessage = 0);

QString CORE_EXPORT getOpenFileName(const QString &pCaption,
const QStringList &pFilters = QStringList(),
QString *pSelectedFilter = 0);
Expand Down

0 comments on commit 0b41770

Please sign in to comment.