Skip to content

Commit

Permalink
General: addressed a problem with quickly changing files potentially …
Browse files Browse the repository at this point in the history
…resulting in the wrong view being shown (closes #1481).
  • Loading branch information
agarny committed Dec 2, 2017
2 parents a3029c6 + 9b18d52 commit 5ca1a92
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var jsonData = { "versions": [
}
],
"changes": [
{ "change": "<strong>General:</strong> addressed a problem with quickly changing files potentially resulting in the wrong view being shown (see issue <a href=\"https://github.com/opencor/opencor/issues/1481\">#1481</a>)." },
{ "change": "<strong>Graph panel widget:</strong> have the legend buttons use the same background as the plot area (see issue <a href=\"https://github.com/opencor/opencor/issues/1477\">#1477</a>). Got the legend context menu to work again (see issue <a href=\"https://github.com/opencor/opencor/issues/1478\">#1478</a>)." }
]
},
Expand Down
20 changes: 19 additions & 1 deletion src/plugins/miscellaneous/Core/src/centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,9 +1578,22 @@ QString CentralWidget::viewKey(const int &pMode, const int &pView,

void CentralWidget::updateGui()
{
TabBarWidget *tabBarWidget = qobject_cast<TabBarWidget *>(sender());

if (mState != Idling) {
// We are doing something, so too risky to update the GUI during that
// time (e.g. things may not be fully initialised)
// time (e.g. things may not be fully initialised), so revert to our old
// tab index, if possible

if (tabBarWidget) {
disconnect(tabBarWidget, SIGNAL(currentChanged(int)),
this, SLOT(updateGui()));

tabBarWidget->setCurrentIndex(tabBarWidget->oldIndex());

connect(tabBarWidget, SIGNAL(currentChanged(int)),
this, SLOT(updateGui()));
}

return;
}
Expand All @@ -1589,6 +1602,11 @@ void CentralWidget::updateGui()

mState = UpdatingGui;

// Keep track of our future old tab index, if possible

if (tabBarWidget)
tabBarWidget->setOldIndex(tabBarWidget->currentIndex());

// Determine whether we are here as a result of changing files, modes or
// views

Expand Down
21 changes: 20 additions & 1 deletion src/plugins/miscellaneous/Core/src/tabbarwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ void TabBarStyle::tabLayout(const QStyleOptionTab *pOption,
//==============================================================================

TabBarWidget::TabBarWidget(QWidget *pParent) :
QTabBar(pParent)
QTabBar(pParent),
mOldIndex(-1)
{
// Customise our style, but only if we are on macOS
// Note: indeed, between Qt 5.6.x LTS and Qt 5.9.x LTS, the styling of a
Expand All @@ -264,6 +265,24 @@ TabBarWidget::TabBarWidget(QWidget *pParent) :

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

int TabBarWidget::oldIndex() const
{
// Return our old index

return mOldIndex;
}

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

void TabBarWidget::setOldIndex(const int &pOldIndex)
{
// Set our old index

mOldIndex = pOldIndex;
}

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

void TabBarWidget::wheelEvent(QWheelEvent *pEvent)
{
// Switch to the next/previous tab, if possible
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/miscellaneous/Core/src/tabbarwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ class CORE_EXPORT TabBarWidget : public QTabBar
public:
explicit TabBarWidget(QWidget *pParent);

int oldIndex() const;
void setOldIndex(const int &pOldIndex);

protected:
virtual void wheelEvent(QWheelEvent *pEvent);

virtual QSize tabSizeHint(int pIndex) const;

private:
int mOldIndex;
};

//==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,21 +1007,32 @@ void SimulationExperimentViewSimulationWidget::initialize(const bool &pReloading
// Further initialise ourselves, if we have a valid environment and we are
// not dealing with a CellML file

bool needProcessingEvents = false;

if ( validSimulationEnvironment
&& (mSimulation->fileType() != SimulationSupport::Simulation::CellmlFile)) {
// Further initialise ourselves, update our GUI (by reinitialising it)
// and initialise our simulation, if we still have a valid simulation
// environment

needProcessingEvents = true;

Core::centralWidget()->showBusyWidget();

bool validSimulationEnvironment = furtherInitialize();

initializeGui(validSimulationEnvironment);

if (validSimulationEnvironment)
initializeSimulation();

Core::centralWidget()->hideBusyWidget();
}

setUpdatesEnabled(true);

if (needProcessingEvents)
QCoreApplication::processEvents();
}

//==============================================================================
Expand Down

0 comments on commit 5ca1a92

Please sign in to comment.