--User changes

-Eliminate delay when switching between single and double precision.

--Code changes
 -Variation tree and associated widgets no longer actually contain variation objects, only IDs.
This commit is contained in:
mfeemster 2015-06-28 14:04:30 -07:00
parent 3cd970a347
commit e8af1050b3
5 changed files with 50 additions and 51 deletions

View File

@ -58,13 +58,12 @@ private:
/// VariationTreeWidgetItem and VariationTreeDoubleSpinBox need each other, but each can't include the other. /// VariationTreeWidgetItem and VariationTreeDoubleSpinBox need each other, but each can't include the other.
/// So VariationTreeWidgetItem includes this file, and use a forward declaration here. /// So VariationTreeWidgetItem includes this file, and use a forward declaration here.
/// </summary> /// </summary>
template <typename T> class VariationTreeWidgetItem; class VariationTreeWidgetItem;
/// <summary> /// <summary>
/// Derivation for the double spin boxes that are in the /// Derivation for the double spin boxes that are in the
/// variations tree. /// variations tree.
/// </summary> /// </summary>
template <typename T>
class VariationTreeDoubleSpinBox : public DoubleSpinBox class VariationTreeDoubleSpinBox : public DoubleSpinBox
{ {
public: public:
@ -73,27 +72,27 @@ public:
/// </summary> /// </summary>
/// <param name="p">The parent widget</param> /// <param name="p">The parent widget</param>
/// <param name="widgetItem">The widget item this spinner is contained in</param> /// <param name="widgetItem">The widget item this spinner is contained in</param>
/// <param name="var">The variation this spinner is for</param> /// <param name="id">The variation this spinner is for</param>
/// <param name="param">The name of the parameter this is for</param> /// <param name="param">The name of the parameter this is for</param>
/// <param name="h">The height of the spin box. Default: 16.</param> /// <param name="h">The height of the spin box. Default: 16.</param>
/// <param name="step">The step used to increment/decrement the spin box when using the mouse wheel. Default: 0.05.</param> /// <param name="step">The step used to increment/decrement the spin box when using the mouse wheel. Default: 0.05.</param>
explicit VariationTreeDoubleSpinBox(QWidget* p, VariationTreeWidgetItem<T>* widgetItem, Variation<T>* var, string param, int h = 16, double step = 0.05) explicit VariationTreeDoubleSpinBox(QWidget* p, VariationTreeWidgetItem* widgetItem, eVariationId id, string param, int h = 16, double step = 0.05)
: DoubleSpinBox(p, h, step) : DoubleSpinBox(p, h, step)
{ {
m_WidgetItem = widgetItem; m_WidgetItem = widgetItem;
m_Param = param; m_Param = param;
m_Variation = var; m_Id = id;
setDecimals(3); setDecimals(3);
} }
virtual ~VariationTreeDoubleSpinBox() { } virtual ~VariationTreeDoubleSpinBox() { }
bool IsParam() { return !m_Param.empty(); } bool IsParam() { return !m_Param.empty(); }
string ParamName() { return m_Param; } string ParamName() { return m_Param; }
Variation<T>* GetVariation() { return m_Variation; } eVariationId GetVariationId() { return m_Id; }
VariationTreeWidgetItem<T>* WidgetItem() { return m_WidgetItem; } VariationTreeWidgetItem* WidgetItem() { return m_WidgetItem; }
private: private:
string m_Param; string m_Param;
Variation<T>* m_Variation; eVariationId m_Id;
VariationTreeWidgetItem<T>* m_WidgetItem; VariationTreeWidgetItem* m_WidgetItem;
}; };

View File

@ -114,6 +114,8 @@ Fractorium::Fractorium(QWidget* p)
#endif #endif
m_Controller = unique_ptr<FractoriumEmberControllerBase>(new FractoriumEmberController<float>(this)); m_Controller = unique_ptr<FractoriumEmberControllerBase>(new FractoriumEmberController<float>(this));
m_Controller->SetupVariationTree();
if (m_Wrapper.CheckOpenCL() && m_Settings->OpenCL() && m_QualitySpin->value() < 30) if (m_Wrapper.CheckOpenCL() && m_Settings->OpenCL() && m_QualitySpin->value() < 30)
m_QualitySpin->setValue(30); m_QualitySpin->setValue(30);

View File

@ -75,7 +75,6 @@ FractoriumEmberController<T>::FractoriumEmberController(Fractorium* fractorium)
m_SheepTools = unique_ptr<SheepTools<T, T>>(new SheepTools<T, T>("flam3-palettes.xml", new EmberNs::Renderer<T, T>())); m_SheepTools = unique_ptr<SheepTools<T, T>>(new SheepTools<T, T>("flam3-palettes.xml", new EmberNs::Renderer<T, T>()));
m_GLController = unique_ptr<GLEmberController<T>>(new GLEmberController<T>(fractorium, fractorium->ui.GLDisplay, this)); m_GLController = unique_ptr<GLEmberController<T>>(new GLEmberController<T>(fractorium, fractorium->ui.GLDisplay, this));
m_PreviewRenderer = unique_ptr<EmberNs::Renderer<T, T>>(new EmberNs::Renderer<T, T>()); m_PreviewRenderer = unique_ptr<EmberNs::Renderer<T, T>>(new EmberNs::Renderer<T, T>());
SetupVariationTree();
//Initial combo change event to fill the palette table will be called automatically later. //Initial combo change event to fill the palette table will be called automatically later.
if (!InitPaletteList("./")) if (!InitPaletteList("./"))

View File

@ -6,7 +6,7 @@
/// </summary> /// </summary>
void Fractorium::InitXformsVariationsUI() void Fractorium::InitXformsVariationsUI()
{ {
QTreeWidget* tree = ui.VariationsTree; auto tree = ui.VariationsTree;
tree->clear(); tree->clear();
tree->header()->setSectionsClickable(true); tree->header()->setSectionsClickable(true);
@ -32,19 +32,19 @@ void FractoriumEmberController<T>::SetupVariationTree()
T fMax = TMAX; T fMax = TMAX;
QSize hint0(75, 16); QSize hint0(75, 16);
QSize hint1(30, 16); QSize hint1(30, 16);
QTreeWidget* tree = m_Fractorium->ui.VariationsTree; auto tree = m_Fractorium->ui.VariationsTree;
tree->clear(); tree->clear();
tree->blockSignals(true); tree->blockSignals(true);
for (size_t i = 0; i < m_VariationList.Size(); i++) for (size_t i = 0; i < m_VariationList.Size(); i++)
{ {
Variation<T>* var = m_VariationList.GetVariation(i); auto var = m_VariationList.GetVariation(i);
ParametricVariation<T>* parVar = dynamic_cast<ParametricVariation<T>*>(var); auto parVar = dynamic_cast<ParametricVariation<T>*>(var);
//First add the variation, with a spinner for its weight. //First add the variation, with a spinner for its weight.
VariationTreeWidgetItem<T>* item = new VariationTreeWidgetItem<T>(var->VariationId(), tree); auto item = new VariationTreeWidgetItem(var->VariationId(), tree);
VariationTreeDoubleSpinBox<T>* spinBox = new VariationTreeDoubleSpinBox<T>(tree, item, parVar ? parVar : var, ""); auto spinBox = new VariationTreeDoubleSpinBox(tree, item, var->VariationId(), "");
item->setText(0, QString::fromStdString(var->Name())); item->setText(0, QString::fromStdString(var->Name()));
item->setSizeHint(0, hint0); item->setSizeHint(0, hint0);
@ -67,8 +67,8 @@ void FractoriumEmberController<T>::SetupVariationTree()
{ {
if (!params[j].IsPrecalc()) if (!params[j].IsPrecalc())
{ {
VariationTreeWidgetItem<T>* paramWidget = new VariationTreeWidgetItem<T>(var->VariationId(), item); auto paramWidget = new VariationTreeWidgetItem(var->VariationId(), item);
VariationTreeDoubleSpinBox<T>* varSpinBox = new VariationTreeDoubleSpinBox<T>(tree, paramWidget, parVar, params[j].Name()); auto varSpinBox = new VariationTreeDoubleSpinBox(tree, paramWidget, parVar->VariationId(), params[j].Name());
paramWidget->setText(0, params[j].Name().c_str()); paramWidget->setText(0, params[j].Name().c_str());
paramWidget->setSizeHint(0, hint0); paramWidget->setSizeHint(0, hint0);
@ -108,13 +108,13 @@ void FractoriumEmberController<T>::ClearVariationsTree()
for (uint i = 0; i < tree->topLevelItemCount(); i++) for (uint i = 0; i < tree->topLevelItemCount(); i++)
{ {
QTreeWidgetItem* item = tree->topLevelItem(i); QTreeWidgetItem* item = tree->topLevelItem(i);
VariationTreeDoubleSpinBox<T>* spinBox = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(tree->itemWidget(item, 1)); auto* spinBox = dynamic_cast<VariationTreeDoubleSpinBox*>(tree->itemWidget(item, 1));
spinBox->SetValueStealth(0); spinBox->SetValueStealth(0);
for (uint j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params. for (uint j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params.
{ {
if ((spinBox = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(tree->itemWidget(item->child(j), 1))))//Cast the child widget to the VariationTreeDoubleSpinBox type. if ((spinBox = dynamic_cast<VariationTreeDoubleSpinBox*>(tree->itemWidget(item->child(j), 1))))//Cast the child widget to the VariationTreeDoubleSpinBox type.
spinBox->SetValueStealth(0); spinBox->SetValueStealth(0);
} }
} }
@ -130,17 +130,17 @@ void FractoriumEmberController<T>::ClearVariationsTree()
template <typename T> template <typename T>
void FractoriumEmberController<T>::VariationSpinBoxValueChanged(double d)//Would be awesome to make this work for all.//TODO void FractoriumEmberController<T>::VariationSpinBoxValueChanged(double d)//Would be awesome to make this work for all.//TODO
{ {
QObject* objSender = m_Fractorium->sender(); auto objSender = m_Fractorium->sender();
QTreeWidget* tree = m_Fractorium->ui.VariationsTree; auto tree = m_Fractorium->ui.VariationsTree;
VariationTreeDoubleSpinBox<T>* sender = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(objSender); auto sender = dynamic_cast<VariationTreeDoubleSpinBox*>(objSender);
Xform<T>* xform = m_Ember.GetTotalXform(m_Fractorium->ui.CurrentXformCombo->currentIndex());//Will retrieve normal xform or final if needed. auto xform = m_Ember.GetTotalXform(m_Fractorium->ui.CurrentXformCombo->currentIndex());//Will retrieve normal xform or final if needed.
if (sender && xform) if (sender && xform)
{ {
Variation<T>* var = sender->GetVariation();//The variation attached to the sender, for reference only. auto var = m_VariationList.GetVariation(sender->GetVariationId());//The variation attached to the sender, for reference only.
ParametricVariation<T>* parVar = dynamic_cast<ParametricVariation<T>*>(var);//The parametric cast of that variation. auto parVar = dynamic_cast<ParametricVariation<T>*>(var);//The parametric cast of that variation.
Variation<T>* xformVar = xform->GetVariationById(var->VariationId());//The corresponding variation in the currently selected xform. auto xformVar = xform->GetVariationById(var->VariationId());//The corresponding variation in the currently selected xform.
VariationTreeWidgetItem<T>* widgetItem = sender->WidgetItem(); auto widgetItem = sender->WidgetItem();
bool isParam = parVar && sender->IsParam(); bool isParam = parVar && sender->IsParam();
if (isParam) if (isParam)
@ -175,7 +175,7 @@ void FractoriumEmberController<T>::VariationSpinBoxValueChanged(double d)//Would
{ {
//If the item wasn't a param and the xform did not contain this variation, //If the item wasn't a param and the xform did not contain this variation,
//it means they went from zero to a non-zero weight, so add a new copy of this xform. //it means they went from zero to a non-zero weight, so add a new copy of this xform.
Variation<T>* newVar = var->Copy();//Create a new one with default values. auto newVar = var->Copy();//Create a new one with default values.
newVar->m_Weight = d; newVar->m_Weight = d;
xform->AddVariation(newVar); xform->AddVariation(newVar);
@ -185,14 +185,14 @@ void FractoriumEmberController<T>::VariationSpinBoxValueChanged(double d)//Would
//for the child parameters and assign them to the newly added variation. //for the child parameters and assign them to the newly added variation.
if (parVar) if (parVar)
{ {
ParametricVariation<T>* newParVar = dynamic_cast<ParametricVariation<T>*>(newVar); auto newParVar = dynamic_cast<ParametricVariation<T>*>(newVar);
for (int i = 0; i < widgetItem->childCount(); i++)//Iterate through all of the children, which will be the params. for (int i = 0; i < widgetItem->childCount(); i++)//Iterate through all of the children, which will be the params.
{ {
QTreeWidgetItem* childItem = widgetItem->child(i);//Get the child. auto childItem = widgetItem->child(i);//Get the child.
QWidget* itemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child. auto itemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child.
if (VariationTreeDoubleSpinBox<T>* spinBox = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(itemWidget))//Cast the widget to the VariationTreeDoubleSpinBox type. if (auto spinBox = dynamic_cast<VariationTreeDoubleSpinBox*>(itemWidget))//Cast the widget to the VariationTreeDoubleSpinBox type.
{ {
string s = childItem->text(0).toStdString();//Use the name of the child, and the value of the spinner widget to assign the param. string s = childItem->text(0).toStdString();//Use the name of the child, and the value of the spinner widget to assign the param.
@ -218,18 +218,18 @@ void Fractorium::OnVariationSpinBoxValueChanged(double d) { m_Controller->Variat
template <typename T> template <typename T>
void FractoriumEmberController<T>::FillVariationTreeWithXform(Xform<T>* xform) void FractoriumEmberController<T>::FillVariationTreeWithXform(Xform<T>* xform)
{ {
QTreeWidget* tree = m_Fractorium->ui.VariationsTree; auto tree = m_Fractorium->ui.VariationsTree;
tree->blockSignals(true); tree->blockSignals(true);
for (uint i = 0; i < tree->topLevelItemCount(); i++) for (uint i = 0; i < tree->topLevelItemCount(); i++)
{ {
VariationTreeWidgetItem<T>* item = dynamic_cast<VariationTreeWidgetItem<T>*>(tree->topLevelItem(i)); auto item = dynamic_cast<VariationTreeWidgetItem*>(tree->topLevelItem(i));
Variation<T>* var = xform->GetVariationById(item->Id());//See if this variation in the tree was contained in the xform. auto var = xform->GetVariationById(item->Id());//See if this variation in the tree was contained in the xform.
ParametricVariation<T>* parVar = dynamic_cast<ParametricVariation<T>*>(var);//Attempt cast to parametric variation for later. auto parVar = dynamic_cast<ParametricVariation<T>*>(var);//Attempt cast to parametric variation for later.
ParametricVariation<T>* origParVar = dynamic_cast<ParametricVariation<T>*>(m_VariationList.GetVariation(item->Id())); auto origParVar = dynamic_cast<ParametricVariation<T>*>(m_VariationList.GetVariation(item->Id()));
if (VariationTreeDoubleSpinBox<T>* spinBox = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(tree->itemWidget(item, 1)))//Get the widget for the item, and cast the widget to the VariationTreeDoubleSpinBox type. if (auto spinBox = dynamic_cast<VariationTreeDoubleSpinBox*>(tree->itemWidget(item, 1)))//Get the widget for the item, and cast the widget to the VariationTreeDoubleSpinBox type.
{ {
spinBox->SetValueStealth(var ? var->m_Weight : 0);//If the variation was present, set the spin box to its weight, else zero. spinBox->SetValueStealth(var ? var->m_Weight : 0);//If the variation was present, set the spin box to its weight, else zero.
item->setBackgroundColor(0, var ? QColor(200, 200, 200) : QColor(255, 255, 255));//Ensure background is always white if the value goes to zero, else gray if var present. item->setBackgroundColor(0, var ? QColor(200, 200, 200) : QColor(255, 255, 255));//Ensure background is always white if the value goes to zero, else gray if var present.
@ -237,10 +237,10 @@ void FractoriumEmberController<T>::FillVariationTreeWithXform(Xform<T>* xform)
for (uint j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params if it was a parametric variation. for (uint j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params if it was a parametric variation.
{ {
T* param = nullptr; T* param = nullptr;
QTreeWidgetItem* childItem = item->child(j);//Get the child. auto childItem = item->child(j);//Get the child.
QWidget* childItemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child. auto childItemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child.
if (VariationTreeDoubleSpinBox<T>* childSpinBox = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(childItemWidget))//Cast the widget to the VariationTreeDoubleSpinBox type. if (auto childSpinBox = dynamic_cast<VariationTreeDoubleSpinBox*>(childItemWidget))//Cast the widget to the VariationTreeDoubleSpinBox type.
{ {
string s = childItem->text(0).toStdString();//Get the name of the child. string s = childItem->text(0).toStdString();//Get the name of the child.

View File

@ -13,7 +13,6 @@
/// by index or by weight. It supports weights less than, equal to, or /// by index or by weight. It supports weights less than, equal to, or
/// greater than zero. /// greater than zero.
/// </summary> /// </summary>
template <typename T>
class VariationTreeWidgetItem : public QTreeWidgetItem class VariationTreeWidgetItem : public QTreeWidgetItem
{ {
public: public:
@ -56,24 +55,24 @@ private:
int column = treeWidget()->sortColumn(); int column = treeWidget()->sortColumn();
eVariationId index1, index2; eVariationId index1, index2;
double weight1 = 0, weight2 = 0; double weight1 = 0, weight2 = 0;
VariationTreeWidgetItem<T>* varItemWidget; VariationTreeWidgetItem* varItemWidget;
VariationTreeDoubleSpinBox<T>* spinBox1, *spinBox2; VariationTreeDoubleSpinBox* spinBox1, *spinBox2;
QWidget* itemWidget1 = treeWidget()->itemWidget(const_cast<VariationTreeWidgetItem<T>*>(this), 1);//Get the widget for the second column. auto itemWidget1 = treeWidget()->itemWidget(const_cast<VariationTreeWidgetItem*>(this), 1);//Get the widget for the second column.
if ((spinBox1 = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(itemWidget1)))//Cast the widget to the VariationTreeDoubleSpinBox type. if ((spinBox1 = dynamic_cast<VariationTreeDoubleSpinBox*>(itemWidget1)))//Cast the widget to the VariationTreeDoubleSpinBox type.
{ {
QWidget* itemWidget2 = treeWidget()->itemWidget(const_cast<QTreeWidgetItem*>(&other), 1);//Get the widget for the second column of the widget item passed in. auto itemWidget2 = treeWidget()->itemWidget(const_cast<QTreeWidgetItem*>(&other), 1);//Get the widget for the second column of the widget item passed in.
if ((spinBox2 = dynamic_cast<VariationTreeDoubleSpinBox<T>*>(itemWidget2)))//Cast the widget to the VariationTreeDoubleSpinBox type. if ((spinBox2 = dynamic_cast<VariationTreeDoubleSpinBox*>(itemWidget2)))//Cast the widget to the VariationTreeDoubleSpinBox type.
{ {
if (spinBox1->IsParam() || spinBox2->IsParam())//Do not sort params, their order will always remain the same. if (spinBox1->IsParam() || spinBox2->IsParam())//Do not sort params, their order will always remain the same.
return false; return false;
weight1 = spinBox1->value(); weight1 = spinBox1->value();
weight2 = spinBox2->value(); weight2 = spinBox2->value();
index1 = spinBox1->GetVariation()->VariationId(); index1 = spinBox1->GetVariationId();
index2 = spinBox2->GetVariation()->VariationId(); index2 = spinBox2->GetVariationId();
if (column == 0)//First column clicked, sort by variation index. if (column == 0)//First column clicked, sort by variation index.
{ {