mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 23:35:40 +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:
@@ -110,19 +110,6 @@ BlackGui--CDropSite {
|
|||||||
margin: 2px;
|
margin: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
QTableView[isShowingLoadIndicator="true"] {
|
|
||||||
background-image: url(:/preloaders/icons/preloaders/FillingRing64.gif);
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-position: center;
|
|
||||||
}
|
|
||||||
QTableView[isShowingLoadIndicator="false"] {
|
|
||||||
background-image: url(:/own/icons/own/transparent1px.png);
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-position: center;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Validator bar */
|
/* Validator bar */
|
||||||
BlackGui--Editors--CValidationIndicator {
|
BlackGui--Editors--CValidationIndicator {
|
||||||
background: black; /* background is background color here */
|
background: black; /* background is background color here */
|
||||||
|
|||||||
@@ -93,17 +93,25 @@ namespace BlackGui
|
|||||||
return CVariant::fromValue(static_cast<int>(cs));
|
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
|
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
|
// always supported
|
||||||
if (roleEnum == Qt::TextAlignmentRole) return { alignmentRole() };
|
if (roleEnum == Qt::TextAlignmentRole) return { alignmentRole() };
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (role == Qt::UserRole) { return CDefaultFormatter::displayRole(inputData); } // just as data provider
|
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)
|
switch (roleEnum)
|
||||||
{
|
{
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ namespace BlackGui
|
|||||||
//! Alignment available?
|
//! Alignment available?
|
||||||
virtual bool hasAlignment() const { return m_alignment >= 0; }
|
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
|
//! 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;
|
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);
|
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>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
CListModelBase<ObjectType, ContainerType, UseCompare>::CListModelBase(const QString &translationContext, QObject *parent)
|
CListModelBase<ObjectType, ContainerType, UseCompare>::CListModelBase(const QString &translationContext, QObject *parent)
|
||||||
: CListModelBaseNonTemplate(translationContext, parent)
|
: CListModelBaseNonTemplate(translationContext, parent)
|
||||||
@@ -282,12 +289,26 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
// check / init
|
// check / init
|
||||||
if (!this->isValidIndex(index)) { return QVariant(); }
|
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);
|
const CDefaultFormatter *formatter = this->m_columns.getFormatter(index);
|
||||||
Q_ASSERT_X(formatter, Q_FUNC_INFO, "Missing formatter");
|
Q_ASSERT_X(formatter, Q_FUNC_INFO, "Missing formatter");
|
||||||
if (!formatter) { return QVariant(); }
|
|
||||||
|
|
||||||
//! Formatted data
|
// Upfront checking avoids unnecessary data fetching
|
||||||
ObjectType obj = this->containerOrFilteredContainer()[index.row()];
|
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());
|
BlackMisc::CPropertyIndex propertyIndex = this->columnToPropertyIndex(index.column());
|
||||||
return formatter->data(role, obj.propertyByIndex(propertyIndex)).getQVariant();
|
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)
|
bool CListModelBase<ObjectType, ContainerType, UseCompare>::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
Qt::ItemDataRole dataRole = static_cast<Qt::ItemDataRole>(role);
|
Qt::ItemDataRole dataRole = static_cast<Qt::ItemDataRole>(role);
|
||||||
if (!(dataRole == Qt::UserRole || dataRole == Qt::EditRole))
|
if (!(dataRole == Qt::UserRole || dataRole == Qt::EditRole)) { return false; }
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check / init
|
// check / init
|
||||||
if (!this->isValidIndex(index))
|
if (!this->isValidIndex(index)) { return false; }
|
||||||
{
|
if (!this->m_columns.isEditable(index)) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!this->m_columns.isEditable(index))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const CDefaultFormatter *formatter = this->m_columns.getFormatter(index);
|
const CDefaultFormatter *formatter = this->m_columns.getFormatter(index);
|
||||||
Q_ASSERT(formatter);
|
Q_ASSERT(formatter);
|
||||||
if (!formatter)
|
if (!formatter) { return false; }
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectType obj = this->m_container[index.row()];
|
ObjectType obj = this->m_container[index.row()];
|
||||||
ObjectType currentObject(obj);
|
ObjectType currentObject(obj);
|
||||||
|
|||||||
@@ -161,11 +161,15 @@ namespace BlackGui
|
|||||||
//! Helper method with template free signature
|
//! Helper method with template free signature
|
||||||
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort) = 0;
|
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort) = 0;
|
||||||
|
|
||||||
CColumns m_columns; //!< columns metadata
|
//! Row to be hovered?
|
||||||
int m_sortedColumn; //!< current sort column
|
bool isHoveredRow(const QModelIndex &modelIndex) const;
|
||||||
bool m_modelDestroyed = false; //!< model is about to be destroyed
|
|
||||||
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
CColumns m_columns; //!< columns metadata
|
||||||
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
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:
|
private:
|
||||||
BlackMisc::CDigestSignal m_dsModelsChanged { this, &CListModelBaseNonTemplate::changed, &CListModelBaseNonTemplate::ps_onChangedDigest, 500, 10 };
|
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 (isHighlightIndex(index)) { return QBrush(m_highlightColor); }
|
||||||
if (!highlightDbData()) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
|
if (!highlightDbData()) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
|
||||||
|
|
||||||
ObjectType obj(this->at(index));
|
const ObjectType obj(this->at(index));
|
||||||
// highlight DB models
|
// highlight DB models
|
||||||
if (obj.hasValidDbKey())
|
if (obj.hasValidDbKey())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -303,20 +303,17 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (sm != MultiSelection)
|
if (sm != MultiSelection)
|
||||||
{
|
{
|
||||||
QAction *a = menuActions.addAction("Switch to multi selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_toggleSelectionMode });
|
menuActions.addAction("Switch to multi selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_setMultiSelection });
|
||||||
a->setData(MultiSelection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm != ExtendedSelection)
|
if (sm != ExtendedSelection)
|
||||||
{
|
{
|
||||||
QAction *a = menuActions.addAction("Switch to extended selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_toggleSelectionMode });
|
menuActions.addAction("Switch to extended selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_setExtendedSelection });
|
||||||
a->setData(ExtendedSelection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm != SingleSelection)
|
if (sm != SingleSelection)
|
||||||
{
|
{
|
||||||
QAction *a = menuActions.addAction("Switch to single selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_toggleSelectionMode });
|
menuActions.addAction("Switch to single selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_setSingleSelection });
|
||||||
a->setData(SingleSelection);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,20 +625,28 @@ namespace BlackGui
|
|||||||
this->m_displayAutomatically = a->isChecked();
|
this->m_displayAutomatically = a->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_toggleSelectionMode()
|
|
||||||
|
void CViewBaseNonTemplate::ps_setSingleSelection()
|
||||||
{
|
{
|
||||||
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
this->setSelectionMode(SingleSelection);
|
||||||
if (action && action->data().isValid() && action->data().canConvert<int>())
|
}
|
||||||
{
|
}
|
||||||
SelectionMode sm = static_cast<SelectionMode>(action->data().toInt());
|
|
||||||
this->setSelectionMode(sm);
|
void CViewBaseNonTemplate::ps_setExtendedSelection()
|
||||||
}
|
{
|
||||||
else
|
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
||||||
{
|
{
|
||||||
this->setSelectionMode(this->m_originalSelectionMode);
|
this->setSelectionMode(ExtendedSelection);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CViewBaseNonTemplate::ps_setMultiSelection()
|
||||||
|
{
|
||||||
|
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
||||||
|
{
|
||||||
|
this->setSelectionMode(MultiSelection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -962,7 +967,7 @@ namespace BlackGui
|
|||||||
// see model for implementing logic of drag
|
// see model for implementing logic of drag
|
||||||
this->viewport()->setAcceptDrops(allowDrop);
|
this->viewport()->setAcceptDrops(allowDrop);
|
||||||
this->setDragEnabled(allowDrag);
|
this->setDragEnabled(allowDrag);
|
||||||
this->setDropIndicatorShown(allowDrop);
|
this->setDropIndicatorShown(allowDrag || allowDrop);
|
||||||
this->m_model->allowDrop(allowDrop);
|
this->m_model->allowDrop(allowDrop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -437,8 +437,12 @@ namespace BlackGui
|
|||||||
//! Toggle auto display flag
|
//! Toggle auto display flag
|
||||||
void ps_toggleAutoDisplay();
|
void ps_toggleAutoDisplay();
|
||||||
|
|
||||||
//! Toogle between single and multi selection
|
//! \name Change selection modes
|
||||||
void ps_toggleSelectionMode();
|
//! @{
|
||||||
|
void ps_setMultiSelection();
|
||||||
|
void ps_setExtendedSelection();
|
||||||
|
void ps_setSingleSelection();
|
||||||
|
//! @}
|
||||||
|
|
||||||
//! Clear the model
|
//! Clear the model
|
||||||
virtual void ps_clear() { this->clear(); }
|
virtual void ps_clear() { this->clear(); }
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QAction *> m_menuActions;
|
QList<QAction *> m_menuActions;
|
||||||
QLineEdit *m_leOrder = nullptr;
|
QLineEdit *m_leOrder = nullptr;
|
||||||
QFrame *m_frame = nullptr;
|
QFrame *m_frame = nullptr;
|
||||||
QIntValidator *m_validator = nullptr;
|
QIntValidator *m_validator = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user