From e8af1050b363f100bcc6e40063fe21b866ef0d4c Mon Sep 17 00:00:00 2001 From: mfeemster Date: Sun, 28 Jun 2015 14:04:30 -0700 Subject: [PATCH] --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. --- Source/Fractorium/DoubleSpinBox.h | 17 +++-- Source/Fractorium/Fractorium.cpp | 2 + .../Fractorium/FractoriumEmberController.cpp | 1 - .../Fractorium/FractoriumXformsVariations.cpp | 64 +++++++++---------- Source/Fractorium/VariationTreeWidgetItem.h | 17 +++-- 5 files changed, 50 insertions(+), 51 deletions(-) diff --git a/Source/Fractorium/DoubleSpinBox.h b/Source/Fractorium/DoubleSpinBox.h index f0cb880..305bf00 100644 --- a/Source/Fractorium/DoubleSpinBox.h +++ b/Source/Fractorium/DoubleSpinBox.h @@ -58,13 +58,12 @@ private: /// VariationTreeWidgetItem and VariationTreeDoubleSpinBox need each other, but each can't include the other. /// So VariationTreeWidgetItem includes this file, and use a forward declaration here. /// -template class VariationTreeWidgetItem; +class VariationTreeWidgetItem; /// /// Derivation for the double spin boxes that are in the /// variations tree. /// -template class VariationTreeDoubleSpinBox : public DoubleSpinBox { public: @@ -73,27 +72,27 @@ public: /// /// The parent widget /// The widget item this spinner is contained in - /// The variation this spinner is for + /// The variation this spinner is for /// The name of the parameter this is for /// The height of the spin box. Default: 16. /// The step used to increment/decrement the spin box when using the mouse wheel. Default: 0.05. - explicit VariationTreeDoubleSpinBox(QWidget* p, VariationTreeWidgetItem* widgetItem, Variation* 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) { m_WidgetItem = widgetItem; m_Param = param; - m_Variation = var; + m_Id = id; setDecimals(3); } virtual ~VariationTreeDoubleSpinBox() { } bool IsParam() { return !m_Param.empty(); } string ParamName() { return m_Param; } - Variation* GetVariation() { return m_Variation; } - VariationTreeWidgetItem* WidgetItem() { return m_WidgetItem; } + eVariationId GetVariationId() { return m_Id; } + VariationTreeWidgetItem* WidgetItem() { return m_WidgetItem; } private: string m_Param; - Variation* m_Variation; - VariationTreeWidgetItem* m_WidgetItem; + eVariationId m_Id; + VariationTreeWidgetItem* m_WidgetItem; }; diff --git a/Source/Fractorium/Fractorium.cpp b/Source/Fractorium/Fractorium.cpp index c4eb5ad..b2d3b42 100644 --- a/Source/Fractorium/Fractorium.cpp +++ b/Source/Fractorium/Fractorium.cpp @@ -114,6 +114,8 @@ Fractorium::Fractorium(QWidget* p) #endif m_Controller = unique_ptr(new FractoriumEmberController(this)); + m_Controller->SetupVariationTree(); + if (m_Wrapper.CheckOpenCL() && m_Settings->OpenCL() && m_QualitySpin->value() < 30) m_QualitySpin->setValue(30); diff --git a/Source/Fractorium/FractoriumEmberController.cpp b/Source/Fractorium/FractoriumEmberController.cpp index 8185357..70a4dbe 100644 --- a/Source/Fractorium/FractoriumEmberController.cpp +++ b/Source/Fractorium/FractoriumEmberController.cpp @@ -75,7 +75,6 @@ FractoriumEmberController::FractoriumEmberController(Fractorium* fractorium) m_SheepTools = unique_ptr>(new SheepTools("flam3-palettes.xml", new EmberNs::Renderer())); m_GLController = unique_ptr>(new GLEmberController(fractorium, fractorium->ui.GLDisplay, this)); m_PreviewRenderer = unique_ptr>(new EmberNs::Renderer()); - SetupVariationTree(); //Initial combo change event to fill the palette table will be called automatically later. if (!InitPaletteList("./")) diff --git a/Source/Fractorium/FractoriumXformsVariations.cpp b/Source/Fractorium/FractoriumXformsVariations.cpp index c36c270..cbd43fc 100644 --- a/Source/Fractorium/FractoriumXformsVariations.cpp +++ b/Source/Fractorium/FractoriumXformsVariations.cpp @@ -6,7 +6,7 @@ /// void Fractorium::InitXformsVariationsUI() { - QTreeWidget* tree = ui.VariationsTree; + auto tree = ui.VariationsTree; tree->clear(); tree->header()->setSectionsClickable(true); @@ -32,19 +32,19 @@ void FractoriumEmberController::SetupVariationTree() T fMax = TMAX; QSize hint0(75, 16); QSize hint1(30, 16); - QTreeWidget* tree = m_Fractorium->ui.VariationsTree; + auto tree = m_Fractorium->ui.VariationsTree; tree->clear(); tree->blockSignals(true); for (size_t i = 0; i < m_VariationList.Size(); i++) { - Variation* var = m_VariationList.GetVariation(i); - ParametricVariation* parVar = dynamic_cast*>(var); + auto var = m_VariationList.GetVariation(i); + auto parVar = dynamic_cast*>(var); //First add the variation, with a spinner for its weight. - VariationTreeWidgetItem* item = new VariationTreeWidgetItem(var->VariationId(), tree); - VariationTreeDoubleSpinBox* spinBox = new VariationTreeDoubleSpinBox(tree, item, parVar ? parVar : var, ""); + auto item = new VariationTreeWidgetItem(var->VariationId(), tree); + auto spinBox = new VariationTreeDoubleSpinBox(tree, item, var->VariationId(), ""); item->setText(0, QString::fromStdString(var->Name())); item->setSizeHint(0, hint0); @@ -67,8 +67,8 @@ void FractoriumEmberController::SetupVariationTree() { if (!params[j].IsPrecalc()) { - VariationTreeWidgetItem* paramWidget = new VariationTreeWidgetItem(var->VariationId(), item); - VariationTreeDoubleSpinBox* varSpinBox = new VariationTreeDoubleSpinBox(tree, paramWidget, parVar, params[j].Name()); + auto paramWidget = new VariationTreeWidgetItem(var->VariationId(), item); + auto varSpinBox = new VariationTreeDoubleSpinBox(tree, paramWidget, parVar->VariationId(), params[j].Name()); paramWidget->setText(0, params[j].Name().c_str()); paramWidget->setSizeHint(0, hint0); @@ -108,13 +108,13 @@ void FractoriumEmberController::ClearVariationsTree() for (uint i = 0; i < tree->topLevelItemCount(); i++) { QTreeWidgetItem* item = tree->topLevelItem(i); - VariationTreeDoubleSpinBox* spinBox = dynamic_cast*>(tree->itemWidget(item, 1)); + auto* spinBox = dynamic_cast(tree->itemWidget(item, 1)); spinBox->SetValueStealth(0); for (uint j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params. { - if ((spinBox = dynamic_cast*>(tree->itemWidget(item->child(j), 1))))//Cast the child widget to the VariationTreeDoubleSpinBox type. + if ((spinBox = dynamic_cast(tree->itemWidget(item->child(j), 1))))//Cast the child widget to the VariationTreeDoubleSpinBox type. spinBox->SetValueStealth(0); } } @@ -130,17 +130,17 @@ void FractoriumEmberController::ClearVariationsTree() template void FractoriumEmberController::VariationSpinBoxValueChanged(double d)//Would be awesome to make this work for all.//TODO { - QObject* objSender = m_Fractorium->sender(); - QTreeWidget* tree = m_Fractorium->ui.VariationsTree; - VariationTreeDoubleSpinBox* sender = dynamic_cast*>(objSender); - Xform* xform = m_Ember.GetTotalXform(m_Fractorium->ui.CurrentXformCombo->currentIndex());//Will retrieve normal xform or final if needed. + auto objSender = m_Fractorium->sender(); + auto tree = m_Fractorium->ui.VariationsTree; + auto sender = dynamic_cast(objSender); + auto xform = m_Ember.GetTotalXform(m_Fractorium->ui.CurrentXformCombo->currentIndex());//Will retrieve normal xform or final if needed. if (sender && xform) { - Variation* var = sender->GetVariation();//The variation attached to the sender, for reference only. - ParametricVariation* parVar = dynamic_cast*>(var);//The parametric cast of that variation. - Variation* xformVar = xform->GetVariationById(var->VariationId());//The corresponding variation in the currently selected xform. - VariationTreeWidgetItem* widgetItem = sender->WidgetItem(); + auto var = m_VariationList.GetVariation(sender->GetVariationId());//The variation attached to the sender, for reference only. + auto parVar = dynamic_cast*>(var);//The parametric cast of that variation. + auto xformVar = xform->GetVariationById(var->VariationId());//The corresponding variation in the currently selected xform. + auto widgetItem = sender->WidgetItem(); bool isParam = parVar && sender->IsParam(); if (isParam) @@ -175,7 +175,7 @@ void FractoriumEmberController::VariationSpinBoxValueChanged(double d)//Would { //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. - Variation* 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; xform->AddVariation(newVar); @@ -185,14 +185,14 @@ void FractoriumEmberController::VariationSpinBoxValueChanged(double d)//Would //for the child parameters and assign them to the newly added variation. if (parVar) { - ParametricVariation* newParVar = dynamic_cast*>(newVar); + auto newParVar = dynamic_cast*>(newVar); 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. - QWidget* itemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child. + auto childItem = widgetItem->child(i);//Get the child. + auto itemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child. - if (VariationTreeDoubleSpinBox* spinBox = dynamic_cast*>(itemWidget))//Cast the widget to the VariationTreeDoubleSpinBox type. + if (auto spinBox = dynamic_cast(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. @@ -218,18 +218,18 @@ void Fractorium::OnVariationSpinBoxValueChanged(double d) { m_Controller->Variat template void FractoriumEmberController::FillVariationTreeWithXform(Xform* xform) { - QTreeWidget* tree = m_Fractorium->ui.VariationsTree; + auto tree = m_Fractorium->ui.VariationsTree; tree->blockSignals(true); for (uint i = 0; i < tree->topLevelItemCount(); i++) { - VariationTreeWidgetItem* item = dynamic_cast*>(tree->topLevelItem(i)); - Variation* var = xform->GetVariationById(item->Id());//See if this variation in the tree was contained in the xform. - ParametricVariation* parVar = dynamic_cast*>(var);//Attempt cast to parametric variation for later. - ParametricVariation* origParVar = dynamic_cast*>(m_VariationList.GetVariation(item->Id())); + auto item = dynamic_cast(tree->topLevelItem(i)); + auto var = xform->GetVariationById(item->Id());//See if this variation in the tree was contained in the xform. + auto parVar = dynamic_cast*>(var);//Attempt cast to parametric variation for later. + auto origParVar = dynamic_cast*>(m_VariationList.GetVariation(item->Id())); - if (VariationTreeDoubleSpinBox* spinBox = dynamic_cast*>(tree->itemWidget(item, 1)))//Get the widget for the item, and cast the widget to the VariationTreeDoubleSpinBox type. + if (auto spinBox = dynamic_cast(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. 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::FillVariationTreeWithXform(Xform* 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. { T* param = nullptr; - QTreeWidgetItem* childItem = item->child(j);//Get the child. - QWidget* childItemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child. + auto childItem = item->child(j);//Get the child. + auto childItemWidget = tree->itemWidget(childItem, 1);//Get the widget for the child. - if (VariationTreeDoubleSpinBox* childSpinBox = dynamic_cast*>(childItemWidget))//Cast the widget to the VariationTreeDoubleSpinBox type. + if (auto childSpinBox = dynamic_cast(childItemWidget))//Cast the widget to the VariationTreeDoubleSpinBox type. { string s = childItem->text(0).toStdString();//Get the name of the child. diff --git a/Source/Fractorium/VariationTreeWidgetItem.h b/Source/Fractorium/VariationTreeWidgetItem.h index 370eb3f..2ac3b88 100644 --- a/Source/Fractorium/VariationTreeWidgetItem.h +++ b/Source/Fractorium/VariationTreeWidgetItem.h @@ -13,7 +13,6 @@ /// by index or by weight. It supports weights less than, equal to, or /// greater than zero. /// -template class VariationTreeWidgetItem : public QTreeWidgetItem { public: @@ -56,24 +55,24 @@ private: int column = treeWidget()->sortColumn(); eVariationId index1, index2; double weight1 = 0, weight2 = 0; - VariationTreeWidgetItem* varItemWidget; - VariationTreeDoubleSpinBox* spinBox1, *spinBox2; + VariationTreeWidgetItem* varItemWidget; + VariationTreeDoubleSpinBox* spinBox1, *spinBox2; - QWidget* itemWidget1 = treeWidget()->itemWidget(const_cast*>(this), 1);//Get the widget for the second column. + auto itemWidget1 = treeWidget()->itemWidget(const_cast(this), 1);//Get the widget for the second column. - if ((spinBox1 = dynamic_cast*>(itemWidget1)))//Cast the widget to the VariationTreeDoubleSpinBox type. + if ((spinBox1 = dynamic_cast(itemWidget1)))//Cast the widget to the VariationTreeDoubleSpinBox type. { - QWidget* itemWidget2 = treeWidget()->itemWidget(const_cast(&other), 1);//Get the widget for the second column of the widget item passed in. + auto itemWidget2 = treeWidget()->itemWidget(const_cast(&other), 1);//Get the widget for the second column of the widget item passed in. - if ((spinBox2 = dynamic_cast*>(itemWidget2)))//Cast the widget to the VariationTreeDoubleSpinBox type. + if ((spinBox2 = dynamic_cast(itemWidget2)))//Cast the widget to the VariationTreeDoubleSpinBox type. { if (spinBox1->IsParam() || spinBox2->IsParam())//Do not sort params, their order will always remain the same. return false; weight1 = spinBox1->value(); weight2 = spinBox2->value(); - index1 = spinBox1->GetVariation()->VariationId(); - index2 = spinBox2->GetVariation()->VariationId(); + index1 = spinBox1->GetVariationId(); + index2 = spinBox2->GetVariationId(); if (column == 0)//First column clicked, sort by variation index. {