Skip to content

Commit

Permalink
Fix use dithering matrix name to save dynamics options
Browse files Browse the repository at this point in the history
Prior this fix the index of the dithering matrix was saved instead
its name. This will prevent inadvertent changes after
the installation of new dithering matrices.
  • Loading branch information
Gasparoken committed Aug 24, 2023
1 parent 8032817 commit 7e9d776
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@
<option id="min_size" type="int" default="1" />
<option id="min_angle" type="int" default="1" />
<option id="color_from_to" type="app::tools::ColorFromTo" default="app::tools::ColorFromTo::BgToFg" />
<option id="matrix_index" type="int" default="0" />
<option id="matrix_name" type="std::string" />
<option id="min_pressure_threshold" type="double" default="0.1" />
<option id="max_pressure_threshold" type="double" default="0.9" />
<option id="min_velocity_threshold" type="double" default="0.1" />
Expand Down
5 changes: 3 additions & 2 deletions src/app/ui/context_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ class ContextBar::DynamicsField : public ButtonSet
dynaPref.maxPressureThreshold(m_dynamics.maxPressureThreshold);
dynaPref.maxVelocityThreshold(m_dynamics.maxVelocityThreshold);
dynaPref.colorFromTo(m_dynamics.colorFromTo);
dynaPref.matrixIndex(m_popup->ditheringIndex());
dynaPref.matrixName(m_popup->ditheringMatrixName());
}

void loadDynamicsPref() {
Expand All @@ -1242,7 +1242,8 @@ class ContextBar::DynamicsField : public ButtonSet
m_dynamics.colorFromTo = dynaPref.colorFromTo();

DitheringSelector matrixSel(DitheringSelector::SelectMatrix);
matrixSel.setSelectedItemIndex(dynaPref.matrixIndex());
matrixSel.setSelectedItemIndex(matrixSel.getSelectedIndexByName(
dynaPref.matrixName()));
render::DitheringMatrix matrix(matrixSel.ditheringMatrix());
m_dynamics.ditheringMatrix = matrix;
}
Expand Down
7 changes: 4 additions & 3 deletions src/app/ui/dithering_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ void DitheringSelector::onInitTheme(ui::InitThemeEvent& ev)
setSizeHint(getItem(0)->sizeHint());
}

void DitheringSelector::setSelectedIndex(int itemIndex)
void DitheringSelector::setSelectedItemByName(std::string name)
{
setSelectedItemIndex(itemIndex);
regenerate(itemIndex);
int index = getSelectedIndexByName(name);
setSelectedItemIndex(index);
regenerate(index);
}

void DitheringSelector::regenerate(int selectedItemIndex)
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/dithering_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace app {

render::DitheringAlgorithm ditheringAlgorithm();
render::DitheringMatrix ditheringMatrix();
void setSelectedIndex(int itemIndex);
void setSelectedItemByName(std::string name);

protected:
void onInitTheme(ui::InitThemeEvent& ev) override;
Expand Down
13 changes: 8 additions & 5 deletions src/app/ui/dynamics_popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "app/ui/dynamics_popup.h"

#include "app/app.h"
#include "app/i18n/strings.h"
#include "app/tools/tool_box.h"
#include "app/ui/dithering_selector.h"
#include "app/ui/skin/skin_theme.h"
Expand Down Expand Up @@ -305,10 +306,11 @@ void DynamicsPopup::setOptionsGridVisibility(bool state)
expandWindow(sizeHint());
}

int DynamicsPopup::ditheringIndex() const {
std::string DynamicsPopup::ditheringMatrixName() const {
if (m_ditheringSel)
return m_ditheringSel->getSelectedItemIndex();
return 0;
return m_ditheringSel->getItemText(
m_ditheringSel->getSelectedItemIndex());
return Strings::dithering_selector_no_dithering();
}

void DynamicsPopup::loadDynamicsPref(bool sameInAllTools) {
Expand Down Expand Up @@ -344,7 +346,7 @@ void DynamicsPopup::loadDynamicsPref(bool sameInAllTools) {
dynaPref.gradient() == tools::DynamicSensor::Velocity);

if (m_ditheringSel)
m_ditheringSel->setSelectedIndex(dynaPref.matrixIndex());
m_ditheringSel->setSelectedItemByName(dynaPref.matrixName());
}

void DynamicsPopup::saveDynamicsPref(bool sameInAllTools) {
Expand All @@ -369,7 +371,8 @@ void DynamicsPopup::saveDynamicsPref(bool sameInAllTools) {
dynaPref->gradient(dyna.gradient);

if (m_ditheringSel)
dynaPref->matrixIndex(m_ditheringSel->getSelectedItemIndex());
dynaPref->matrixName(m_ditheringSel->getItemText(
m_ditheringSel->getSelectedItemIndex()));
}

tools::DynamicsOptions DynamicsPopup::getDynamics() const
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/dynamics_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace app {
void setOptionsGridVisibility(bool state);
void loadDynamicsPref(bool sameInAllTools);
void saveDynamicsPref(bool sameInAllTools);
int ditheringIndex() const;
std::string ditheringMatrixName() const;
void refreshVisibility();
bool sharedSettings() const;

Expand Down
8 changes: 8 additions & 0 deletions src/ui/combobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ void ComboBox::setSelectedItemIndex(int itemIndex)
}
}

int ComboBox::getSelectedIndexByName(std::string itemName) const
{
for (int i=0; i < m_items.size(); i++)
if (itemName == getItemText(i))
return i;
return 0;
}

std::string ComboBox::getValue() const
{
if (isEditable())
Expand Down
1 change: 1 addition & 0 deletions src/ui/combobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace ui {

int getSelectedItemIndex() const;
void setSelectedItemIndex(int itemIndex);
int getSelectedIndexByName(std::string itemName) const;

std::string getValue() const;
void setValue(const std::string& value);
Expand Down

0 comments on commit 7e9d776

Please sign in to comment.