Browse Source

Optimise widgets to avoid repaints/relayouts.

chirpmodem-v8.1.0
Jon Beniston 4 weeks ago
parent
commit
f5ff904d22
  1. 1
      plugins/channelrx/demoddab/dabcarrierplot.cpp
  2. 1
      sdrgui/dtv/dtvscope.cpp
  3. 55
      sdrgui/gui/rollupcontents.cpp
  4. 12
      sdrgui/gui/rollupcontents.h

1
plugins/channelrx/demoddab/dabcarrierplot.cpp

@ -31,6 +31,7 @@ DABCarrierPlot::DABCarrierPlot(QWidget *parent) : @@ -31,6 +31,7 @@ DABCarrierPlot::DABCarrierPlot(QWidget *parent) :
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setMinimumHeight(110);
setAttribute(Qt::WA_OpaquePaintEvent, true);
setToolTip(tr("Carrier to noise ratio of each carrier, from the null symbol.\n"
"Notches are multipath; dips over a few carriers are interference.\n"
"The dashed line is the median (the C/N statistic)."));

1
sdrgui/dtv/dtvscope.cpp

@ -50,6 +50,7 @@ DTVScope::DTVScope(QWidget *parent) : @@ -50,6 +50,7 @@ DTVScope::DTVScope(QWidget *parent) :
m_lastRowTime(0)
{
setMinimumSize(300, 150);
setAttribute(Qt::WA_OpaquePaintEvent, true);
setView(Response);
}

55
sdrgui/gui/rollupcontents.cpp

@ -33,8 +33,9 @@ RollupContents::RollupContents(QWidget* parent) : @@ -33,8 +33,9 @@ RollupContents::RollupContents(QWidget* parent) :
QWidget(parent),
m_streamIndicator("S"),
// m_channelWidget(true),
m_newHeight(0),
m_transparentBackground(false)
m_transparentBackground(false),
m_arranging(false),
m_arrangePending(false)
{
setMinimumSize(250, 150);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
@ -98,7 +99,7 @@ bool RollupContents::hasExpandableWidgets() @@ -98,7 +99,7 @@ bool RollupContents::hasExpandableWidgets()
{
QWidget* r = qobject_cast<QWidget*>(children()[i]);
if (r && isRollupChild(r) && !r->isHidden() && (r->sizePolicy().verticalPolicy() == QSizePolicy::Expanding)) {
if (r && isRollupChild(r) && !r->isHidden() && isExpandingChild(r)) {
return true;
}
}
@ -106,6 +107,36 @@ bool RollupContents::hasExpandableWidgets() @@ -106,6 +107,36 @@ bool RollupContents::hasExpandableWidgets()
return false;
}
int RollupContents::arrangeRollups()
{
// Resizing a child, or setting our own minimum height, can have Qt deliver a resize
// event synchronously, which comes straight back here. Running that nested would
// reposition the children from the inner call and then finish the outer one with a
// stale cursor. Note it instead and repeat the arrangement, so the sizes the nested
// call was reacting to are still taken into account
if (m_arranging)
{
m_arrangePending = true;
return m_minimumSizeHint.height();
}
m_arranging = true;
int pos = 0;
int passes = 0;
do
{
m_arrangePending = false;
pos = arrangeRollupsOnce();
}
while (m_arrangePending && (++passes < 4));
m_arranging = false;
return pos;
}
int RollupContents::arrangeRollupsOnce()
{
QFontMetrics fm(font());
int pos;
@ -124,7 +155,7 @@ int RollupContents::arrangeRollups() @@ -124,7 +155,7 @@ int RollupContents::arrangeRollups()
pos += fm.height() + 2;
if (!r->isHidden())
{
if (r->sizePolicy().verticalPolicy() & QSizePolicy::ExpandFlag) {
if (isExpandingChild(r)) {
expandingChildren++;
}
int h = 0;
@ -169,9 +200,13 @@ int RollupContents::arrangeRollups() @@ -169,9 +200,13 @@ int RollupContents::arrangeRollups()
// In the future, we should probably respect 'Vertical Stretch'
int extraSpace;
int firstExtra;
if ((expandingChildren > 0) && (m_newHeight > pos))
// height() rather than a value cached in resizeEvent: arrangeRollups() is called
// from layout requests, from children being shown or hidden and from clicks on the
// section headers, and in all of those the cached value is whatever the last resize
// happened to be - or zero before the first one
if ((expandingChildren > 0) && (height() > pos))
{
int totalExtra = m_newHeight - pos;
int totalExtra = height() - pos;
extraSpace = totalExtra / expandingChildren;
firstExtra = totalExtra - (extraSpace * expandingChildren);
}
@ -199,7 +234,7 @@ int RollupContents::arrangeRollups() @@ -199,7 +234,7 @@ int RollupContents::arrangeRollups()
} else {
h = r->minimumSizeHint().height();
}
if (r->sizePolicy().verticalPolicy() & QSizePolicy::ExpandFlag)
if (isExpandingChild(r))
{
h += extraSpace;
h += firstExtra;
@ -373,7 +408,6 @@ int RollupContents::paintRollup(QWidget* rollup, int pos, QPainter* p, bool last @@ -373,7 +408,6 @@ int RollupContents::paintRollup(QWidget* rollup, int pos, QPainter* p, bool last
void RollupContents::resizeEvent(QResizeEvent* size)
{
m_newHeight = size->size().height();
arrangeRollups();
QWidget::resizeEvent(size);
}
@ -472,3 +506,8 @@ bool RollupContents::isRollupChild(QWidget *childWidget) @@ -472,3 +506,8 @@ bool RollupContents::isRollupChild(QWidget *childWidget)
{
return (qobject_cast<QDialog*>(childWidget) == nullptr); // exclude Dialogs from rollups
}
bool RollupContents::isExpandingChild(const QWidget *childWidget)
{
return (childWidget->sizePolicy().verticalPolicy() & QSizePolicy::ExpandFlag) != 0;
}

12
sdrgui/gui/rollupcontents.h

@ -62,10 +62,20 @@ protected: @@ -62,10 +62,20 @@ protected:
private:
static bool isRollupChild(QWidget *childWidget); //!< chidl is part of rollups (ex: not a dialog)
//!< Whether a child takes a share of any space left over. MinimumExpanding carries
//!< ExpandFlag as well as Expanding, and hasExpandableWidgets() and arrangeRollups()
//!< have to agree, or the window is made fixed size while its contents expand
static bool isExpandingChild(const QWidget *childWidget);
int arrangeRollupsOnce();
// bool m_channelWidget;
int m_newHeight;
QSize m_minimumSizeHint;
bool m_transparentBackground;
//!< arrangeRollups() resizes children and sets our own minimum height, either of
//!< which can have Qt deliver a resize event synchronously and call us again while
//!< we are part way through positioning
bool m_arranging;
//!< Set when that happens, so the arrangement is repeated rather than lost
bool m_arrangePending;
};
#endif // INCLUDE_ROLLUPCONTENTS_H

Loading…
Cancel
Save