#3099 Apply QWT-hack to align tracks without xaxis markers and labels.

This commit is contained in:
Gaute Lindkvist 2018-06-26 11:01:21 +02:00
parent 405d470eda
commit ad17ee1050

View File

@ -32,6 +32,7 @@
#include "cvfAssert.h" #include "cvfAssert.h"
#include "qwt_legend.h" #include "qwt_legend.h"
#include "qwt_plot_layout.h"
#include <QFocusEvent> #include <QFocusEvent>
#include <QHBoxLayout> #include <QHBoxLayout>
@ -355,6 +356,18 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
if (visibleTrackCount) if (visibleTrackCount)
{ {
int maxCanvasOffset = 0;
for (int tIdx = 0; tIdx < trackCount; ++tIdx)
{
if (m_trackPlots[tIdx]->isVisible())
{
// Hack to align QWT plots. See below.
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
maxCanvasOffset = std::max(maxCanvasOffset, static_cast<int>(canvasRect.top()));
}
}
int trackWidth = (width - scrollBarWidth)/visibleTrackCount; int trackWidth = (width - scrollBarWidth)/visibleTrackCount;
int trackWidthExtra = (width-scrollBarWidth)%visibleTrackCount; int trackWidthExtra = (width-scrollBarWidth)%visibleTrackCount;
@ -362,14 +375,30 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
{ {
if (m_trackPlots[tIdx]->isVisible()) if (m_trackPlots[tIdx]->isVisible())
{ {
int realTrackWidth = trackWidth; int realTrackWidth = trackWidth;
if (trackWidthExtra > 0) if (trackWidthExtra > 0)
{ {
realTrackWidth += 1; realTrackWidth += 1;
--trackWidthExtra; --trackWidthExtra;
} }
int adjustedVerticalPosition = titleHeight + maxLegendHeight + 10;
int adjustedTrackHeight = trackHeight;
{
// Hack to align QWT plots which doesn't have an x-axis with the other tracks.
// Since they are missing the axis, QWT will shift them upwards.
// So we shift the plot downwards and resize to match the others.
// TODO: Look into subclassing QwtPlotLayout instead.
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
int myCanvasOffset = static_cast<int>(canvasRect.top());
int myMargins = m_trackPlots[tIdx]->plotLayout()->canvasMargin(QwtPlot::xTop);
int canvasShift = std::max(0, maxCanvasOffset - myCanvasOffset);
adjustedVerticalPosition += canvasShift - myMargins;
adjustedTrackHeight -= canvasShift;
}
m_legends[tIdx]->setGeometry(trackX + trackPadding, titleHeight, realTrackWidth - 2 * trackPadding, maxLegendHeight); m_legends[tIdx]->setGeometry(trackX + trackPadding, titleHeight, realTrackWidth - 2 * trackPadding, maxLegendHeight);
m_trackPlots[tIdx]->setGeometry(trackX + trackPadding, titleHeight + maxLegendHeight, realTrackWidth - 2 * trackPadding, trackHeight); m_trackPlots[tIdx]->setGeometry(trackX + trackPadding, adjustedVerticalPosition, realTrackWidth - 2 * trackPadding, adjustedTrackHeight);
trackX += realTrackWidth; trackX += realTrackWidth;
} }