refs #735, allow to reset highlighting

(some leftovers of DB object highlighting also deleted)
This commit is contained in:
Klaus Basan
2016-08-15 21:09:06 +02:00
committed by Mathew Sutcliffe
parent 2434c7bbe2
commit b324a26747
9 changed files with 50 additions and 23 deletions

View File

@@ -197,5 +197,12 @@ namespace BlackGui
}
return QVariant();
}
void CAircraftModelListModel::clearHighlighting()
{
this->m_highlightModelStrings = false;
this->m_highlightStrings.clear();
COrderableListModelDbObjects::clearHighlighting();
}
} // namespace
} // namespace

View File

@@ -72,6 +72,9 @@ namespace BlackGui
//! The highlight color
void setHighlightModelStringsColor(const QBrush &brush) { m_highlightColor = brush; }
//! \copydoc CListModelBase::clearHighlighting
virtual void clearHighlighting() override;
//! Model strings
QStringList getModelStrings(bool sort) const;
@@ -86,7 +89,7 @@ namespace BlackGui
private:
AircraftModelMode m_mode = NotSet; //!< current mode
bool m_highlightModelStrings = false; //!< highlight in in model strings
bool m_highlightModelStrings = false; //!< highlight if in m_highlightStrings
QStringList m_highlightStrings; //!< model strings to highlight
QBrush m_highlightColor{Qt::yellow}; //!< how to highlight
};

View File

@@ -210,6 +210,11 @@ namespace BlackGui
emit this->dataChanged(topLeft, bottomRight);
}
void CListModelBaseNonTemplate::clearHighlighting()
{
// can be overridden to delete highlighting
}
void CListModelBaseNonTemplate::emitDataChanged(int startRowIndex, int endRowIndex)
{
BLACK_VERIFY_X(startRowIndex <= endRowIndex, Q_FUNC_INFO, "check rows");

View File

@@ -111,6 +111,9 @@ namespace BlackGui
//! Hovered role
void setHoveredRow(int row);
//! Remove all highlighting
virtual void clearHighlighting();
//! Drop actions
void setDropActions(Qt::DropActions dropActions) { this->m_dropActions = dropActions; }

View File

@@ -36,18 +36,8 @@ namespace BlackGui
QVariant CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::data(const QModelIndex &index, int role) const
{
if (role != Qt::BackgroundRole) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
if (isHighlightIndex(index)) { return QBrush(m_highlightColor); }
if (!highlightDbData()) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
const ObjectType obj(this->at(index));
// highlight DB models
if (obj.hasValidDbKey())
{
static const QBrush b(Qt::green);
return b;
}
return QVariant();
return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role);
}
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>

View File

@@ -47,15 +47,19 @@ namespace BlackGui
//! Destructor
virtual ~CListModelDbObjects() {}
//! Highlight the DB models
bool highlightDbData() const { return m_highlightDbData; }
//! Highlight the DB models
void setHighlightDbData(bool highlightDbData) { m_highlightDbData = highlightDbData; }
//! Keys to be highlighted
void setHighlightDbKeys(const QList<KeyType> &keys) { m_highlightKeys = keys; }
//! Clear the highlighted keys
void clearHighlightingDbKeys() { m_highlightKeys.clear(); }
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::clearHighlighting
virtual void clearHighlighting() override
{
this->clearHighlightingDbKeys();
CListModelBase<ObjectType, ContainerType, UseCompare>::clearHighlighting();
}
//! Set color for highlighting
void setHighlightColor(QColor color) { m_highlightColor = color; }
@@ -73,12 +77,10 @@ namespace BlackGui
CListModelDbObjects(const QString &translationContext, QObject *parent = nullptr);
private:
bool m_highlightDbData = false; //!< highlight if DB data entry (valid key)
QList<KeyType> m_highlightKeys; //!< keys to be highlighted
QColor m_highlightColor = Qt::green;
};
//! List model for DB objects
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare = false> class COrderableListModelDbObjects :
public CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>