#4031 Ensemble : Fix operator<

This commit is contained in:
Magne Sjaastad 2019-02-04 11:22:38 +01:00
parent 89d55d8354
commit d275b2bf60

View File

@ -142,28 +142,45 @@ QString RiaSummaryCurveDefinition::curveDefinitionText(const QString& caseName,
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RiaSummaryCurveDefinition::operator<(const RiaSummaryCurveDefinition& other) const bool RiaSummaryCurveDefinition::operator<(const RiaSummaryCurveDefinition& other) const
{ {
if (m_summaryCase != other.summaryCase())
{ {
// Try comparing the dereferenced objects first. They have a predictable sorting operator. QString ensembleName;
if (m_summaryCase && other.summaryCase()) QString otherEnsembleName;
if (m_ensemble)
{ {
return *m_summaryCase < *other.summaryCase(); ensembleName = m_ensemble->name();
}
if (other.ensemble())
{
otherEnsembleName = other.ensemble()->name();
}
if (ensembleName != otherEnsembleName)
{
return ensembleName < otherEnsembleName;
} }
// Sorting by pointer address, which may appear random to the user.
return m_summaryCase < other.summaryCase();
} }
if (m_ensemble != other.ensemble())
{ {
// Try comparing the dereferenced objects first. They have a predictable sorting operator. QString summaryCaseName;
if (m_ensemble && other.ensemble()) QString otherSummaryCaseName;
if (m_summaryCase)
{ {
return *m_ensemble < *other.ensemble(); summaryCaseName = m_summaryCase->caseName();
}
if (other.summaryCase())
{
otherSummaryCaseName = other.summaryCase()->caseName();
}
if (summaryCaseName != otherSummaryCaseName)
{
return summaryCaseName < otherSummaryCaseName;
} }
// Sorting by pointer address, which may appear random to the user.
return (m_ensemble < other.ensemble());
} }
return (m_summaryAddress < other.summaryAddress()); return (m_summaryAddress < other.summaryAddress());
} }