Fixed broken feature 'Default height and size'.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-01-03 15:21:30 +02:00
parent fa410de76d
commit 65bf17fcf9
4 changed files with 114 additions and 66 deletions

View File

@ -88,12 +88,10 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat
InitComboBox(ui->comboBoxHeight, heights); InitComboBox(ui->comboBoxHeight, heights);
InitComboBox(ui->comboBoxSize, sizes); InitComboBox(ui->comboBoxSize, sizes);
const QString height = QString().setNum(static_cast<int>(UnitConvertor(doc->GetDefCustomHeight(), const QString height = QString().setNum(doc->GetDefCustomHeight());
*pattern->GetPatternUnit(), Unit::Cm)));
SetDefaultHeight(height); SetDefaultHeight(height);
const QString size = QString().setNum(static_cast<int>(UnitConvertor(doc->GetDefCustomSize(), const QString size = QString().setNum(doc->GetDefCustomSize());
*pattern->GetPatternUnit(), Unit::Cm)));
SetDefaultSize(size); SetDefaultSize(size);
connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, &DialogPatternProperties::ToggleComboBox); connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, &DialogPatternProperties::ToggleComboBox);
@ -454,18 +452,12 @@ void DialogPatternProperties::SaveDefValues()
if (ui->radioButtonDefFromM->isChecked()) if (ui->radioButtonDefFromM->isChecked())
{ {
doc->SetDefCustom(false); doc->SetDefCustom(false);
doc->SetDefCustomHeight(0);
doc->SetDefCustomSize(0);
} }
else else
{ {
doc->SetDefCustom(true); doc->SetDefCustom(true);
const int height = static_cast<int>(UnitConvertor(ui->comboBoxHeight->currentText().toInt(), doc->SetDefCustomHeight(ui->comboBoxHeight->currentText().toInt());
Unit::Cm, *pattern->GetPatternUnit())); doc->SetDefCustomSize(ui->comboBoxSize->currentText().toInt());
doc->SetDefCustomHeight(height);
const int size = static_cast<int>(UnitConvertor(ui->comboBoxSize->currentText().toInt(),
Unit::Cm, *pattern->GetPatternUnit()));
doc->SetDefCustomSize(size);
} }
defaultChanged = false; defaultChanged = false;
} }
@ -481,7 +473,7 @@ void DialogPatternProperties::SetDefaultHeight(const QString &def)
} }
else else
{ {
const int height = static_cast<int>(UnitConvertor(pattern->height(), *pattern->GetPatternUnit(), Unit::Cm)); const int height = static_cast<int>(pattern->height());
index = ui->comboBoxHeight->findText(QString().setNum(height)); index = ui->comboBoxHeight->findText(QString().setNum(height));
if (index != -1) if (index != -1)
{ {
@ -502,7 +494,7 @@ void DialogPatternProperties::SetDefaultSize(const QString &def)
} }
else else
{ {
const int size = static_cast<int>(UnitConvertor(pattern->size(), *pattern->GetPatternUnit(), Unit::Cm)); const int size = static_cast<int>(pattern->size());
index = ui->comboBoxSize->findText(QString().setNum(size)); index = ui->comboBoxSize->findText(QString().setNum(size));
if (index != -1) if (index != -1)
{ {
@ -572,7 +564,8 @@ void DialogPatternProperties::InitComboBox(QComboBox *box, const QMap<GVal, bool
i.next(); i.next();
if (i.value() && i.key() != GVal::ALL) if (i.value() && i.key() != GVal::ALL)
{ {
box->addItem(QString().setNum(static_cast<int>(i.key()))); box->addItem(QString().setNum(static_cast<int>(UnitConvertor(static_cast<int>(i.key()), Unit::Cm,
*pattern->GetPatternUnit()))));
} }
} }
} }

View File

@ -2693,8 +2693,7 @@ void MainWindow::ChangedHeight(const QString &text)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetDefaultHeight() void MainWindow::SetDefaultHeight()
{ {
const QString defHeight = QString().setNum(static_cast<int>(UnitConvertor(doc->GetDefCustomHeight(), const QString defHeight = QString().setNum(doc->GetDefCustomHeight());
*pattern->GetPatternUnit(), Unit::Cm)));
int index = gradationHeights->findText(defHeight); int index = gradationHeights->findText(defHeight);
if (index != -1) if (index != -1)
{ {
@ -2707,18 +2706,14 @@ void MainWindow::SetDefaultHeight()
{ {
gradationHeights->setCurrentIndex(index); gradationHeights->setCurrentIndex(index);
} }
else
{
pattern->SetHeight(gradationHeights->currentText().toInt());
}
} }
pattern->SetHeight(gradationHeights->currentText().toInt());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetDefaultSize() void MainWindow::SetDefaultSize()
{ {
const QString defSize = QString().setNum(static_cast<int>(UnitConvertor(doc->GetDefCustomSize(), const QString defSize = QString().setNum(doc->GetDefCustomSize());
*pattern->GetPatternUnit(), Unit::Cm)));
int index = gradationSizes->findText(defSize); int index = gradationSizes->findText(defSize);
if (index != -1) if (index != -1)
{ {
@ -2731,11 +2726,8 @@ void MainWindow::SetDefaultSize()
{ {
gradationSizes->setCurrentIndex(index); gradationSizes->setCurrentIndex(index);
} }
else
{
pattern->SetSize(gradationSizes->currentText().toInt());
}
} }
pattern->SetSize(gradationSizes->currentText().toInt());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -2547,7 +2547,16 @@ void VPattern::SetDefCustom(bool value)
QDomElement domElement = domNode.toElement(); QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false) if (domElement.isNull() == false)
{ {
SetAttribute(domElement, AttrCustom, value); if (value == false)
{
domElement.removeAttribute(AttrDefHeight);
SetDefCustomHeight(0);
SetDefCustomSize(0);
}
else
{
SetAttribute(domElement, AttrCustom, value);
}
modified = true; modified = true;
} }
else else

View File

@ -654,24 +654,48 @@ void VAbstractPattern::SetGradationHeights(const QMap<GHeights, bool> &options)
{ {
case 0: // TagHeights case 0: // TagHeights
SetAttribute(domElement, AttrAll, options.value(GHeights::ALL)); SetAttribute(domElement, AttrAll, options.value(GHeights::ALL));
SetAttribute(domElement, AttrH92, options.value(GHeights::H92)); if (options.value(GHeights::ALL))
SetAttribute(domElement, AttrH98, options.value(GHeights::H98)); {
SetAttribute(domElement, AttrH104, options.value(GHeights::H104)); domElement.removeAttribute(AttrH92);
SetAttribute(domElement, AttrH110, options.value(GHeights::H110)); domElement.removeAttribute(AttrH98);
SetAttribute(domElement, AttrH116, options.value(GHeights::H116)); domElement.removeAttribute(AttrH104);
SetAttribute(domElement, AttrH122, options.value(GHeights::H122)); domElement.removeAttribute(AttrH110);
SetAttribute(domElement, AttrH128, options.value(GHeights::H128)); domElement.removeAttribute(AttrH116);
SetAttribute(domElement, AttrH134, options.value(GHeights::H134)); domElement.removeAttribute(AttrH122);
SetAttribute(domElement, AttrH140, options.value(GHeights::H140)); domElement.removeAttribute(AttrH128);
SetAttribute(domElement, AttrH146, options.value(GHeights::H146)); domElement.removeAttribute(AttrH134);
SetAttribute(domElement, AttrH152, options.value(GHeights::H152)); domElement.removeAttribute(AttrH140);
SetAttribute(domElement, AttrH158, options.value(GHeights::H158)); domElement.removeAttribute(AttrH146);
SetAttribute(domElement, AttrH164, options.value(GHeights::H164)); domElement.removeAttribute(AttrH152);
SetAttribute(domElement, AttrH170, options.value(GHeights::H170)); domElement.removeAttribute(AttrH158);
SetAttribute(domElement, AttrH176, options.value(GHeights::H176)); domElement.removeAttribute(AttrH164);
SetAttribute(domElement, AttrH182, options.value(GHeights::H182)); domElement.removeAttribute(AttrH170);
SetAttribute(domElement, AttrH188, options.value(GHeights::H188)); domElement.removeAttribute(AttrH176);
SetAttribute(domElement, AttrH194, options.value(GHeights::H194)); domElement.removeAttribute(AttrH182);
domElement.removeAttribute(AttrH188);
domElement.removeAttribute(AttrH194);
}
else
{
SetAttribute(domElement, AttrH92, options.value(GHeights::H92));
SetAttribute(domElement, AttrH98, options.value(GHeights::H98));
SetAttribute(domElement, AttrH104, options.value(GHeights::H104));
SetAttribute(domElement, AttrH110, options.value(GHeights::H110));
SetAttribute(domElement, AttrH116, options.value(GHeights::H116));
SetAttribute(domElement, AttrH122, options.value(GHeights::H122));
SetAttribute(domElement, AttrH128, options.value(GHeights::H128));
SetAttribute(domElement, AttrH134, options.value(GHeights::H134));
SetAttribute(domElement, AttrH140, options.value(GHeights::H140));
SetAttribute(domElement, AttrH146, options.value(GHeights::H146));
SetAttribute(domElement, AttrH152, options.value(GHeights::H152));
SetAttribute(domElement, AttrH158, options.value(GHeights::H158));
SetAttribute(domElement, AttrH164, options.value(GHeights::H164));
SetAttribute(domElement, AttrH170, options.value(GHeights::H170));
SetAttribute(domElement, AttrH176, options.value(GHeights::H176));
SetAttribute(domElement, AttrH182, options.value(GHeights::H182));
SetAttribute(domElement, AttrH188, options.value(GHeights::H188));
SetAttribute(domElement, AttrH194, options.value(GHeights::H194));
}
modified = true; modified = true;
emit patternChanged(false); emit patternChanged(false);
@ -798,24 +822,48 @@ void VAbstractPattern::SetGradationSizes(const QMap<GSizes, bool> &options)
break; break;
case 1: // TagSizes case 1: // TagSizes
SetAttribute(domElement, AttrAll, options.value(GSizes::ALL)); SetAttribute(domElement, AttrAll, options.value(GSizes::ALL));
SetAttribute(domElement, AttrS22, options.value(GSizes::S22)); if (options.value(GSizes::ALL))
SetAttribute(domElement, AttrS24, options.value(GSizes::S24)); {
SetAttribute(domElement, AttrS26, options.value(GSizes::S26)); domElement.removeAttribute(AttrS22);
SetAttribute(domElement, AttrS28, options.value(GSizes::S28)); domElement.removeAttribute(AttrS24);
SetAttribute(domElement, AttrS30, options.value(GSizes::S30)); domElement.removeAttribute(AttrS26);
SetAttribute(domElement, AttrS32, options.value(GSizes::S32)); domElement.removeAttribute(AttrS28);
SetAttribute(domElement, AttrS34, options.value(GSizes::S34)); domElement.removeAttribute(AttrS30);
SetAttribute(domElement, AttrS36, options.value(GSizes::S36)); domElement.removeAttribute(AttrS32);
SetAttribute(domElement, AttrS38, options.value(GSizes::S38)); domElement.removeAttribute(AttrS34);
SetAttribute(domElement, AttrS40, options.value(GSizes::S40)); domElement.removeAttribute(AttrS36);
SetAttribute(domElement, AttrS42, options.value(GSizes::S42)); domElement.removeAttribute(AttrS38);
SetAttribute(domElement, AttrS44, options.value(GSizes::S44)); domElement.removeAttribute(AttrS40);
SetAttribute(domElement, AttrS46, options.value(GSizes::S46)); domElement.removeAttribute(AttrS42);
SetAttribute(domElement, AttrS48, options.value(GSizes::S48)); domElement.removeAttribute(AttrS44);
SetAttribute(domElement, AttrS50, options.value(GSizes::S50)); domElement.removeAttribute(AttrS46);
SetAttribute(domElement, AttrS52, options.value(GSizes::S52)); domElement.removeAttribute(AttrS48);
SetAttribute(domElement, AttrS54, options.value(GSizes::S54)); domElement.removeAttribute(AttrS50);
SetAttribute(domElement, AttrS56, options.value(GSizes::S56)); domElement.removeAttribute(AttrS52);
domElement.removeAttribute(AttrS54);
domElement.removeAttribute(AttrS56);
}
else
{
SetAttribute(domElement, AttrS22, options.value(GSizes::S22));
SetAttribute(domElement, AttrS24, options.value(GSizes::S24));
SetAttribute(domElement, AttrS26, options.value(GSizes::S26));
SetAttribute(domElement, AttrS28, options.value(GSizes::S28));
SetAttribute(domElement, AttrS30, options.value(GSizes::S30));
SetAttribute(domElement, AttrS32, options.value(GSizes::S32));
SetAttribute(domElement, AttrS34, options.value(GSizes::S34));
SetAttribute(domElement, AttrS36, options.value(GSizes::S36));
SetAttribute(domElement, AttrS38, options.value(GSizes::S38));
SetAttribute(domElement, AttrS40, options.value(GSizes::S40));
SetAttribute(domElement, AttrS42, options.value(GSizes::S42));
SetAttribute(domElement, AttrS44, options.value(GSizes::S44));
SetAttribute(domElement, AttrS46, options.value(GSizes::S46));
SetAttribute(domElement, AttrS48, options.value(GSizes::S48));
SetAttribute(domElement, AttrS50, options.value(GSizes::S50));
SetAttribute(domElement, AttrS52, options.value(GSizes::S52));
SetAttribute(domElement, AttrS54, options.value(GSizes::S54));
SetAttribute(domElement, AttrS56, options.value(GSizes::S56));
}
modified = true; modified = true;
emit patternChanged(false); emit patternChanged(false);
@ -973,8 +1021,14 @@ void VAbstractPattern::CheckTagExists(const QString &tag)
case 4: //TagGradation case 4: //TagGradation
{ {
QDomElement gradation = createElement(TagGradation); QDomElement gradation = createElement(TagGradation);
gradation.appendChild(createElement(TagHeights));
gradation.appendChild(createElement(TagSizes)); QDomElement heights = createElement(TagHeights);
heights.setAttribute(AttrAll, QLatin1Literal("true"));
gradation.appendChild(heights);
QDomElement sizes = createElement(TagSizes);
sizes.setAttribute(AttrAll, QLatin1Literal("true"));
gradation.appendChild(sizes);
for (int i = tags.indexOf(tag)-1; i >= 0; --i) for (int i = tags.indexOf(tag)-1; i >= 0; --i)
{ {