Added dialog Pattern materials.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-30 07:26:18 +03:00
parent da892dfc3c
commit 2885d95a43
15 changed files with 496 additions and 44 deletions

View file

@ -31,6 +31,7 @@
#include "../../core/vapplication.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../dialogdatetimeformats.h"
#include "../dialogknownmaterials.h"
#include <QMessageBox>
#include <QDate>
@ -55,19 +56,28 @@ QStringList ComboBoxAllStrings(QComboBox *combo)
//---------------------------------------------------------------------------------------------------------------------
PreferencesPatternPage::PreferencesPatternPage(QWidget *parent)
: QWidget(parent),
ui(new Ui::PreferencesPatternPage)
ui(new Ui::PreferencesPatternPage),
m_knownMaterials()
{
ui->setupUi(this);
ui->graphOutputCheck->setChecked(qApp->ValentinaSettings()->GetGraphicalOutput());
ui->undoCount->setValue(qApp->ValentinaSettings()->GetUndoCount());
VSettings *settings = qApp->ValentinaSettings();
ui->graphOutputCheck->setChecked(settings->GetGraphicalOutput());
ui->undoCount->setValue(settings->GetUndoCount());
InitDefaultSeamAllowance();
InitLabelDateTimeFormats();
ui->forbidFlippingCheck->setChecked(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping());
ui->doublePassmarkCheck->setChecked(qApp->ValentinaSettings()->IsDoublePassmark());
ui->checkBoxHideMainPath->setChecked(qApp->ValentinaSettings()->IsHideMainPath());
ui->fontComboBoxLabelFont->setCurrentFont(qApp->ValentinaSettings()->GetLabelFont());
ui->forbidFlippingCheck->setChecked(settings->GetForbidWorkpieceFlipping());
ui->doublePassmarkCheck->setChecked(settings->IsDoublePassmark());
ui->checkBoxHideMainPath->setChecked(settings->IsHideMainPath());
ui->fontComboBoxLabelFont->setCurrentFont(settings->GetLabelFont());
ui->checkBoxRemeberPatternMaterials->setChecked(settings->IsRememberPatternMaterials());
m_knownMaterials = settings->GetKnownMaterials();
connect(ui->pushButtonKnownMaterials, &QPushButton::clicked, this, &PreferencesPatternPage::ManageKnownMaterials);
}
//---------------------------------------------------------------------------------------------------------------------
@ -108,6 +118,9 @@ void PreferencesPatternPage::Apply()
settings->SetUserDefinedDateFormats(ComboBoxAllStrings(ui->comboBoxDateFormats));
settings->SetUserDefinedTimeFormats(ComboBoxAllStrings(ui->comboBoxTimeFormats));
settings->SetKnownMaterials(m_knownMaterials);
settings->SetRememberPatternMaterials(ui->checkBoxRemeberPatternMaterials->isChecked());
}
//---------------------------------------------------------------------------------------------------------------------
@ -135,6 +148,18 @@ void PreferencesPatternPage::EditDateTimeFormats()
}
}
//---------------------------------------------------------------------------------------------------------------------
void PreferencesPatternPage::ManageKnownMaterials()
{
DialogKnownMaterials editor;
editor.SetList(m_knownMaterials);
if (QDialog::Accepted == editor.exec())
{
m_knownMaterials = editor.GetList();
}
}
//---------------------------------------------------------------------------------------------------------------------
void PreferencesPatternPage::InitLabelDateTimeFormats()
{

View file

@ -51,10 +51,12 @@ public:
private slots:
void EditDateTimeFormats();
void ManageKnownMaterials();
private:
Q_DISABLE_COPY(PreferencesPatternPage)
Ui::PreferencesPatternPage *ui;
QStringList m_knownMaterials;
void InitLabelDateTimeFormats();
void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat);

View file

@ -13,7 +13,7 @@
<property name="windowTitle">
<string notr="true">Pattern</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
@ -191,6 +191,68 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Materials</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Known materials:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonKnownMaterials">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Manage list of known materials</string>
</property>
<property name="text">
<string>Manage</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxRemeberPatternMaterials">
<property name="toolTip">
<string>When manage pattern materials save them to known materials list</string>
</property>
<property name="text">
<string>Remeber pattern materials</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View file

@ -0,0 +1,196 @@
/************************************************************************
**
** @file dialogpatternmaterials.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 28 8, 2017
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2017 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "dialogpatternmaterials.h"
#include "ui_dialogpatternmaterials.h"
#include "../vmisc/def.h"
#include "../core/vapplication.h"
#include <QComboBox>
#include <QItemDelegate>
namespace
{
//---------------------------------------------------------------------------------------------------------------------
QStringList PrepareKnowMaterials(const QStringList &patternMaterials, bool rememberPM)
{
QStringList knownMaterials = qApp->ValentinaSettings()->GetKnownMaterials();
if (rememberPM)
{
for(int i=0; i < patternMaterials.size(); ++i)
{
if (not patternMaterials.at(i).isEmpty() && not knownMaterials.contains(patternMaterials.at(i)))
{
knownMaterials.append(patternMaterials.at(i));
}
}
}
return knownMaterials;
}
}
class VComboBoxDelegate : public QItemDelegate
{
public:
VComboBoxDelegate(const QStringList &items, QObject *parent = nullptr)
: QItemDelegate(parent),
m_items(items)
{
m_items.prepend(QLatin1String("--") + tr("Select material") + QLatin1String("--"));
}
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE
{
Q_UNUSED(option)
Q_UNUSED(index)
QComboBox *editor = new QComboBox(parent);
editor->addItems(m_items);
return editor;
}
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE
{
const QString value = index.model()->data(index, Qt::EditRole).toString();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
const int cIndex = comboBox->findText(value);
if (cIndex != -1)
{
comboBox->setCurrentIndex(cIndex);
}
}
virtual void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const Q_DECL_OVERRIDE
{
QComboBox *comboBox = static_cast<QComboBox*>(editor);
QString value;
const int cIndex = comboBox->currentIndex();
if (cIndex > 0)
{
value = comboBox->currentText();
}
model->setData(index, value, Qt::EditRole);
}
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE
{
Q_UNUSED(index)
editor->setGeometry(option.rect);
}
private:
Q_DISABLE_COPY(VComboBoxDelegate)
QStringList m_items;
};
//---------------------------------------------------------------------------------------------------------------------
DialogPatternMaterials::DialogPatternMaterials(const QMap<int, QString> &list, bool rememberPM, QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogPatternMaterials),
m_knownMaterials()
{
ui->setupUi(this);
m_knownMaterials = PrepareKnowMaterials(list.values(), rememberPM);
SetPatternMaterials(list);
ui->tableWidget->setItemDelegateForColumn(1, new VComboBoxDelegate(m_knownMaterials, this));
}
//---------------------------------------------------------------------------------------------------------------------
DialogPatternMaterials::~DialogPatternMaterials()
{
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternMaterials::SetPatternMaterials(const QMap<int, QString> &list)
{
ui->tableWidget->setRowCount(9);
QLatin1String per("%");
for (int i = 0; i < 9; ++i)
{
QTableWidgetItem *item = new QTableWidgetItem(per + qApp->TrVars()->PlaceholderToUser(pl_userMaterial) +
QString::number(i + 1) + per);
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
item->setTextAlignment(Qt::AlignLeft);
QFont font = item->font();
font.setBold(true);
item->setFont(font);
ui->tableWidget->setItem(i, 0, item);
QString value;
if (list.contains(i + 1))
{
value = list.value(i + 1);
}
item = new QTableWidgetItem(value);
item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidget->setItem(i, 1, item);
}
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->verticalHeader()->setDefaultSectionSize(20);
}
//---------------------------------------------------------------------------------------------------------------------
QMap<int, QString> DialogPatternMaterials::GetPatternMaterials() const
{
QMap<int, QString> materials;
for (int i = 0; i < ui->tableWidget->rowCount(); ++i)
{
const QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (not item->text().isEmpty())
{
materials.insert(i + 1, item->text());
}
}
return materials;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList DialogPatternMaterials::GetKnownMaterials() const
{
return m_knownMaterials;
}

View file

@ -0,0 +1,61 @@
/************************************************************************
**
** @file dialogpatternmaterials.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 28 8, 2017
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2017 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef DIALOGPATTERNMATERIALS_H
#define DIALOGPATTERNMATERIALS_H
#include <QDialog>
namespace Ui
{
class DialogPatternMaterials;
}
class VComboBoxDelegate;
class DialogPatternMaterials : public QDialog
{
Q_OBJECT
public:
explicit DialogPatternMaterials(const QMap<int, QString> &list, bool rememberPM, QWidget *parent = nullptr);
virtual ~DialogPatternMaterials();
QMap<int, QString> GetPatternMaterials() const;
QStringList GetKnownMaterials() const;
private:
Q_DISABLE_COPY(DialogPatternMaterials)
Ui::DialogPatternMaterials *ui;
QStringList m_knownMaterials;
void SetPatternMaterials(const QMap<int, QString> &list);
};
#endif // DIALOGPATTERNMATERIALS_H

View file

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogPatternMaterials</class>
<widget class="QDialog" name="DialogPatternMaterials">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>419</width>
<height>472</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="gridStyle">
<enum>Qt::NoPen</enum>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Placeholder</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogPatternMaterials</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogPatternMaterials</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -40,6 +40,7 @@
#include "../core/vapplication.h"
#include "../vtools/dialogs/support/dialogeditlabel.h"
#include "dialogknownmaterials.h"
#include "dialogpatternmaterials.h"
// calc how many combinations we have
static const int heightsCount = (static_cast<int>(GHeights::H200) -
@ -182,7 +183,6 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat
connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
connect(ui->pushButtonEditPatternLabel, &QPushButton::clicked, this, &DialogPatternProperties::EditLabel);
connect(ui->pushButtonKnownMaterials, &QPushButton::clicked, this, &DialogPatternProperties::ManageKnownMaterials);
connect(ui->pushButtonPatternMaterials, &QPushButton::clicked, this,
&DialogPatternProperties::ManagePatternMaterials);
@ -906,21 +906,17 @@ void DialogPatternProperties::EditLabel()
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::ManageKnownMaterials()
void DialogPatternProperties::ManagePatternMaterials()
{
VSettings *settings = qApp->ValentinaSettings();
DialogKnownMaterials editor;
editor.SetList(settings->GetKnownMaterials());
DialogPatternMaterials editor(QMap<int, QString>(), settings->IsRememberPatternMaterials());
if (QDialog::Accepted == editor.exec())
{
settings->SetKnownMaterials(editor.GetList());
if (settings->IsRememberPatternMaterials())
{
settings->SetKnownMaterials(editor.GetKnownMaterials());
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::ManagePatternMaterials()
{
}

View file

@ -62,7 +62,6 @@ private slots:
void ChangeImage();
void SaveImage();
void EditLabel();
void ManageKnownMaterials();
void ManagePatternMaterials();
private:
Q_DISABLE_COPY(DialogPatternProperties)

View file

@ -1332,30 +1332,13 @@
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Known materials:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButtonKnownMaterials">
<property name="toolTip">
<string>Manage list of known materials</string>
</property>
<property name="text">
<string>Manage</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Pattern materials:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<widget class="QPushButton" name="pushButtonPatternMaterials">
<property name="toolTip">
<string>Manage list of pattern materials</string>
@ -1376,7 +1359,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<height>90</height>
</size>
</property>
</spacer>

View file

@ -18,7 +18,8 @@ HEADERS += \
$$PWD/configpages/preferencespatternpage.h \
$$PWD/configpages/preferencespathpage.h \
$$PWD/dialogdatetimeformats.h \
$$PWD/dialogknownmaterials.h
$$PWD/dialogknownmaterials.h \
$$PWD/dialogpatternmaterials.h
SOURCES += \
$$PWD/dialogincrements.cpp \
@ -36,7 +37,8 @@ SOURCES += \
$$PWD/configpages/preferencespatternpage.cpp \
$$PWD/configpages/preferencespathpage.cpp \
$$PWD/dialogdatetimeformats.cpp \
$$PWD/dialogknownmaterials.cpp
$$PWD/dialogknownmaterials.cpp \
$$PWD/dialogpatternmaterials.cpp
FORMS += \
$$PWD/dialogincrements.ui \
@ -54,4 +56,5 @@ FORMS += \
$$PWD/configpages/preferencespatternpage.ui \
$$PWD/configpages/preferencespathpage.ui \
$$PWD/dialogdatetimeformats.ui \
$$PWD/dialogknownmaterials.ui
$$PWD/dialogknownmaterials.ui \
$$PWD/dialogpatternmaterials.ui

View file

@ -117,6 +117,7 @@ const QString pl_patternName = QStringLiteral("patternName");
const QString pl_patternNumber = QStringLiteral("patternNumber");
const QString pl_author = QStringLiteral("author");
const QString pl_customer = QStringLiteral("customer");
const QString pl_userMaterial = QStringLiteral("userMaterial");
const QString pl_pExt = QStringLiteral("pExt");
const QString pl_pFileName = QStringLiteral("pFileName");
const QString pl_mFileName = QStringLiteral("mFileName");
@ -144,6 +145,7 @@ const QStringList labelTemplatePlaceholders = QStringList() << pl_size
<< pl_patternNumber
<< pl_author
<< pl_customer
<< pl_userMaterial
<< pl_pExt
<< pl_pFileName
<< pl_mFileName

View file

@ -359,6 +359,7 @@ extern const QString pl_patternName;
extern const QString pl_patternNumber;
extern const QString pl_author;
extern const QString pl_customer;
extern const QString pl_userMaterial;
extern const QString pl_pExt;
extern const QString pl_pFileName;
extern const QString pl_mFileName;

View file

@ -51,8 +51,9 @@ const QString settingConfigurationLabelLanguage = QStringLiteral("configuration/
const QString settingPathsPattern = QStringLiteral("paths/pattern");
const QString settingPathsLayout = QStringLiteral("paths/layout");
const QString settingPatternGraphicalOutput = QStringLiteral("pattern/graphicalOutput");
const QString settingPatternKnownMaterials = QStringLiteral("pattern/knownMaterials");
const QString settingPatternGraphicalOutput = QStringLiteral("pattern/graphicalOutput");
const QString settingPatternKnownMaterials = QStringLiteral("pattern/knownMaterials");
const QString settingPatternRememberMaterials = QStringLiteral("pattern/rememberMaterials");
const QString settingCommunityServer = QStringLiteral("community/server");
const QString settingCommunityServerSecure = QStringLiteral("community/serverSecure");
@ -618,3 +619,15 @@ void VSettings::SetKnownMaterials(const QStringList &list)
{
setValue(settingPatternKnownMaterials, list);
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::IsRememberPatternMaterials() const
{
return value(settingPatternRememberMaterials, true).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetRememberPatternMaterials(bool value)
{
setValue(settingPatternRememberMaterials, value);
}

View file

@ -158,6 +158,9 @@ public:
QStringList GetKnownMaterials() const;
void SetKnownMaterials(const QStringList &list);
bool IsRememberPatternMaterials() const;
void SetRememberPatternMaterials(bool value);
private:
Q_DISABLE_COPY(VSettings)
};

View file

@ -465,6 +465,7 @@ void VTranslateVars::InitPlaceholder()
placeholders.insert(pl_patternNumber, translate("VTranslateVars", "patternNumber", "placeholder"));
placeholders.insert(pl_author, translate("VTranslateVars", "author", "placeholder"));
placeholders.insert(pl_customer, translate("VTranslateVars", "customer", "placeholder"));
placeholders.insert(pl_userMaterial, translate("VTranslateVars", "userMaterial", "placeholder"));
placeholders.insert(pl_pExt, translate("VTranslateVars", "pExt", "placeholder"));
placeholders.insert(pl_pFileName, translate("VTranslateVars", "pFileName", "placeholder"));
placeholders.insert(pl_mFileName, translate("VTranslateVars", "mFileName", "placeholder"));