2014-07-08 03:11:14 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "FractoriumPch.h"
|
|
|
|
#include "DoubleSpinBox.h"
|
|
|
|
|
|
|
|
/// <summary>
|
2014-10-14 11:53:15 -04:00
|
|
|
/// VariationTreeWidgetItem class.
|
2014-07-08 03:11:14 -04:00
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A derivation of QTreeWidgetItem which helps us with sorting.
|
|
|
|
/// This is used when the user chooses to sort the variations tree
|
|
|
|
/// by index or by weight. It supports weights less than, equal to, or
|
|
|
|
/// greater than zero.
|
|
|
|
/// </summary>
|
|
|
|
class VariationTreeWidgetItem : public QTreeWidgetItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor that takes a pointer to a QTreeWidget as the parent
|
|
|
|
/// and passes it to the base.
|
|
|
|
/// </summary>
|
2014-07-28 01:25:38 -04:00
|
|
|
/// <param name="id">The ID of the variation this widget will represent</param>
|
2014-12-11 00:50:15 -05:00
|
|
|
/// <param name="p">The parent widget</param>
|
2016-04-03 21:55:12 -04:00
|
|
|
VariationTreeWidgetItem(eVariationId id, QTreeWidget* p = nullptr)
|
2014-12-11 00:50:15 -05:00
|
|
|
: QTreeWidgetItem(p)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2014-07-28 01:25:38 -04:00
|
|
|
m_Id = id;
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor that takes a pointer to a QTreeWidgetItem as the parent
|
|
|
|
/// and passes it to the base.
|
|
|
|
/// This is used for making sub items for parametric variation parameters.
|
|
|
|
/// </summary>
|
2014-07-28 01:25:38 -04:00
|
|
|
/// <param name="id">The ID of the variation this widget will represent</param>
|
2014-12-11 00:50:15 -05:00
|
|
|
/// <param name="p">The parent widget</param>
|
|
|
|
VariationTreeWidgetItem(eVariationId id, QTreeWidgetItem* p = 0)
|
|
|
|
: QTreeWidgetItem(p)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2014-07-28 01:25:38 -04:00
|
|
|
m_Id = id;
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~VariationTreeWidgetItem() { }
|
2014-07-28 01:25:38 -04:00
|
|
|
eVariationId Id() { return m_Id; }
|
2014-07-08 03:11:14 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// <summary>
|
|
|
|
/// Less than operator used for sorting.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="other">The QTreeWidgetItem to compare against for sorting</param>
|
|
|
|
/// <returns>True if this is less than other, else false.</returns>
|
|
|
|
bool operator < (const QTreeWidgetItem& other) const
|
|
|
|
{
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto column = treeWidget()->sortColumn();
|
2015-06-28 17:04:30 -04:00
|
|
|
auto itemWidget1 = treeWidget()->itemWidget(const_cast<VariationTreeWidgetItem*>(this), 1);//Get the widget for the second column.
|
2016-01-12 23:42:12 -05:00
|
|
|
|
2016-02-12 00:38:21 -05:00
|
|
|
if (auto spinBox1 = dynamic_cast<VariationTreeDoubleSpinBox*>(itemWidget1))//Cast the widget to the VariationTreeDoubleSpinBox type.
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-06-28 17:04:30 -04:00
|
|
|
auto itemWidget2 = treeWidget()->itemWidget(const_cast<QTreeWidgetItem*>(&other), 1);//Get the widget for the second column of the widget item passed in.
|
2016-01-12 23:42:12 -05:00
|
|
|
|
2016-02-12 00:38:21 -05:00
|
|
|
if (auto spinBox2 = dynamic_cast<VariationTreeDoubleSpinBox*>(itemWidget2))//Cast the widget to the VariationTreeDoubleSpinBox type.
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
|
|
|
if (spinBox1->IsParam() || spinBox2->IsParam())//Do not sort params, their order will always remain the same.
|
|
|
|
return false;
|
|
|
|
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto weight1 = spinBox1->value();
|
|
|
|
const auto weight2 = spinBox2->value();
|
|
|
|
const auto index1 = spinBox1->GetVariationId();
|
|
|
|
const auto index2 = spinBox2->GetVariationId();
|
2014-07-08 03:11:14 -04:00
|
|
|
|
|
|
|
if (column == 0)//First column clicked, sort by variation index.
|
|
|
|
{
|
|
|
|
return index1 < index2;
|
|
|
|
}
|
|
|
|
else if (column == 1)//Second column clicked, sort by weight.
|
|
|
|
{
|
|
|
|
if (IsNearZero(weight1) && IsNearZero(weight2))
|
|
|
|
return index1 > index2;
|
|
|
|
else
|
2016-01-12 23:42:12 -05:00
|
|
|
return std::abs(weight1) < fabs(weight2);
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-12 23:42:12 -05:00
|
|
|
|
2014-07-08 03:11:14 -04:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-28 01:25:38 -04:00
|
|
|
|
|
|
|
eVariationId m_Id;
|
2014-12-11 00:50:15 -05:00
|
|
|
};
|