User defined materials are now remembered and can also be deleted in preferences dialog

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-08-12 01:22:23 +02:00
parent b0532e6fb9
commit 86f24bf0e5
7 changed files with 109 additions and 4 deletions

View File

@ -43,6 +43,7 @@
#include <QVBoxLayout>
#include <QDirIterator>
#include <QFormLayout>
#include <QPushButton>
//---------------------------------------------------------------------------------------------------------------------
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()
{

View File

@ -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();

View File

@ -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);
}

View File

@ -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

View File

@ -602,3 +602,4 @@ void VSettings::SetMultiplier(quint8 value)
{
setValue(SettingMultiplier, value);
}

View File

@ -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(m_qslMaterials[int(mcp.m_eMaterial)]);
ui.comboBoxMaterial->setCurrentText(mcp.m_qsMaterialUserDef);
}
}
else
{
//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));

View File

@ -84,6 +84,7 @@ protected slots:
private slots:
void NameDetailChanged();
void MaterialChanged();
private:
/** @brief ui keeps information about user interface */