--Bug fixes

-Fix a variety of very strange bugs when clicking around on palettes in different files in the palette editor.
This commit is contained in:
Person 2018-01-29 22:14:48 -08:00
parent cef4066271
commit b0dae7795a
4 changed files with 35 additions and 14 deletions

View File

@ -84,6 +84,7 @@ bool PaletteList<T>::AddPaletteToFile(const string& filename, const Palette<T>&
if (auto p = GetPaletteListByFullPathOrFilename(filename))
{
p->push_back(palette);
p->back().m_Filename = make_shared<string>(filename);//Ensure the filename matches because this could have been duplicated from another palette file.
p->back().m_Index = int(p->size()) - 1;
Save(filename);
return true;
@ -489,22 +490,20 @@ const string& PaletteList<T>::Name(size_t index)
}
/// <summary>
/// Determines whether at least one palette in the passed in palette file is modifiable,
/// Determines whether all palettes in the passed in palette file are modifiable,
/// meaning whether the source colors have at least one element in them.
/// </summary>
/// <param name="filename">The full path to the existing palette file to search for a modifiable palette in</param>
/// <returns>True if at least one palette in the file was modifiable, else false.</returns>
/// <returns>True if at all palettes in the file were modifiable, else false.</returns>
template <typename T>
bool PaletteList<T>::IsModifiable(const string& filename)
{
if (auto palFile = GetPaletteListByFullPathOrFilename(filename))
{
for (auto& pal : *palFile)
if (!pal.m_SourceColors.empty())
return true;
}
if (pal.m_SourceColors.empty())
return false;
return false;
return true;
}
/// <summary>

View File

@ -87,6 +87,7 @@ void DoubleSpinBox::DoubleClickNonZero(double val)
/// <summary>
/// Get the default step used when the user scrolls.
/// </summary>
/// <returns>The default step as a double.</returns>
double DoubleSpinBox::Step()
{
return m_Step;
@ -104,6 +105,7 @@ void DoubleSpinBox::Step(double step)
/// <summary>
/// Get the small step to be used when the user holds down shift while scrolling.
/// </summary>
/// <returns>The small step as a double.</returns>
double DoubleSpinBox::SmallStep()
{
return m_SmallStep;
@ -423,13 +425,19 @@ void VariationTreeDoubleSpinBox::FourOverPiActionTriggered(bool checked) { setV
void VariationTreeDoubleSpinBox::SqrtTwoActionTriggered(bool checked) { setValue(M_SQRT2); }
void VariationTreeDoubleSpinBox::SqrtThreeActionTriggered(bool checked) { setValue(std::sqrt(3.0)); }
/// <summary>
/// Override which converts the passed in double to text.
/// </summary>
/// <returns>Text showing decimals() decimal places, or sometimes scientific notation.</returns>
QString VariationTreeDoubleSpinBox::textFromValue(double value) const
{
return QWidget::locale().toString(value, 'g', decimals());
}
/// <summary>
/// Override which converts the passed in text to a double
/// </summary>
/// <returns>The converted double</returns>
double VariationTreeDoubleSpinBox::valueFromText(const QString& text) const
{
return QWidget::locale().toDouble(text);

View File

@ -484,6 +484,7 @@ void PaletteEditor::EmitColorIndexChanged(size_t index, float value)
/// Helper to lazily instantiate an open file dialog.
/// Once created, it will remain alive for the duration of the program run.
/// </summary>
/// <returns>The list of filenames selected</returns>
QStringList PaletteEditor::SetupOpenImagesDialog()
{
QStringList filenames;
@ -555,6 +556,7 @@ void PaletteEditor::AddArrow(const QColor& color)
/// </summary>
/// <param name="filename">The full path to the image file to get random colors from</param>
/// <param name="numPoints">The number of colors to get</param>
/// <returns>A map whose keys are the color indices from 0-1, and whose values are the gradient arrows containing the color for each key position.</returns>
map<float, GradientArrow> PaletteEditor::GetRandomColorsFromImage(QString filename, int numPoints)
{
map<float, GradientArrow> colors;
@ -585,10 +587,11 @@ map<float, GradientArrow> PaletteEditor::GetRandomColorsFromImage(QString filena
/// </summary>
void PaletteEditor::EnablePaletteFileControls()
{
bool b = m_PaletteList->IsModifiable(m_CurrentPaletteFilePath);//At least one in the file is not fixed.
bool b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable.
ui->DeletePaletteButton->setEnabled(b);
ui->CopyPaletteFileButton->setEnabled(b);
ui->AppendPaletteButton->setEnabled(b);
ui->OverwritePaletteButton->setEnabled(b);
}
/// <summary>
@ -596,10 +599,11 @@ void PaletteEditor::EnablePaletteFileControls()
/// </summary>
void PaletteEditor::EnablePaletteControls()
{
auto& palette = m_GradientColorView->GetPalette(256);
bool b = !palette.m_SourceColors.empty();
bool any = m_PaletteList->IsModifiable(m_CurrentPaletteFilePath);//At least one in the file is not fixed.
ui->OverwritePaletteButton->setEnabled(b && any);
bool b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable.
ui->DeletePaletteButton->setEnabled(b);
ui->CopyPaletteFileButton->setEnabled(b);
ui->AppendPaletteButton->setEnabled(b);
ui->OverwritePaletteButton->setEnabled(b && (GetFilename(m_CurrentPaletteFilePath) == GetFilename(*m_GradientColorView->GetPalette(256).m_Filename.get())));//Only allow overwrite if the palette is from the file it's overwriting a palette in.
ui->AddColorButton->setEnabled(b);
ui->DistributeColorsButton->setEnabled(b);
ui->AutoDistributeCheckBox->setEnabled(b);
@ -609,4 +613,13 @@ void PaletteEditor::EnablePaletteControls()
ui->ArrowsSpinBox->setEnabled(b);
ui->CreatePaletteFromImageButton->setEnabled(b);
ui->CreatePaletteAgainFromImageButton->setEnabled(b);
}
/// <summary>
/// Determine whether the current file and the palette selected within it are both editable.
/// </summary>
/// <returns>True if both the currently selected palette is editable and if all palettes in the currently selected file are editable.</returns>
bool PaletteEditor::IsCurrentPaletteAndFileEditable()
{
return m_PaletteList->IsModifiable(m_CurrentPaletteFilePath) && !m_GradientColorView->GetPalette(256).m_SourceColors.empty();
}

View File

@ -73,6 +73,7 @@ private:
map<float, GradientArrow> GetRandomColorsFromImage(QString filename, int numPoints);
void EnablePaletteFileControls();
void EnablePaletteControls();
bool IsCurrentPaletteAndFileEditable();
bool m_PaletteFileChanged = false;
int m_PaletteIndex = 0;
QString m_Filename;