From 86f24bf0e5bf8a1a4473786952787bf9d78cce04 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 12 Aug 2016 01:22:23 +0200 Subject: [PATCH] User defined materials are now remembered and can also be deleted in preferences dialog --HG-- branch : feature --- .../dialogs/configpages/configurationpage.cpp | 32 ++++++++++++- .../dialogs/configpages/configurationpage.h | 6 +++ src/libs/vmisc/vcommonsettings.cpp | 22 +++++++++ src/libs/vmisc/vcommonsettings.h | 5 ++ src/libs/vmisc/vsettings.cpp | 1 + .../vtools/dialogs/tools/dialogdetail.cpp | 46 +++++++++++++++++-- src/libs/vtools/dialogs/tools/dialogdetail.h | 1 + 7 files changed, 109 insertions(+), 4 deletions(-) diff --git a/src/app/valentina/dialogs/configpages/configurationpage.cpp b/src/app/valentina/dialogs/configpages/configurationpage.cpp index 528406837..b563632cc 100644 --- a/src/app/valentina/dialogs/configpages/configurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/configurationpage.cpp @@ -43,6 +43,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- ConfigurationPage::ConfigurationPage(QWidget *parent) @@ -77,7 +78,9 @@ ConfigurationPage::ConfigurationPage(QWidget *parent) sendGroup(nullptr), description(nullptr), drawGroup(nullptr), - toolBarGroup(nullptr) + toolBarGroup(nullptr), + userMaterialsGroup(nullptr), + userMaterialClearButton(nullptr) { QGroupBox *saveGroup = SaveGroup(); QGroupBox *langGroup = LangGroup(); @@ -85,6 +88,7 @@ ConfigurationPage::ConfigurationPage(QWidget *parent) QGroupBox *sendGroup = SendGroup(); QGroupBox *drawGroup = DrawGroup(); QGroupBox *toolBarGroup = ToolBarGroup(); + QGroupBox *userMatGroup = UserMaterialGroup(); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(saveGroup); @@ -93,6 +97,7 @@ ConfigurationPage::ConfigurationPage(QWidget *parent) mainLayout->addWidget(sendGroup); mainLayout->addWidget(drawGroup); mainLayout->addWidget(toolBarGroup); + mainLayout->addWidget(userMatGroup); mainLayout->addStretch(1); setLayout(mainLayout); } @@ -161,6 +166,16 @@ void ConfigurationPage::LabelLangChanged() labelLangChanged = true; } +//--------------------------------------------------------------------------------------------------------------------- +void ConfigurationPage::ClearUserDefinedMaterials() +{ + VSettings* pSet = qApp->ValentinaSettings(); + pSet->ClearUserDefinedMaterial(); + pSet->sync(); + QString qsMsg = tr("All user defined materials have been deleted!"); + QMessageBox::information(this, QApplication::applicationName(), qsMsg); +} + //--------------------------------------------------------------------------------------------------------------------- QGroupBox *ConfigurationPage::SaveGroup() { @@ -381,6 +396,21 @@ QGroupBox *ConfigurationPage::ToolBarGroup() return toolBarGroup; } +//--------------------------------------------------------------------------------------------------------------------- +QGroupBox *ConfigurationPage::UserMaterialGroup() +{ + userMaterialsGroup = new QGroupBox(tr("User defined materials")); + userMaterialClearButton = new QPushButton(tr("Delete all")); + connect(userMaterialClearButton, &QPushButton::clicked, this, &ConfigurationPage::ClearUserDefinedMaterials); + + QHBoxLayout* pLayout = new QHBoxLayout; + pLayout->addWidget(userMaterialClearButton); + pLayout->addStretch(1); + + userMaterialsGroup->setLayout(pLayout); + return userMaterialsGroup; +} + //--------------------------------------------------------------------------------------------------------------------- void ConfigurationPage::SystemChanged() { diff --git a/src/app/valentina/dialogs/configpages/configurationpage.h b/src/app/valentina/dialogs/configpages/configurationpage.h index fa3167a8e..86ec00faa 100644 --- a/src/app/valentina/dialogs/configpages/configurationpage.h +++ b/src/app/valentina/dialogs/configpages/configurationpage.h @@ -38,6 +38,7 @@ class QSpinBox; class QComboBox; class QGroupBox; class QLabel; +class QPushButton; class ConfigurationPage : public QWidget { @@ -50,6 +51,7 @@ public slots: void SystemChanged(); void UnitChanged(); void LabelLangChanged(); + void ClearUserDefinedMaterials(); protected: virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; private: @@ -90,12 +92,16 @@ private: QGroupBox *drawGroup; QGroupBox *toolBarGroup; + QGroupBox *userMaterialsGroup; + QPushButton* userMaterialClearButton; + QGroupBox *SaveGroup() Q_REQUIRED_RESULT; QGroupBox *LangGroup() Q_REQUIRED_RESULT; QGroupBox *PMSystemGroup() Q_REQUIRED_RESULT; QGroupBox *SendGroup() Q_REQUIRED_RESULT; QGroupBox *DrawGroup() Q_REQUIRED_RESULT; QGroupBox *ToolBarGroup() Q_REQUIRED_RESULT; + QGroupBox *UserMaterialGroup() Q_REQUIRED_RESULT; void SetLabelComboBox(const QStringList &list); void RetranslateUi(); diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 97ddf645c..253ac8723 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -75,6 +75,7 @@ const QString VCommonSettings::SettingGeneralToolbarsState = QString const QString VCommonSettings::SettingPreferenceDialogSize = QStringLiteral("preferenceDialogSize"); const QString VCommonSettings::SettingLatestSkippedVersion = QStringLiteral("lastestSkippedVersion"); const QString VCommonSettings::SettingDateOfLastRemind = QStringLiteral("dateOfLastRemind"); +const QString VCommonSettings::SettingUserDefinedMaterials = QStringLiteral("configuration/userDefinedMaterials"); static const QString commonIniFilename = QStringLiteral("common"); @@ -469,3 +470,24 @@ void VCommonSettings::SetDateOfLastRemind(const QDate &date) settings.setValue(SettingDateOfLastRemind, date); settings.sync(); } + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VCommonSettings::GetUserDefinedMaterials() const +{ + return value(SettingUserDefinedMaterials).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::AddUserDefinedMaterial(QString qsMaterial) +{ + QStringList qsl = GetUserDefinedMaterials(); + qsl << qsMaterial; + setValue(SettingUserDefinedMaterials, qsl); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::ClearUserDefinedMaterial() +{ + QStringList qsl; + setValue(SettingUserDefinedMaterials, qsl); +} diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index b56f926bb..258879e66 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -118,6 +118,10 @@ public: QDate GetDateOfLastRemind() const; void SetDateOfLastRemind(const QDate &date); + QStringList GetUserDefinedMaterials() const; + void AddUserDefinedMaterial(QString qsMaterial); + void ClearUserDefinedMaterial(); + private: Q_DISABLE_COPY(VCommonSettings) @@ -146,6 +150,7 @@ private: static const QString SettingPreferenceDialogSize; static const QString SettingLatestSkippedVersion; static const QString SettingDateOfLastRemind; + static const QString SettingUserDefinedMaterials; }; #endif // VCOMMONSETTINGS_H diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index 7de98c245..3075605a6 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -602,3 +602,4 @@ void VSettings::SetMultiplier(quint8 value) { setValue(SettingMultiplier, value); } + diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index d990ba734..da8b9e7c4 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -135,6 +135,13 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge { ui.comboBoxMaterial->addItem(m_qslMaterials[i], i); } + + QStringList qsl = qApp->Settings()->GetUserDefinedMaterials(); + for (int i = 0; i < qsl.count(); ++i) + { + ui.comboBoxMaterial->addItem(qsl[i], int(MaterialType::mtUserDefined)); + } + m_qslPlacements << tr("None") << tr("Cut on fold"); ui.comboBoxPlacement->addItems(m_qslPlacements); @@ -142,6 +149,7 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.pushButtonCancel, &QPushButton::clicked, this, &DialogDetail::Cancel); connect(ui.pushButtonRemove, &QPushButton::clicked, this, &DialogDetail::Remove); connect(ui.listWidgetMCP, &QListWidget::itemClicked, this, &DialogDetail::SetEditMode); + connect(ui.comboBoxMaterial, &QComboBox::currentTextChanged, this, &DialogDetail::MaterialChanged); SetAddMode(); ui.tabWidget->setCurrentIndex(0); @@ -243,15 +251,32 @@ void DialogDetail::UpdateList() void DialogDetail::AddUpdate() { MaterialCutPlacement mcp; + QStringList qslUserMaterials = qApp->Settings()->GetUserDefinedMaterials(); + mcp.m_qsMaterialUserDef = ui.comboBoxMaterial->currentText(); int i = ui.comboBoxMaterial->currentData().toInt(); - if (mcp.m_qsMaterialUserDef == m_qslMaterials[i]) + if (i < m_qslMaterials.count() && mcp.m_qsMaterialUserDef == m_qslMaterials[i]) { mcp.m_eMaterial = MaterialType(i); } else { mcp.m_eMaterial = MaterialType::mtUserDefined; + // check if we have new user defined material + bool bFound = false; + for (int i = 0; i < qslUserMaterials.count() && bFound == false; ++i) + { + if (mcp.m_qsMaterialUserDef == qslUserMaterials[i]) + { + bFound = true; + } + } + if (bFound == false) + { + qApp->Settings()->AddUserDefinedMaterial(mcp.m_qsMaterialUserDef); + qApp->Settings()->sync(); + ui.comboBoxMaterial->addItem(mcp.m_qsMaterialUserDef, int(MaterialType::mtUserDefined)); + } } mcp.m_iCutNumber = ui.spinBoxCutNumber->value(); @@ -315,6 +340,12 @@ void DialogDetail::NameDetailChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::MaterialChanged() +{ + ui.pushButtonAdd->setEnabled(ui.comboBoxMaterial->currentText().isEmpty() == false); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewItem add new object (point, arc, spline or spline path) to list @@ -789,11 +820,20 @@ void DialogDetail::SetEditMode() MaterialCutPlacement mcp = m_conMCP.at(iR); if (mcp.m_eMaterial == MaterialType::mtUserDefined) { - ui.comboBoxMaterial->setCurrentText(mcp.m_qsMaterialUserDef); + int iRow = qApp->Settings()->GetUserDefinedMaterials().indexOf(mcp.m_qsMaterialUserDef); + if (iRow >= 0) + { + ui.comboBoxMaterial->setCurrentIndex(iRow + m_qslMaterials.count()); + } + else + { + ui.comboBoxMaterial->setCurrentText(mcp.m_qsMaterialUserDef); + } } else { - ui.comboBoxMaterial->setCurrentText(m_qslMaterials[int(mcp.m_eMaterial)]); + //ui.comboBoxMaterial->setCurrentText(m_qslMaterials[int(mcp.m_eMaterial)]); + ui.comboBoxMaterial->setCurrentIndex(int(mcp.m_eMaterial)); } ui.spinBoxCutNumber->setValue(mcp.m_iCutNumber); ui.comboBoxPlacement->setCurrentIndex(int(mcp.m_ePlacement)); diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 69a3928af..26dbe48a0 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -84,6 +84,7 @@ protected slots: private slots: void NameDetailChanged(); + void MaterialChanged(); private: /** @brief ui keeps information about user interface */