Added dialog Known Materials.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-28 16:03:19 +03:00
parent 3ea3371d11
commit da892dfc3c
9 changed files with 481 additions and 5 deletions

View File

@ -0,0 +1,161 @@
/************************************************************************
**
** @file dialogknownmaterials.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 "dialogknownmaterials.h"
#include "ui_dialogknownmaterials.h"
//---------------------------------------------------------------------------------------------------------------------
DialogKnownMaterials::DialogKnownMaterials(QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogKnownMaterials)
{
ui->setupUi(this);
ui->lineEditMaterial->setClearButtonEnabled(true);
connect(ui->toolButtonAdd, &QToolButton::clicked, this, &DialogKnownMaterials::Add);
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogKnownMaterials::Remove);
connect(ui->lineEditMaterial, &QLineEdit::textEdited, this, &DialogKnownMaterials::SaveText);
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogKnownMaterials::ShowDetails);
}
//---------------------------------------------------------------------------------------------------------------------
DialogKnownMaterials::~DialogKnownMaterials()
{
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogKnownMaterials::SetList(const QStringList &list)
{
ui->listWidget->blockSignals(true);
ui->listWidget->clear();
int row = -1;
for (int i=0; i<list.size(); ++i)
{
if (not list.at(i).isEmpty())
{
QListWidgetItem *item = new QListWidgetItem(list.at(i));
ui->listWidget->insertItem(++row, item);
}
}
ui->listWidget->blockSignals(false);
if (ui->listWidget->count() > 0)
{
ui->listWidget->setCurrentRow(0);
}
}
//---------------------------------------------------------------------------------------------------------------------
QStringList DialogKnownMaterials::GetList() const
{
QStringList list;
for (int i=0; i<ui->listWidget->count(); ++i)
{
if (const QListWidgetItem *item = ui->listWidget->item(i))
{
if (not item->text().isEmpty())
{
list.append(item->text());
}
}
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogKnownMaterials::ShowDetails()
{
if (ui->listWidget->count() > 0)
{
const QListWidgetItem *line = ui->listWidget->currentItem();
if (line)
{
ui->lineEditMaterial->blockSignals(true);
ui->lineEditMaterial->setText(line->text());
ui->lineEditMaterial->blockSignals(false);
}
}
SetupControls();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogKnownMaterials::Add()
{
int row = ui->listWidget->currentRow();
ui->listWidget->insertItem(++row, new QListWidgetItem(tr("User material")));
ui->listWidget->setCurrentRow(row);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogKnownMaterials::Remove()
{
ui->listWidget->blockSignals(true);
QListWidgetItem *curLine = ui->listWidget->takeItem(ui->listWidget->currentRow());
if (curLine)
{
delete curLine;
}
ui->listWidget->blockSignals(false);
ShowDetails();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogKnownMaterials::SaveText(const QString &text)
{
QListWidgetItem *curLine = ui->listWidget->currentItem();
if (curLine)
{
curLine->setText(text);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogKnownMaterials::SetupControls()
{
const bool enabled = ui->listWidget->count() > 0;
if (not enabled)
{
ui->lineEditMaterial->blockSignals(true);
ui->lineEditMaterial->clear();
ui->lineEditMaterial->blockSignals(false);
}
ui->toolButtonAdd->setEnabled(true);
ui->toolButtonRemove->setEnabled(enabled);
ui->lineEditMaterial->setEnabled(enabled);
}

View File

@ -0,0 +1,63 @@
/************************************************************************
**
** @file dialogknownmaterials.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 DIALOGKNOWNMATERIALS_H
#define DIALOGKNOWNMATERIALS_H
#include <QDialog>
namespace Ui
{
class DialogKnownMaterials;
}
class DialogKnownMaterials : public QDialog
{
Q_OBJECT
public:
explicit DialogKnownMaterials(QWidget *parent = nullptr);
virtual ~DialogKnownMaterials();
void SetList(const QStringList &list);
QStringList GetList() const;
private slots:
void ShowDetails();
void Add();
void Remove();
void SaveText(const QString &text);
private:
Q_DISABLE_COPY(DialogKnownMaterials)
Ui::DialogKnownMaterials *ui;
void SetupControls();
};
#endif // DIALOGKNOWNMATERIALS_H

View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogKnownMaterials</class>
<widget class="QDialog" name="DialogKnownMaterials">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>365</width>
<height>369</height>
</rect>
</property>
<property name="windowTitle">
<string>Known materials</string>
</property>
<property name="windowIcon">
<iconset resource="../../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Material:</string>
</property>
</widget>
</item>
<item>
<widget class="VLineEdit" name="lineEditMaterial">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>Name of material</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="toolButtonAdd">
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonRemove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
</layout>
</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>
<customwidgets>
<customwidget>
<class>VLineEdit</class>
<extends>QLineEdit</extends>
<header>vlineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../libs/vmisc/share/resources/icon.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogKnownMaterials</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>DialogKnownMaterials</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

@ -39,6 +39,7 @@
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../core/vapplication.h" #include "../core/vapplication.h"
#include "../vtools/dialogs/support/dialogeditlabel.h" #include "../vtools/dialogs/support/dialogeditlabel.h"
#include "dialogknownmaterials.h"
// calc how many combinations we have // calc how many combinations we have
static const int heightsCount = (static_cast<int>(GHeights::H200) - static const int heightsCount = (static_cast<int>(GHeights::H200) -
@ -181,6 +182,9 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat
connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged);
connect(ui->pushButtonEditPatternLabel, &QPushButton::clicked, this, &DialogPatternProperties::EditLabel); connect(ui->pushButtonEditPatternLabel, &QPushButton::clicked, this, &DialogPatternProperties::EditLabel);
connect(ui->pushButtonKnownMaterials, &QPushButton::clicked, this, &DialogPatternProperties::ManageKnownMaterials);
connect(ui->pushButtonPatternMaterials, &QPushButton::clicked, this,
&DialogPatternProperties::ManagePatternMaterials);
InitComboBoxFormats(ui->comboBoxDateFormat, InitComboBoxFormats(ui->comboBoxDateFormat,
VSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(), VSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(),
@ -900,3 +904,23 @@ void DialogPatternProperties::EditLabel()
templateDataChanged = true; templateDataChanged = true;
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::ManageKnownMaterials()
{
VSettings *settings = qApp->ValentinaSettings();
DialogKnownMaterials editor;
editor.SetList(settings->GetKnownMaterials());
if (QDialog::Accepted == editor.exec())
{
settings->SetKnownMaterials(editor.GetList());
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::ManagePatternMaterials()
{
}

View File

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

View File

@ -21,7 +21,7 @@
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -1239,7 +1239,7 @@
<property name="title"> <property name="title">
<string>Label data</string> <string>Label data</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum> <enum>QFormLayout::ExpandingFieldsGrow</enum>
</property> </property>
@ -1322,6 +1322,65 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Materials</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<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">
<widget class="QPushButton" name="pushButtonPatternMaterials">
<property name="toolTip">
<string>Manage list of pattern materials</string>
</property>
<property name="text">
<string>Manage</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -17,7 +17,8 @@ HEADERS += \
$$PWD/configpages/preferencesconfigurationpage.h \ $$PWD/configpages/preferencesconfigurationpage.h \
$$PWD/configpages/preferencespatternpage.h \ $$PWD/configpages/preferencespatternpage.h \
$$PWD/configpages/preferencespathpage.h \ $$PWD/configpages/preferencespathpage.h \
$$PWD/dialogdatetimeformats.h $$PWD/dialogdatetimeformats.h \
$$PWD/dialogknownmaterials.h
SOURCES += \ SOURCES += \
$$PWD/dialogincrements.cpp \ $$PWD/dialogincrements.cpp \
@ -34,7 +35,8 @@ SOURCES += \
$$PWD/configpages/preferencesconfigurationpage.cpp \ $$PWD/configpages/preferencesconfigurationpage.cpp \
$$PWD/configpages/preferencespatternpage.cpp \ $$PWD/configpages/preferencespatternpage.cpp \
$$PWD/configpages/preferencespathpage.cpp \ $$PWD/configpages/preferencespathpage.cpp \
$$PWD/dialogdatetimeformats.cpp $$PWD/dialogdatetimeformats.cpp \
$$PWD/dialogknownmaterials.cpp
FORMS += \ FORMS += \
$$PWD/dialogincrements.ui \ $$PWD/dialogincrements.ui \
@ -51,4 +53,5 @@ FORMS += \
$$PWD/configpages/preferencesconfigurationpage.ui \ $$PWD/configpages/preferencesconfigurationpage.ui \
$$PWD/configpages/preferencespatternpage.ui \ $$PWD/configpages/preferencespatternpage.ui \
$$PWD/configpages/preferencespathpage.ui \ $$PWD/configpages/preferencespathpage.ui \
$$PWD/dialogdatetimeformats.ui $$PWD/dialogdatetimeformats.ui \
$$PWD/dialogknownmaterials.ui

View File

@ -52,6 +52,7 @@ const QString settingPathsPattern = QStringLiteral("paths/pattern");
const QString settingPathsLayout = QStringLiteral("paths/layout"); const QString settingPathsLayout = QStringLiteral("paths/layout");
const QString settingPatternGraphicalOutput = QStringLiteral("pattern/graphicalOutput"); const QString settingPatternGraphicalOutput = QStringLiteral("pattern/graphicalOutput");
const QString settingPatternKnownMaterials = QStringLiteral("pattern/knownMaterials");
const QString settingCommunityServer = QStringLiteral("community/server"); const QString settingCommunityServer = QStringLiteral("community/server");
const QString settingCommunityServerSecure = QStringLiteral("community/serverSecure"); const QString settingCommunityServerSecure = QStringLiteral("community/serverSecure");
@ -606,3 +607,14 @@ void VSettings::SetTextAsPaths(bool value)
setValue(settingTextAsPaths, value); setValue(settingTextAsPaths, value);
} }
//---------------------------------------------------------------------------------------------------------------------
QStringList VSettings::GetKnownMaterials() const
{
return value(settingPatternKnownMaterials, QStringList()).toStringList();
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetKnownMaterials(const QStringList &list)
{
setValue(settingPatternKnownMaterials, list);
}

View File

@ -155,6 +155,9 @@ public:
static bool GetDefTextAsPaths(); static bool GetDefTextAsPaths();
void SetTextAsPaths(bool value); void SetTextAsPaths(bool value);
QStringList GetKnownMaterials() const;
void SetKnownMaterials(const QStringList &list);
private: private:
Q_DISABLE_COPY(VSettings) Q_DISABLE_COPY(VSettings)
}; };