mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
View / model fixes / improvements
* allow upfront checking of formatter roles * selection mode menus adjusted (data approach no longer worked with CSlot) * removed unused style sheet parts * minor View/Model tweaks/formatting
This commit is contained in:
@@ -93,17 +93,25 @@ namespace BlackGui
|
||||
return CVariant::fromValue(static_cast<int>(cs));
|
||||
}
|
||||
|
||||
bool CDefaultFormatter::supportsRole(int role) const
|
||||
{
|
||||
// generally supported?
|
||||
if (role == Qt::TextAlignmentRole || role == Qt::UserRole) { return true; }
|
||||
|
||||
// specific?
|
||||
return this->m_supportedRoles.contains(role);
|
||||
}
|
||||
|
||||
CVariant CDefaultFormatter::data(int role, const CVariant &inputData) const
|
||||
{
|
||||
Qt::ItemDataRole roleEnum = static_cast<Qt::ItemDataRole>(role);
|
||||
if (!this->supportsRole(role)) { return CVariant(); }
|
||||
const Qt::ItemDataRole roleEnum = static_cast<Qt::ItemDataRole>(role);
|
||||
|
||||
// always supported
|
||||
if (roleEnum == Qt::TextAlignmentRole) return { alignmentRole() };
|
||||
|
||||
// check
|
||||
if (role == Qt::UserRole) { return CDefaultFormatter::displayRole(inputData); } // just as data provider
|
||||
if (this->m_supportedRoles.isEmpty()) { return CVariant(); }
|
||||
if (!this->m_supportedRoles.contains(role)) { return CVariant(); }
|
||||
switch (roleEnum)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
|
||||
@@ -73,6 +73,9 @@ namespace BlackGui
|
||||
//! Alignment available?
|
||||
virtual bool hasAlignment() const { return m_alignment >= 0; }
|
||||
|
||||
//! Is given role supported by formatter
|
||||
bool supportsRole(int role) const;
|
||||
|
||||
//! Receives CVariant of column data, and returns CVariant wrapping string, pixmap, or other values depending on role
|
||||
virtual BlackMisc::CVariant data(int role, const BlackMisc::CVariant &inputData) const;
|
||||
|
||||
|
||||
@@ -225,6 +225,13 @@ namespace BlackGui
|
||||
connect(this, &CListModelBaseNonTemplate::dataChanged, this, &CListModelBaseNonTemplate::ps_onDataChanged);
|
||||
}
|
||||
|
||||
bool CListModelBaseNonTemplate::isHoveredRow(const QModelIndex &modelIndex) const
|
||||
{
|
||||
if (this->m_hoverRow < 0) { return false; }
|
||||
if (!modelIndex.isValid()) { return false; }
|
||||
return modelIndex.row() == this->m_hoverRow;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
CListModelBase<ObjectType, ContainerType, UseCompare>::CListModelBase(const QString &translationContext, QObject *parent)
|
||||
: CListModelBaseNonTemplate(translationContext, parent)
|
||||
@@ -282,12 +289,26 @@ namespace BlackGui
|
||||
{
|
||||
// check / init
|
||||
if (!this->isValidIndex(index)) { return QVariant(); }
|
||||
|
||||
// Hover effect
|
||||
if (role == Qt::BackgroundRole)
|
||||
{
|
||||
if (this->isHoveredRow(index))
|
||||
{
|
||||
return QBrush(Qt::red);
|
||||
}
|
||||
return CListModelBaseNonTemplate::data(index, role);
|
||||
}
|
||||
|
||||
// Formatter
|
||||
const CDefaultFormatter *formatter = this->m_columns.getFormatter(index);
|
||||
Q_ASSERT_X(formatter, Q_FUNC_INFO, "Missing formatter");
|
||||
if (!formatter) { return QVariant(); }
|
||||
|
||||
//! Formatted data
|
||||
ObjectType obj = this->containerOrFilteredContainer()[index.row()];
|
||||
// Upfront checking avoids unnecessary data fetching
|
||||
if (!formatter || !formatter->supportsRole(role)) { return CListModelBaseNonTemplate::data(index, role); }
|
||||
|
||||
// Formatted data
|
||||
const ObjectType obj = this->containerOrFilteredContainer()[index.row()];
|
||||
BlackMisc::CPropertyIndex propertyIndex = this->columnToPropertyIndex(index.column());
|
||||
return formatter->data(role, obj.propertyByIndex(propertyIndex)).getQVariant();
|
||||
}
|
||||
@@ -296,26 +317,14 @@ namespace BlackGui
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
Qt::ItemDataRole dataRole = static_cast<Qt::ItemDataRole>(role);
|
||||
if (!(dataRole == Qt::UserRole || dataRole == Qt::EditRole))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(dataRole == Qt::UserRole || dataRole == Qt::EditRole)) { return false; }
|
||||
|
||||
// check / init
|
||||
if (!this->isValidIndex(index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this->m_columns.isEditable(index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this->isValidIndex(index)) { return false; }
|
||||
if (!this->m_columns.isEditable(index)) { return false; }
|
||||
const CDefaultFormatter *formatter = this->m_columns.getFormatter(index);
|
||||
Q_ASSERT(formatter);
|
||||
if (!formatter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!formatter) { return false; }
|
||||
|
||||
ObjectType obj = this->m_container[index.row()];
|
||||
ObjectType currentObject(obj);
|
||||
|
||||
@@ -161,11 +161,15 @@ namespace BlackGui
|
||||
//! Helper method with template free signature
|
||||
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort) = 0;
|
||||
|
||||
CColumns m_columns; //!< columns metadata
|
||||
int m_sortedColumn; //!< current sort column
|
||||
bool m_modelDestroyed = false; //!< model is about to be destroyed
|
||||
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
||||
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
||||
//! Row to be hovered?
|
||||
bool isHoveredRow(const QModelIndex &modelIndex) const;
|
||||
|
||||
CColumns m_columns; //!< columns metadata
|
||||
int m_hoverRow = -1; //!< hovered row number
|
||||
int m_sortedColumn; //!< currently sorted column
|
||||
bool m_modelDestroyed = false; //!< model is about to be destroyed
|
||||
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
||||
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
||||
|
||||
private:
|
||||
BlackMisc::CDigestSignal m_dsModelsChanged { this, &CListModelBaseNonTemplate::changed, &CListModelBaseNonTemplate::ps_onChangedDigest, 500, 10 };
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace BlackGui
|
||||
if (isHighlightIndex(index)) { return QBrush(m_highlightColor); }
|
||||
if (!highlightDbData()) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
|
||||
|
||||
ObjectType obj(this->at(index));
|
||||
const ObjectType obj(this->at(index));
|
||||
// highlight DB models
|
||||
if (obj.hasValidDbKey())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user