Update after change, set default gradation options in list.

--HG--
branch : feature
This commit is contained in:
dismine 2014-08-08 22:46:05 +03:00
parent b31069859e
commit a9a1e156af
2 changed files with 116 additions and 14 deletions

View File

@ -65,7 +65,8 @@ MainWindow::MainWindow(QWidget *parent)
view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr), view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr),
comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0),
currentToolBoxIndex(0), drawMode(true), recentFileActs{nullptr, nullptr, nullptr, nullptr, nullptr}, currentToolBoxIndex(0), drawMode(true), recentFileActs{nullptr, nullptr, nullptr, nullptr, nullptr},
separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true) separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true), gradationHeights(nullptr),
gradationSizes(nullptr)
{ {
CreateActions(); CreateActions();
CreateMenus(); CreateMenus();
@ -690,6 +691,7 @@ void MainWindow::OpenRecentFile()
void MainWindow::PatternProperties() void MainWindow::PatternProperties()
{ {
DialogPatternProperties proper(doc, this); DialogPatternProperties proper(doc, this);
connect(&proper, &DialogPatternProperties::UpdateGradation, this, &MainWindow::UpdateGradation);
proper.exec(); proper.exec();
} }
@ -764,8 +766,15 @@ void MainWindow::ToolBarOption()
const QStringList listHeights = VMeasurement::ListHeights(doc->GetGradationHeights()); const QStringList listHeights = VMeasurement::ListHeights(doc->GetGradationHeights());
const QStringList listSizes = VMeasurement::ListSizes(doc->GetGradationSizes()); const QStringList listSizes = VMeasurement::ListSizes(doc->GetGradationSizes());
SetGradationList(tr("Height: "), listHeights, &MainWindow::ChangedHeight); gradationHeights = SetGradationList(tr("Height: "), listHeights);
SetGradationList(tr("Size: "), listSizes, &MainWindow::ChangedSize); SetDefaultHeight(static_cast<int>(GHeights::H176));
connect(gradationHeights, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedHeight);
gradationSizes = SetGradationList(tr("Size: "), listSizes);
SetDefaultSize(static_cast<int>(GSizes::S50));
connect(gradationSizes, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedSize);
ui->toolBarOption->addSeparator(); ui->toolBarOption->addSeparator();
} }
@ -775,17 +784,49 @@ void MainWindow::ToolBarOption()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename Func> QComboBox *MainWindow::SetGradationList(const QString &label, const QStringList &list)
void MainWindow::SetGradationList(const QString &label, const QStringList &list, Func changeSlot)
{ {
ui->toolBarOption->addWidget(new QLabel(label)); ui->toolBarOption->addWidget(new QLabel(label));
QComboBox *comboBox = new QComboBox; QComboBox *comboBox = new QComboBox;
comboBox->addItems(list); comboBox->addItems(list);
comboBox->setCurrentIndex(14);//176 cm
ui->toolBarOption->addWidget(comboBox); ui->toolBarOption->addWidget(comboBox);
connect(comboBox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, changeSlot); return comboBox;
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetDefaultHeight(int value)
{
qreal val = VAbstractMeasurements::UnitConvertor(value, Unit::Cm, qApp->patternUnit());
QString strVal = QString("%1").arg(val);
qint32 index = gradationHeights->findText(strVal);
if (index != -1)
{
gradationHeights->setCurrentIndex(index);
}
else
{
pattern->SetHeight(gradationHeights->currentText().toInt());
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetDefaultSize(int value)
{
qreal val = VAbstractMeasurements::UnitConvertor(value, Unit::Cm, qApp->patternUnit());
QString strVal = QString("%1").arg(val);
qint32 index = gradationSizes->findText(strVal);
if (index != -1)
{
gradationSizes->setCurrentIndex(index);
}
else
{
pattern->SetSize(gradationSizes->currentText().toInt());
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1446,6 +1487,63 @@ void MainWindow::Layout()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::UpdateGradation()
{
UpdateHeightsList(VMeasurement::ListHeights(doc->GetGradationHeights()));
UpdateSizesList(VMeasurement::ListSizes(doc->GetGradationSizes()));
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::UpdateHeightsList(const QStringList &list)
{
QString val;
if (gradationHeights->currentIndex() != -1)
{
val = gradationHeights->currentText();
}
gradationHeights->blockSignals(true);
gradationHeights->clear();
gradationHeights->addItems(list);
gradationHeights->blockSignals(false);
int index = gradationHeights->findText(val);
if (index != -1)
{
gradationHeights->setCurrentIndex(index);
}
else
{
ChangedHeight(list.at(0));
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::UpdateSizesList(const QStringList &list)
{
QString val;
if (gradationSizes->currentIndex() != -1)
{
val = gradationSizes->currentText();
}
gradationSizes->blockSignals(true);
gradationSizes->clear();
gradationSizes->addItems(list);
gradationSizes->blockSignals(false);
int index = gradationSizes->findText(val);
if (index != -1)
{
gradationSizes->setCurrentIndex(index);
}
else
{
ChangedSize(list.at(0));
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief NewPattern create new empty pattern. * @brief NewPattern create new empty pattern.
@ -1480,8 +1578,7 @@ void MainWindow::PatternWasModified(bool saved)
*/ */
void MainWindow::ChangedSize(const QString & text) void MainWindow::ChangedSize(const QString & text)
{ {
qint32 size = text.toInt(); pattern->SetSize(text.toInt());
pattern->SetSize(size);
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);
} }
@ -1492,8 +1589,7 @@ void MainWindow::ChangedSize(const QString & text)
*/ */
void MainWindow::ChangedHeight(const QString &text) void MainWindow::ChangedHeight(const QString &text)
{ {
qint32 growth = text.toInt(); pattern->SetHeight(text.toInt());
pattern->SetHeight(growth);
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);
} }

View File

@ -120,6 +120,7 @@ public slots:
void SetEnabledGUI(bool enabled); void SetEnabledGUI(bool enabled);
void ClickEndVisualization(); void ClickEndVisualization();
void Layout(); void Layout();
void UpdateGradation();
signals: signals:
/** /**
* @brief ModelChosen emit after calculation all details. * @brief ModelChosen emit after calculation all details.
@ -194,6 +195,8 @@ private:
QAction *separatorAct; QAction *separatorAct;
QTimer *autoSaveTimer; QTimer *autoSaveTimer;
bool guiEnabled; bool guiEnabled;
QComboBox *gradationHeights;
QComboBox *gradationSizes;
void ToolBarOption(); void ToolBarOption();
void ToolBarDraws(); void ToolBarDraws();
void ToolBarTools(); void ToolBarTools();
@ -232,14 +235,17 @@ private:
QString PatternPieceName(const QString &text); QString PatternPieceName(const QString &text);
QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType); QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType);
void OpenPattern(const QString &filePath); void OpenPattern(const QString &filePath);
template <typename Func> QComboBox *SetGradationList(const QString &label, const QStringList &list);
void SetGradationList(const QString &label, const QStringList &list, Func changeSlot);
void ChangePP(int index , bool zoomBestFit = true); void ChangePP(int index , bool zoomBestFit = true);
/** /**
* @brief EndVisualization try show dialog after and working with tool visualization. * @brief EndVisualization try show dialog after and working with tool visualization.
*/ */
void EndVisualization(bool click = false); void EndVisualization(bool click = false);
void ZoomFirstShow(); void ZoomFirstShow();
void UpdateHeightsList(const QStringList &list);
void UpdateSizesList(const QStringList &list);
void SetDefaultHeight(int value);
void SetDefaultSize(int value);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H