Fixes in model set form as described by RP

https://swift-project.slack.com/archives/G96QTUBEG/p1544353355002400

* fixed missing radio button groups
* return values for some functions to detect "changes"
* minor style fixes
This commit is contained in:
Klaus Basan
2018-12-10 01:35:04 +01:00
parent 9b06a159f2
commit 9f408e8319
9 changed files with 176 additions and 115 deletions

View File

@@ -20,6 +20,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QPointer> #include <QPointer>
using namespace BlackMisc;
using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation;
using namespace BlackGui::Models; using namespace BlackGui::Models;
using namespace BlackGui::Components; using namespace BlackGui::Components;
@@ -59,7 +60,7 @@ namespace BlackGui
const bool hasPreferences = this->hasDistributorPreferences(); const bool hasPreferences = this->hasDistributorPreferences();
ui->cb_SortByPreferences->setChecked(hasPreferences); ui->cb_SortByPreferences->setChecked(hasPreferences);
CGuiUtility::checkBoxReadOnly(ui->cb_SortByPreferences, !hasPreferences); CGuiUtility::checkBoxReadOnly(ui->cb_SortByPreferences, !hasPreferences);
ui->comp_SimulatorSelector->setValue(this->m_simulator); ui->comp_SimulatorSelector->setValue(m_simulator);
this->setDistributorView(hasPreferences); this->setDistributorView(hasPreferences);
this->initDistributorDisplay(); this->initDistributorDisplay();
} }
@@ -142,29 +143,23 @@ namespace BlackGui
{ {
ui->tvp_Distributors->setDistributorMode(hasPreferences ? CDistributorListModel::MinimalWithOrder : CDistributorListModel::Minimal); ui->tvp_Distributors->setDistributorMode(hasPreferences ? CDistributorListModel::MinimalWithOrder : CDistributorListModel::Minimal);
ui->tvp_Distributors->fullResizeToContents(); ui->tvp_Distributors->fullResizeToContents();
if (hasPreferences) const CPropertyIndex i = hasPreferences ? CPropertyIndex(CDistributor::IndexOrder) : CPropertyIndex(CDistributor::IndexDbStringKey);
{ ui->tvp_Distributors->sortByPropertyIndex(i);
ui->tvp_Distributors->setSorting(CDistributor::IndexOrder);
}
else
{
ui->tvp_Distributors->setSorting(CDistributor::IndexDbStringKey);
}
} }
CDistributorList COwnModelSetForm::getDistributorsFromPreferences() const CDistributorList COwnModelSetForm::getDistributorsFromPreferences() const
{ {
Q_ASSERT_X(this->m_simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); Q_ASSERT_X(m_simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
const CDistributorListPreferences prefs(this->m_distributorPreferences.get()); const CDistributorListPreferences prefs(m_distributorPreferences.get());
const CDistributorList distributors(prefs.getDistributors(this->m_simulator)); const CDistributorList distributors(prefs.getDistributors(m_simulator));
return distributors; return distributors;
} }
CDistributorList COwnModelSetForm::getAllDistributors() const CDistributorList COwnModelSetForm::getAllDistributors() const
{ {
Q_ASSERT_X(this->m_simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); Q_ASSERT_X(m_simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web data services"); Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web data services");
return sGui->getWebDataServices()->getDistributors().matchesSimulator(this->m_simulator); return sGui->getWebDataServices()->getDistributors().matchesSimulator(m_simulator);
} }
CDistributorList COwnModelSetForm::getDistributorsBasedOnOptions() const CDistributorList COwnModelSetForm::getDistributorsBasedOnOptions() const
@@ -199,8 +194,8 @@ namespace BlackGui
bool COwnModelSetForm::hasDistributorPreferences() const bool COwnModelSetForm::hasDistributorPreferences() const
{ {
const CDistributorListPreferences prefs(this->m_distributorPreferences.get()); const CDistributorListPreferences prefs(m_distributorPreferences.get());
return !prefs.getDistributors(this->m_simulator).isEmpty(); return !prefs.getDistributors(m_simulator).isEmpty();
} }
} // ns } // ns
} // ns } // ns

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>450</width> <width>350</width>
<height>350</height> <height>376</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
@@ -37,11 +37,21 @@
<property name="title"> <property name="title">
<string>Selection</string> <string>Selection</string>
</property> </property>
<layout class="QGridLayout" name="gl_Selection"> <layout class="QGridLayout" name="gl_Selection" columnstretch="0,1,1,1">
<item row="1" column="0"> <item row="0" column="1" colspan="3" alignment="Qt::AlignLeft">
<widget class="QLabel" name="lbl_Mode"> <widget class="BlackGui::Components::CSimulatorSelector" name="comp_SimulatorSelector">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Simulator">
<property name="text"> <property name="text">
<string>Mode:</string> <string>Simulator:</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -54,24 +64,24 @@
<string>full</string> <string>full</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">bg_Mode</string>
</attribute>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_Mode">
<property name="text">
<string>Mode:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="2" column="0">
<widget class="QLabel" name="lbl_Simulator"> <widget class="QLabel" name="lbl_SelectSourceSet">
<property name="text"> <property name="text">
<string>Simulator:</string> <string>Source set:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QRadioButton" name="rb_Incremental">
<property name="toolTip">
<string>add to existing set</string>
</property>
<property name="text">
<string>incremental</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -86,6 +96,22 @@
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>false</bool>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">bg_SourceSet</string>
</attribute>
</widget>
</item>
<item row="1" column="2">
<widget class="QRadioButton" name="rb_Incremental">
<property name="toolTip">
<string>add to existing set</string>
</property>
<property name="text">
<string>incremental</string>
</property>
<attribute name="buttonGroup">
<string notr="true">bg_Mode</string>
</attribute>
</widget> </widget>
</item> </item>
<item row="2" column="3"> <item row="2" column="3">
@@ -99,6 +125,9 @@
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>false</bool>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">bg_SourceSet</string>
</attribute>
</widget> </widget>
</item> </item>
<item row="1" column="3"> <item row="1" column="3">
@@ -111,23 +140,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_SelectSourceSet">
<property name="text">
<string>Source set:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="BlackGui::Components::CSimulatorSelector" name="comp_SimulatorSelector">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QRadioButton" name="rb_DbDataOnly"> <widget class="QRadioButton" name="rb_DbDataOnly">
<property name="toolTip"> <property name="toolTip">
@@ -136,6 +148,22 @@
<property name="text"> <property name="text">
<string>DB data only</string> <string>DB data only</string>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">bg_SourceSet</string>
</attribute>
</widget>
</item>
<item row="3" column="2">
<widget class="QRadioButton" name="rb_DistributorsFromBelow">
<property name="text">
<string>all from below</string>
</property>
<attribute name="buttonGroup">
<string notr="true">bg_Distributors</string>
</attribute>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
@@ -150,20 +178,9 @@
<property name="text"> <property name="text">
<string>selected</string> <string>selected</string>
</property> </property>
</widget> <attribute name="buttonGroup">
</item> <string notr="true">bg_Distributors</string>
<item row="4" column="1"> </attribute>
<widget class="QRadioButton" name="rb_DisplayPreferencesDistributors">
<property name="text">
<string>from preferences</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QRadioButton" name="rb_DistributorsFromBelow">
<property name="text">
<string>all from below</string>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="3"> <item row="3" column="3">
@@ -174,26 +191,9 @@
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> <attribute name="buttonGroup">
</item> <string notr="true">bg_Distributors</string>
<item row="4" column="2"> </attribute>
<widget class="QRadioButton" name="rb_DisplayAllDistributors">
<property name="text">
<string>all distributors</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QCheckBox" name="cb_SortByPreferences">
<property name="toolTip">
<string>If checked the distributors from the settings page will be used</string>
</property>
<property name="text">
<string>sort by dist. preferences</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -205,6 +205,57 @@
<string>Distributors</string> <string>Distributors</string>
</property> </property>
<layout class="QVBoxLayout" name="vl_Distributors"> <layout class="QVBoxLayout" name="vl_Distributors">
<item>
<widget class="QWidget" name="wi_DistributionButtons" native="true">
<layout class="QGridLayout" name="gl_DistributorButtons">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QRadioButton" name="rb_DisplayPreferencesDistributors">
<property name="text">
<string>from preferences</string>
</property>
<attribute name="buttonGroup">
<string notr="true">bg_Displayed</string>
</attribute>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="rb_DisplayAllDistributors">
<property name="text">
<string>all distributors</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">bg_Displayed</string>
</attribute>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="cb_SortByPreferences">
<property name="toolTip">
<string>If checked the distributors from the settings page will be used</string>
</property>
<property name="text">
<string>sort by dist. preferences</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="BlackGui::Views::CDistributorView" name="tvp_Distributors"> <widget class="BlackGui::Views::CDistributorView" name="tvp_Distributors">
<property name="selectionBehavior"> <property name="selectionBehavior">
@@ -236,12 +287,27 @@
<header>blackgui/views/distributorview.h</header> <header>blackgui/views/distributorview.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>rb_Full</tabstop>
<tabstop>rb_Incremental</tabstop>
<tabstop>cb_ConsolidateModelSet</tabstop>
<tabstop>rb_DbDataOnly</tabstop>
<tabstop>rb_DbIcaoCodesOnly</tabstop>
<tabstop>rb_WithIcaoData</tabstop>
<tabstop>rb_DistributorsSelected</tabstop>
<tabstop>rb_DistributorsFromBelow</tabstop>
<tabstop>rb_DistributorsAll</tabstop>
<tabstop>rb_DisplayPreferencesDistributors</tabstop>
<tabstop>rb_DisplayAllDistributors</tabstop>
<tabstop>cb_SortByPreferences</tabstop>
<tabstop>tvp_Distributors</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
<buttongroups> <buttongroups>
<buttongroup name="bg_SourceSet"/> <buttongroup name="bg_SourceSet"/>
<buttongroup name="bg_Distributors"/> <buttongroup name="bg_Distributors"/>
<buttongroup name="bg_Mode"/> <buttongroup name="bg_Mode"/>
<buttongroup name="bg_DisplayedDistributors"/> <buttongroup name="bg_Displayed"/>
</buttongroups> </buttongroups>
</ui> </ui>

View File

@@ -97,15 +97,20 @@ namespace BlackGui
this->sort(column, order); this->sort(column, order);
} }
void CListModelBaseNonTemplate::setSortColumnByPropertyIndex(const CPropertyIndex &propertyIndex) bool CListModelBaseNonTemplate::setSortColumnByPropertyIndex(const CPropertyIndex &propertyIndex)
{ {
m_sortColumn = m_columns.propertyIndexToColumn(propertyIndex); const int column = m_columns.propertyIndexToColumn(propertyIndex);
if (m_sortColumn == column) { return false; } // not changed
m_sortColumn = column;
return true; // changed
} }
void CListModelBaseNonTemplate::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order) bool CListModelBaseNonTemplate::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
{ {
this->setSortColumnByPropertyIndex(propertyIndex); const bool changedColumn = this->setSortColumnByPropertyIndex(propertyIndex);
const bool changedOrder = (m_sortOrder == order);
m_sortOrder = order; m_sortOrder = order;
return changedColumn || changedOrder;
} }
bool CListModelBaseNonTemplate::hasValidSortColumn() const bool CListModelBaseNonTemplate::hasValidSortColumn() const

View File

@@ -85,10 +85,10 @@ namespace BlackGui
//! Set column for sorting //! Set column for sorting
//! \param propertyIndex index of column to be sorted //! \param propertyIndex index of column to be sorted
virtual void setSortColumnByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex); virtual bool setSortColumnByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex);
//! Sorting //! Sorting
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder); virtual bool setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder);
//! Get sort column property index //! Get sort column property index
virtual int getSortColumn() const { return m_sortColumn; } virtual int getSortColumn() const { return m_sortColumn; }

View File

@@ -49,7 +49,7 @@ namespace BlackGui
QVariant CListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::data(const QModelIndex &index, int role) const 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 (role != Qt::BackgroundRole) { return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); }
if (isHighlightedIndex(index)) { return QBrush(m_highlightColor); } if (isHighlightedIndex(index) ) { return QBrush(m_highlightColor); }
return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role); return CListModelBase<ObjectType, ContainerType, UseCompare>::data(index, role);
} }
@@ -91,10 +91,10 @@ namespace BlackGui
} }
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare> template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
void COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::setSortColumnToOrder() bool COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::setSortColumnToOrder()
{ {
// force sorted by order, otherwise display looks confusing // force sorted by order, otherwise display looks confusing
this->setSorting(IOrderable::IndexOrder); return this->setSorting(IOrderable::IndexOrder);
} }
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare> template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>

View File

@@ -91,7 +91,7 @@ namespace BlackGui
//! @} //! @}
//! Sort order to order property BlackMisc::IOrderable::IndexOrder //! Sort order to order property BlackMisc::IOrderable::IndexOrder
void setSortColumnToOrder(); bool setSortColumnToOrder();
protected: protected:
//! Constructor //! Constructor

View File

@@ -468,10 +468,10 @@ namespace BlackGui
} }
template <class ModelClass, class ContainerType, class ObjectType> template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order) bool CViewBase<ModelClass, ContainerType, ObjectType>::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
{ {
Q_ASSERT(m_model); Q_ASSERT(m_model);
m_model->setSorting(propertyIndex, order); return m_model->setSorting(propertyIndex, order);
} }
template <class ModelClass, class ContainerType, class ObjectType> template <class ModelClass, class ContainerType, class ObjectType>

View File

@@ -168,7 +168,7 @@ namespace BlackGui
virtual bool isOrderable() const = 0; virtual bool isOrderable() const = 0;
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::setSorting //! \copydoc BlackGui::Models::CListModelBaseNonTemplate::setSorting
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0; virtual bool setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0;
//! Sort by index //! Sort by index
virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0; virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0;
@@ -700,7 +700,7 @@ namespace BlackGui
virtual bool isDropAllowed() const override; virtual bool isDropAllowed() const override;
virtual void dropEvent(QDropEvent *event) override; virtual void dropEvent(QDropEvent *event) override;
virtual bool acceptDrop(const QMimeData *mimeData) const override; virtual bool acceptDrop(const QMimeData *mimeData) const override;
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override; virtual bool setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override;
virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override; virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override;
//! @} //! @}

View File

@@ -26,7 +26,7 @@ namespace BlackMisc
QString IOrderable::getOrderAsString() const QString IOrderable::getOrderAsString() const
{ {
if (this->hasValidOrder()) { return QString::number(this->getOrder()); } if (this->hasValidOrder()) { return QString::number(this->getOrder()); }
return "-"; return QStringLiteral("-");
} }
bool IOrderable::hasValidOrder() const bool IOrderable::hasValidOrder() const
@@ -37,7 +37,7 @@ namespace BlackMisc
bool IOrderable::canHandleIndex(const CPropertyIndex &index) bool IOrderable::canHandleIndex(const CPropertyIndex &index)
{ {
if (index.isEmpty()) { return false; } if (index.isEmpty()) { return false; }
int i = index.frontCasted<int>(); const int i = index.frontCasted<int>();
return (i >= static_cast<int>(IndexOrder)) && (i <= static_cast<int>(IndexOrderString)); return (i >= static_cast<int>(IndexOrder)) && (i <= static_cast<int>(IndexOrderString));
} }
@@ -45,15 +45,12 @@ namespace BlackMisc
{ {
if (!index.isEmpty()) if (!index.isEmpty())
{ {
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexOrder: case IndexOrder: return CVariant::fromValue(this->m_order);
return CVariant::fromValue(this->m_order); case IndexOrderString: return CVariant::fromValue(this->getOrderAsString());
case IndexOrderString: default: break;
return CVariant::fromValue(this->getOrderAsString());
default:
break;
} }
} }
const QString m = QString("Cannot handle index %1").arg(index.toQString()); const QString m = QString("Cannot handle index %1").arg(index.toQString());
@@ -65,12 +62,10 @@ namespace BlackMisc
{ {
if (!index.isEmpty()) if (!index.isEmpty())
{ {
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexOrder: case IndexOrder: this->setOrder(variant.toInt()); return;
this->setOrder(variant.toInt());
return;
case IndexOrderString: case IndexOrderString:
default: default:
break; break;