mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3136 Fix RFT/PLT plots and refactor the way Mdi windows are resized when adding/removing plot tracks.
This commit is contained in:
@@ -422,6 +422,35 @@ QList<QMdiSubWindow*> RiuPlotMainWindow::subWindowList(QMdiArea::WindowOrder ord
|
||||
return m_mdiArea->subWindowList(order);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPlotMainWindow::setWidthOfMdiWindow(QWidget* mdiWindowWidget, int newWidth)
|
||||
{
|
||||
QMdiSubWindow* mdiWindow = findMdiSubWindow(mdiWindowWidget);
|
||||
if (mdiWindow)
|
||||
{
|
||||
QSize subWindowSize = mdiWindow->size();
|
||||
int currentWidth = subWindowSize.width();
|
||||
|
||||
subWindowSize.setWidth(std::max(newWidth, 100));
|
||||
mdiWindow->resize(subWindowSize);
|
||||
|
||||
if (mdiWindow->isMaximized())
|
||||
{
|
||||
// Set window temporarily to normal state and back to maximized
|
||||
// to redo layout so the whole window canvas is filled
|
||||
// Tried to activate layout, did not work as expected
|
||||
// Tested code:
|
||||
// m_layout->activate();
|
||||
// mdiWindow->layout()->activate();
|
||||
|
||||
mdiWindow->showNormal();
|
||||
mdiWindow->showMaximized();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -498,7 +527,9 @@ void RiuPlotMainWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& w
|
||||
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(subWin->widget());
|
||||
if (wellLogPlot)
|
||||
{
|
||||
subWindowSize = QSize(275, m_mdiArea->height());
|
||||
QSize preferredSize = wellLogPlot->preferredSize();
|
||||
subWindowSize =
|
||||
QSize(preferredSize.width(), m_mdiArea->height());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
QMdiSubWindow* findMdiSubWindow(QWidget* viewer);
|
||||
QList<QMdiSubWindow*> subWindowList(QMdiArea::WindowOrder order);
|
||||
|
||||
void setWidthOfMdiWindow(QWidget* mdiWindowWidget, int newWidth);
|
||||
void addToTemporaryWidgets(QWidget* widget);
|
||||
|
||||
void updateSummaryPlotToolBar();
|
||||
|
||||
@@ -94,7 +94,7 @@ RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefiniti
|
||||
rightColumnLayout->addWidget(m_plotDefinition->tofAccumulatedPhaseFractionsPlot()->createViewWidget(this), Qt::AlignTop);
|
||||
rightColumnLayout->addStretch();
|
||||
|
||||
QWidget* wellFlowWidget = m_plotDefinition->accumulatedWellFlowPlot()->createViewWidget(this);
|
||||
QWidget* wellFlowWidget = m_plotDefinition->accumulatedWellFlowPlot()->createPlotWidget();
|
||||
|
||||
plotWidgetsLayout->addWidget(wellFlowWidget);
|
||||
}
|
||||
|
||||
@@ -120,8 +120,6 @@ void RiuWellLogPlot::insertTrackPlot(RiuWellLogTrack* trackPlot, size_t index)
|
||||
legend->connect(trackPlot, SIGNAL(legendDataChanged(const QVariant &, const QList< QwtLegendData > &)), SLOT(updateLegend(const QVariant &, const QList< QwtLegendData > &)));
|
||||
legend->contentsWidget()->layout()->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
|
||||
m_legends.insert(static_cast<int>(index), legend);
|
||||
|
||||
this->connect(trackPlot, SIGNAL(legendDataChanged(const QVariant &, const QList< QwtLegendData > &)), SLOT(scheduleUpdateChildrenLayout()));
|
||||
|
||||
if (!m_plotDefinition->areTrackLegendsVisible())
|
||||
{
|
||||
@@ -138,8 +136,6 @@ void RiuWellLogPlot::insertTrackPlot(RiuWellLogTrack* trackPlot, size_t index)
|
||||
{
|
||||
trackPlot->hide();
|
||||
}
|
||||
|
||||
modifyWidthOfContainingMdiWindow(trackPlot->width());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -149,8 +145,6 @@ void RiuWellLogPlot::removeTrackPlot(RiuWellLogTrack* trackPlot)
|
||||
{
|
||||
if (!trackPlot) return;
|
||||
|
||||
int windowWidthChange = - trackPlot->width();
|
||||
|
||||
int trackIdx = m_trackPlots.indexOf(trackPlot);
|
||||
CVF_ASSERT(trackIdx >= 0);
|
||||
|
||||
@@ -160,51 +154,6 @@ void RiuWellLogPlot::removeTrackPlot(RiuWellLogTrack* trackPlot)
|
||||
QwtLegend* legend = m_legends[trackIdx];
|
||||
m_legends.removeAt(trackIdx);
|
||||
delete legend;
|
||||
|
||||
modifyWidthOfContainingMdiWindow(windowWidthChange);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuWellLogPlot::modifyWidthOfContainingMdiWindow(int widthChange)
|
||||
{
|
||||
RiuPlotMainWindow* plotWindow = RiaApplication::instance()->getOrCreateMainPlotWindow();
|
||||
QMdiSubWindow* mdiWindow = plotWindow->findMdiSubWindow(this);
|
||||
if (mdiWindow)
|
||||
{
|
||||
if (m_trackPlots.size() == 0 && widthChange <= 0) return; // Last track removed. Leave be
|
||||
|
||||
QSize subWindowSize = mdiWindow->size();
|
||||
int newWidth = 0;
|
||||
|
||||
if (m_trackPlots.size() == 1 && widthChange > 0) // First track added
|
||||
{
|
||||
newWidth = widthChange;
|
||||
}
|
||||
else
|
||||
{
|
||||
newWidth = subWindowSize.width() + widthChange;
|
||||
}
|
||||
|
||||
if (newWidth < 0) newWidth = 100;
|
||||
|
||||
subWindowSize.setWidth(newWidth);
|
||||
mdiWindow->resize(subWindowSize);
|
||||
|
||||
if (mdiWindow->isMaximized())
|
||||
{
|
||||
// Set window temporarily to normal state and back to maximized
|
||||
// to redo layout so the whole window canvas is filled
|
||||
// Tried to activate layout, did not work as expected
|
||||
// Tested code:
|
||||
// m_layout->activate();
|
||||
// mdiWindow->layout()->activate();
|
||||
|
||||
mdiWindow->showNormal();
|
||||
mdiWindow->showMaximized();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -233,9 +182,24 @@ void RiuWellLogPlot::setPlotTitle(const QString& plotTitle)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiuWellLogPlot::sizeHint() const
|
||||
QSize RiuWellLogPlot::preferredSize() const
|
||||
{
|
||||
return QSize(1,1);
|
||||
int titleWidth = 0;
|
||||
int titleHeight = 0;
|
||||
if (m_plotTitle && m_plotTitle->isVisible())
|
||||
{
|
||||
titleWidth = m_plotTitle->width();
|
||||
titleHeight = m_plotTitle->height() + 10;
|
||||
}
|
||||
|
||||
int sumTrackWidth = 0;
|
||||
int maxTrackHeight = 0;
|
||||
for (QPointer<RiuWellLogTrack> track : m_trackPlots)
|
||||
{
|
||||
sumTrackWidth += track->width();
|
||||
maxTrackHeight = std::max(maxTrackHeight, track->height());
|
||||
}
|
||||
return QSize(std::max(titleWidth, sumTrackWidth), titleHeight + maxTrackHeight);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -259,6 +223,14 @@ void RiuWellLogPlot::contextMenuEvent(QContextMenuEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiuWellLogPlot::sizeHint() const
|
||||
{
|
||||
return QSize(1, 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -327,7 +299,7 @@ void RiuWellLogPlot::resizeEvent(QResizeEvent *event)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<int, int> RiuWellLogPlot::calculateTrackWidths(int frameWidth)
|
||||
std::map<int, int> RiuWellLogPlot::calculateTrackWidthsToMatchFrame(int frameWidth) const
|
||||
{
|
||||
int trackCount = m_trackPlots.size();
|
||||
|
||||
@@ -341,6 +313,12 @@ std::map<int, int> RiuWellLogPlot::calculateTrackWidths(int frameWidth)
|
||||
{
|
||||
firstTrackAxisOffset = static_cast<int>(m_trackPlots[tIdx]->plotLayout()->canvasRect().left());
|
||||
}
|
||||
else if (visibleTrackCount == 1)
|
||||
{
|
||||
// The others axes also have markers, and so we need to subtract for this to get the shift due to labels and title
|
||||
int otherTrackAxisOffset = static_cast<int>(m_trackPlots[tIdx]->plotLayout()->canvasRect().left());
|
||||
firstTrackAxisOffset -= otherTrackAxisOffset;
|
||||
}
|
||||
++visibleTrackCount;
|
||||
}
|
||||
}
|
||||
@@ -402,7 +380,7 @@ void RiuWellLogPlot::placeChildWidgets(int frameHeight, int frameWidth)
|
||||
|
||||
const int trackPadding = 4;
|
||||
|
||||
std::map<int, int> trackWidths = calculateTrackWidths(frameWidth);
|
||||
std::map<int, int> trackWidths = calculateTrackWidthsToMatchFrame(frameWidth);
|
||||
size_t visibleTrackCount = trackWidths.size();
|
||||
|
||||
int maxLegendHeight = 0;
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
void setDepthZoomAndReplot(double minDepth, double maxDepth);
|
||||
void setPlotTitle(const QString& plotTitle);
|
||||
|
||||
virtual QSize preferredSize() const;
|
||||
public slots:
|
||||
void updateChildrenLayout();
|
||||
|
||||
@@ -67,13 +67,12 @@ protected:
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
virtual void showEvent(QShowEvent *);
|
||||
virtual void changeEvent(QEvent *);
|
||||
virtual QSize sizeHint() const override;
|
||||
virtual void contextMenuEvent(QContextMenuEvent *) override;
|
||||
virtual QSize sizeHint() const override;
|
||||
|
||||
private:
|
||||
void updateScrollBar(double minDepth, double maxDepth);
|
||||
void modifyWidthOfContainingMdiWindow(int widthChange);
|
||||
std::map<int, int> calculateTrackWidths(int frameWidth);
|
||||
std::map<int, int> calculateTrackWidthsToMatchFrame(int frameWidth) const;
|
||||
void placeChildWidgets(int frameHeight, int frameWidth);
|
||||
void positionTitle(int frameWidth);
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ void RiuWellLogTrack::setDefaults()
|
||||
axisScaleEngine(QwtPlot::xTop)->setAttribute(QwtScaleEngine::Floating, true);
|
||||
axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating, true);
|
||||
setAxisScale(QwtPlot::yLeft, 1000, 0);
|
||||
setAxisScale(QwtPlot::xTop, -10, 100);
|
||||
setXRange(0, 100);
|
||||
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ void RiuWellLogTrack::setAutoTickIntervalCounts(int maxMajorTickIntervalCount, i
|
||||
this->setAxisMaxMinor(QwtPlot::xTop, maxMinorTickIntervalCount);
|
||||
// Reapply axis limits to force Qwt to use the tick settings.
|
||||
QwtInterval currentRange = this->axisInterval(QwtPlot::xTop);
|
||||
this->setAxisScale(QwtPlot::xTop, currentRange.minValue(), currentRange.maxValue());
|
||||
this->setXRange(currentRange.minValue(), currentRange.maxValue());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -77,7 +77,7 @@ RiuWellPltPlot::RiuWellPltPlot(RimWellPltPlot* plotDefinition, QWidget* parent)
|
||||
mainLayout->addLayout(plotWidgetsLayout);
|
||||
plotWidgetsLayout->addLayout(rightColumnLayout);
|
||||
|
||||
QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createViewWidget(this);
|
||||
QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createPlotWidget();
|
||||
|
||||
plotWidgetsLayout->addWidget(wellFlowWidget);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ RiuWellRftPlot::RiuWellRftPlot(RimWellRftPlot* plotDefinition, QWidget* parent)
|
||||
mainLayout->addLayout(plotWidgetsLayout);
|
||||
plotWidgetsLayout->addLayout(rightColumnLayout);
|
||||
|
||||
QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createViewWidget(this);
|
||||
QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createPlotWidget();
|
||||
|
||||
plotWidgetsLayout->addWidget(wellFlowWidget);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user