refs #335, Minor tweaks:

* Formatting
* renaming
* fixed some issues of cppcheck
* new icons
* smooth scrolling in views, stretching for few columns
* fixed start timer in updatetimer
* background colors of some LEDs
This commit is contained in:
Klaus Basan
2014-10-24 23:55:36 +02:00
committed by Roland Winklmeier
parent a9768566e6
commit 43ecc238ed
36 changed files with 186 additions and 124 deletions

View File

@@ -19,6 +19,7 @@ namespace BlackGui
{
CNameVariantPairView::CNameVariantPairView(QWidget *parent) : CViewBase(parent)
{
m_forceStretchLastColumnWhenResized = true;
this->standardInit(new CNameVariantPairModel(true, this));
}
@@ -47,4 +48,4 @@ namespace BlackGui
return this->m_model->containsName(name);
}
}
}
} // namespace

View File

@@ -31,10 +31,10 @@ namespace BlackGui
void setIconMode(bool withIcon);
//! Update or add value, QVariant version
bool addOrUpdateByName(const QString &name, const QVariant &value, const BlackMisc::CIcon &icon = BlackMisc::CIcon(), bool resize = true, bool skipEqualValues = true);
bool addOrUpdateByName(const QString &name, const QVariant &value, const BlackMisc::CIcon &icon = BlackMisc::CIcon(), bool performResizing = true, bool skipEqualValues = true);
//! Remove by name
void removeByName(const QString &name, bool resize = true);
void removeByName(const QString &name, bool performResizing = true);
//! Contains name
bool containsName(const QString &name);

View File

@@ -40,6 +40,11 @@ namespace BlackGui
{
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::ps_customMenuRequested);
// scroll modes
this->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
this->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
}
void CViewBaseNonTemplate::customMenu(QMenu &menu) const
@@ -82,8 +87,8 @@ namespace BlackGui
void CViewBaseNonTemplate::initRowsResizeModeToInteractive()
{
const int h = this->verticalHeader()->minimumSectionSize();
this->setRowsResizeModeToInteractive(h);
const int height = this->verticalHeader()->minimumSectionSize();
this->setRowsResizeModeToInteractive(height);
}
void CViewBaseNonTemplate::setRowsResizeModeToInteractive(int height)
@@ -94,8 +99,9 @@ namespace BlackGui
verticalHeader->setDefaultSectionSize(height);
}
bool CViewBaseNonTemplate::resize() const
bool CViewBaseNonTemplate::performResizing() const
{
if (m_resizeMode == ResizingOff) { return false; }
if (m_resizeMode == ResizingOnce) { return m_resizeCount < 1; }
if (m_resizeMode == ResizingAuto)
{
@@ -103,7 +109,7 @@ namespace BlackGui
if (m_resizeAutoNthTime < 2) return true;
return (m_resizeCount % m_resizeAutoNthTime) == 0;
}
return m_resizeMode == ResizingOff;
return false;
}
void CViewBaseNonTemplate::fullResizeToContents()
@@ -115,7 +121,11 @@ namespace BlackGui
m_resizeCount++;
this->resizeColumnsToContents();
this->resizeRowsToContents();
if (m_forceStretchLastColumnWhenResized)
{
// re-stretch
this->horizontalHeader()->setStretchLastSection(true);
}
qDebug() << this->objectName() << "resize ms:" << t.elapsed() << QThread::currentThreadId();
}
@@ -158,7 +168,7 @@ namespace BlackGui
{
ContainerType sortedContainer = model->sortContainerByColumn(container, sortColumn, sortOrder);
QMetaObject::invokeMethod(this, "updateContainer",
Q_ARG(QVariant, sortedContainer.toQVariant()), Q_ARG(bool, false), Q_ARG(bool, resize));
Q_ARG(QVariant, sortedContainer.toQVariant()), Q_ARG(bool, false), Q_ARG(bool, resize));
});
worker->then(this, &CViewBase::asyncUpdateFinished);
return worker;
@@ -166,7 +176,7 @@ namespace BlackGui
template <class ModelClass, class ContainerType> void CViewBase<ModelClass, ContainerType>::updateContainerMaybeAsync(const ContainerType &container, bool sort, bool resize)
{
if (container.size() > asyncThreshold && sort)
if (container.size() > asyncRowsCountThreshold && sort)
{
// larger container with sorting
updateContainerAsync(container, sort, resize);
@@ -231,7 +241,7 @@ namespace BlackGui
template <class ModelClass, class ContainerType> void CViewBase<ModelClass, ContainerType>::performResizeToContents()
{
// small set or large set?
if (this->resize())
if (this->performResizing())
{
this->fullResizeToContents();
}

View File

@@ -38,11 +38,11 @@ namespace BlackGui
{
ResizingAuto, //!< always resizing, \sa m_resizeAutoNthTime
ResizingOnce, //!< only one time
ResizingOff
ResizingOff //!< never
};
//! When to use asynchronous updates
static const int asyncThreshold = 50;
//! When (rows count) to use asynchronous updates
static const int asyncRowsCountThreshold = 50;
//! Clear data
virtual void clear() = 0;
@@ -101,21 +101,22 @@ namespace BlackGui
//! \param variant contains the container
//! \param sort
//! \param resize
virtual int performUpdateContainer(const QVariant &variant, bool sort, bool resize) = 0;
virtual int performUpdateContainer(const QVariant &variant, bool sort, bool performResizing) = 0;
//! Skip resizing because of size?
virtual bool reachedResizeThreshold() const = 0;
//! Resize or skip resize?
virtual bool resize() const;
virtual bool performResizing() const;
//! Init default values
virtual void standardInit();
ResizeMode m_resizeMode = ResizingAuto; //!< mode
int m_resizeCount = 0; //!< flag / counter,how many resize activities
int m_skipResizeThreshold = 40; //!< when to skip resize
int m_resizeCount = 0; //!< flag / counter, how many resize activities
int m_skipResizeThreshold = 40; //!< when to skip resize (rows count)
int m_resizeAutoNthTime = 1; //!< with ResizeAuto, resize every n-th time
bool m_forceStretchLastColumnWhenResized = false; //! a small table might (few columns) might to fail stretching, force again
protected slots:
//! Helper method with template free signature serving as callback from threaded worker
@@ -153,13 +154,13 @@ namespace BlackGui
virtual void clear() override { Q_ASSERT(this->m_model); this->m_model->clear(); }
//! Update whole container
int updateContainer(const ContainerType &container, bool sort = true, bool resize = true);
int updateContainer(const ContainerType &container, bool sort = true, bool performResizing = true);
//! Update whole container in background
BlackMisc::CWorker *updateContainerAsync(const ContainerType &container, bool sort = true, bool resize = true);
BlackMisc::CWorker *updateContainerAsync(const ContainerType &container, bool sort = true, bool performResizing = true);
//! Based on size call sync / async update
void updateContainerMaybeAsync(const ContainerType &container, bool sort = true, bool resize = true);
void updateContainerMaybeAsync(const ContainerType &container, bool sort = true, bool performResizing = true);
//! Insert
template<class ObjectType> void insert(const ObjectType &value, bool resize = true)
@@ -211,7 +212,7 @@ namespace BlackGui
virtual void performResizeToContents() override;
//! \copydoc CViewBaseNonTemplate::performUpdateContainer
virtual int performUpdateContainer(const QVariant &variant, bool sort, bool resize) override;
virtual int performUpdateContainer(const QVariant &variant, bool sort, bool performResizing) override;
};
} // namespace