Dialog Restrict dimension.

This commit is contained in:
Roman Telezhynskyi 2020-10-05 15:14:38 +03:00
parent 0668a99cb5
commit df2f2f7f83
9 changed files with 477 additions and 11 deletions

View file

@ -0,0 +1,50 @@
/************************************************************************
**
** @file dialogrestrictdimension.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 5 10, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 "dialogrestrictdimension.h"
#include "ui_dialogrestrictdimension.h"
//---------------------------------------------------------------------------------------------------------------------
DialogRestrictDimension::DialogRestrictDimension(const QList<MeasurementDimension_p> &dimensions,
const QMap<QString, QPair<int, int>> &restrictions,
bool oneDimesionRestriction, bool fullCircumference,
QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogRestrictDimension),
m_oneDimesionRestriction(oneDimesionRestriction),
m_fullCircumference(fullCircumference),
m_dimensions(dimensions),
m_restrictions(restrictions)
{
ui->setupUi(this);
}
//---------------------------------------------------------------------------------------------------------------------
DialogRestrictDimension::~DialogRestrictDimension()
{
delete ui;
}

View file

@ -0,0 +1,69 @@
/************************************************************************
**
** @file dialogrestrictdimension.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 5 10, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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 DIALOGRESTRICTDIMENSION_H
#define DIALOGRESTRICTDIMENSION_H
#include <QDialog>
#include <QMap>
#include "../vformat/vdimensions.h"
namespace Ui
{
class DialogRestrictDimension;
}
class DialogRestrictDimension : public QDialog
{
Q_OBJECT
public:
DialogRestrictDimension(const QList<MeasurementDimension_p> &dimensions,
const QMap<QString, QPair<int, int>> &restrictions, bool oneDimesionRestriction,
bool fullCircumference, QWidget *parent = nullptr);
virtual ~DialogRestrictDimension();
QMap<QString, QPair<int, int> > Restrictions() const;
private:
Q_DISABLE_COPY(DialogRestrictDimension)
Ui::DialogRestrictDimension *ui;
bool m_oneDimesionRestriction;
bool m_fullCircumference;
QList<MeasurementDimension_p> m_dimensions;
QMap<QString, QPair<int, int>> m_restrictions;
};
//---------------------------------------------------------------------------------------------------------------------
inline QMap<QString, QPair<int, int> > DialogRestrictDimension::Restrictions() const
{
return m_restrictions;
}
#endif // DIALOGRESTRICTDIMENSION_H

View file

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogRestrictDimension</class>
<widget class="QDialog" name="DialogRestrictDimension">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>844</width>
<height>683</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="comboBoxDimensionB"/>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="comboBoxDimensionA"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelDimensioB">
<property name="text">
<string>Dimension B:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<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>
<item row="0" column="1">
<widget class="QLabel" name="labelDimensionA">
<property name="text">
<string>Dimension A:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_4">
<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="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTableWidget" name="tableWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>4</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="QGroupBox" name="groupBoxRestriction">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Restriction</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxMin"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxMax"/>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_6">
<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>
</widget>
</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>DialogRestrictDimension</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>DialogRestrictDimension</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

@ -2,6 +2,7 @@
# This need for corect working file translations.pro
SOURCES += \
$$PWD/dialogs/dialogrestrictdimension.cpp \
$$PWD/main.cpp \
$$PWD/tmainwindow.cpp \
$$PWD/mapplication.cpp \
@ -17,6 +18,7 @@ SOURCES += \
*msvc*:SOURCES += $$PWD/stable.cpp
HEADERS += \
$$PWD/dialogs/dialogrestrictdimension.h \
$$PWD/tmainwindow.h \
$$PWD/stable.h \
$$PWD/mapplication.h \
@ -31,6 +33,7 @@ HEADERS += \
$$PWD/dialogs/dialogsetupmultisize.h
FORMS += \
$$PWD/dialogs/dialogrestrictdimension.ui \
$$PWD/tmainwindow.ui \
$$PWD/dialogs/dialogabouttape.ui \
$$PWD/dialogs/dialognewmeasurements.ui \

View file

@ -33,6 +33,7 @@
#include "dialogs/dialogmdatabase.h"
#include "dialogs/dialogtapepreferences.h"
#include "dialogs/dialogsetupmultisize.h"
#include "dialogs/dialogrestrictdimension.h"
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/calculator.h"
#include "../vpatterndb/pmsystems.h"
@ -2187,6 +2188,44 @@ void TMainWindow::ExportToIndividual()
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::RestrictSecondDimesion()
{
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
const QMap<QString, QPair<int, int>> restrictions = m->GetRestrictions();
bool oneDimesionRestriction = true;
bool fullCircumference = m->IsFullCircumference();
DialogRestrictDimension dialog(dimensions, restrictions, oneDimesionRestriction, fullCircumference, this);
if (dialog.exec() == QDialog::Rejected)
{
return;
}
m->SetRestrictions(dialog.Restrictions());
MeasurementsWereSaved(false);
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::RestrictThirdDimesion()
{
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
const QMap<QString, QPair<int, int>> restrictions = m->GetRestrictions();
bool oneDimesionRestriction = false;
bool fullCircumference = m->IsFullCircumference();
DialogRestrictDimension dialog(dimensions, restrictions, oneDimesionRestriction, fullCircumference, this);
if (dialog.exec() == QDialog::Rejected)
{
return;
}
m->SetRestrictions(dialog.Restrictions());
MeasurementsWereSaved(false);
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetupMenu()
{
@ -2467,6 +2506,26 @@ void TMainWindow::InitMenu()
separator->setSeparator(true);
ui->menuMeasurements->insertAction(ui->actionUseFullCircumference, separator);
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
if (dimensions.size() > 1)
{
ui->actionRestrictSecondDimension->setVisible(true);
ui->actionRestrictSecondDimension->setEnabled(true);
connect(ui->actionRestrictSecondDimension, &QAction::triggered, this, &TMainWindow::RestrictSecondDimesion);
separator = new QAction(this);
separator->setSeparator(true);
ui->menuMeasurements->insertAction(ui->actionRestrictSecondDimension, separator);
if (dimensions.size() > 2)
{
ui->actionRestrictThirdDimension->setVisible(true);
ui->actionRestrictThirdDimension->setEnabled(true);
connect(ui->actionRestrictThirdDimension, &QAction::triggered, this,
&TMainWindow::RestrictThirdDimesion);
}
}
// File
ui->actionExportToIndividual->setVisible(true);
ui->actionExportToIndividual->setEnabled(true);
@ -3995,7 +4054,7 @@ QVector<int> TMainWindow::DimensionRestrictedValues(int index, const Measurement
}
else if (dimension->Type() == MeasurementDimension::Y)
{
const QPair<int, int> restriction = m->OneDimensionRestriction(currentDimensionA);
const QPair<int, int> restriction = m->Restriction(currentDimensionA);
VYMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step());
restricted.SetCircumference(dimension->IsCircumference());
@ -4013,11 +4072,11 @@ QVector<int> TMainWindow::DimensionRestrictedValues(int index, const Measurement
if (index == 1)
{
restriction = m->OneDimensionRestriction(currentDimensionA);
restriction = m->Restriction(currentDimensionA);
}
else
{
restriction = m->TwoDimensionRestriction(currentDimensionA, currentDimensionB);
restriction = m->Restriction(currentDimensionA, currentDimensionB);
}
VWMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step());
@ -4036,11 +4095,11 @@ QVector<int> TMainWindow::DimensionRestrictedValues(int index, const Measurement
if (index == 1)
{
restriction = m->OneDimensionRestriction(currentDimensionA);
restriction = m->Restriction(currentDimensionA);
}
else
{
restriction = m->TwoDimensionRestriction(currentDimensionA, currentDimensionB);
restriction = m->Restriction(currentDimensionA, currentDimensionB);
}
VZMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step());

View file

@ -139,6 +139,9 @@ private slots:
void ExportToIndividual();
void RestrictSecondDimesion();
void RestrictThirdDimesion();
private:
Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui;

View file

@ -993,6 +993,8 @@
<addaction name="actionImportFromPattern"/>
<addaction name="actionMeasurementDiagram"/>
<addaction name="actionUseFullCircumference"/>
<addaction name="actionRestrictSecondDimension"/>
<addaction name="actionRestrictThirdDimension"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuMeasurements"/>
@ -1365,6 +1367,28 @@
<bool>false</bool>
</property>
</action>
<action name="actionRestrictSecondDimension">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Restrict second dimension</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
<action name="actionRestrictThirdDimension">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Restrict third dimension</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View file

@ -71,6 +71,7 @@ const QString VMeasurements::TagMeasurement = QStringLiteral("m");
const QString VMeasurements::TagDimensions = QStringLiteral("dimensions");
const QString VMeasurements::TagDimension = QStringLiteral("dimension");
const QString VMeasurements::TagRestrictions = QStringLiteral("restrictions");
const QString VMeasurements::TagRestriction = QStringLiteral("restriction");
const QString VMeasurements::TagCorrections = QStringLiteral("corrections");
const QString VMeasurements::TagCorrection = QStringLiteral("correction");
@ -853,15 +854,58 @@ QMap<MeasurementDimension, MeasurementDimension_p > VMeasurements::Dimensions()
}
//---------------------------------------------------------------------------------------------------------------------
QPair<int, int> VMeasurements::OneDimensionRestriction(int base) const
QMap<QString, QPair<int, int> > VMeasurements::GetRestrictions() const
{
return QPair<int, int>(0, 0);
QMap<QString, QPair<int, int> > restrictions;
const QDomNodeList list = elementsByTagName(TagRestriction);
for (int i=0; i < list.size(); ++i)
{
const QDomElement res = list.at(i).toElement();
QString coordinates = GetParametrString(res, AttrCoordinates);
const int min = GetParametrInt(res, AttrMin, QChar('0'));
const int max = GetParametrInt(res, AttrMax, QChar('0'));
restrictions.insert(coordinates, qMakePair(min, max));
}
return restrictions;
}
//---------------------------------------------------------------------------------------------------------------------
QPair<int, int> VMeasurements::TwoDimensionRestriction(int base1, int base2) const
void VMeasurements::SetRestrictions(const QMap<QString, QPair<int, int> > &restrictions)
{
return QPair<int, int>(0, 0);
QDomElement root = documentElement();
QDomElement restrictionsTag = root.firstChildElement(TagRestrictions);
if (restrictionsTag.isNull())
{
qDebug() << "Can't find restrictions tag";
}
RemoveAllChildren(restrictionsTag);
QMap<QString, QPair<int, int> >::const_iterator i = restrictions.constBegin();
while (i != restrictions.constEnd())
{
QDomElement restrictionTag = createElement(TagRestriction);
SetAttribute(restrictionTag, AttrCoordinates, i.key());
SetAttribute(restrictionTag, AttrMin, i.value().first);
SetAttribute(restrictionTag, AttrMax, i.value().second);
restrictionsTag.appendChild(restrictionTag);
++i;
}
}
//---------------------------------------------------------------------------------------------------------------------
QPair<int, int> VMeasurements::Restriction(int base, int base2) const
{
const QMap<QString, QPair<int, int> > restrictions = GetRestrictions();
const QString hash = VMeasurement::CorrectionHash(base, base2, 0);
return restrictions.value(hash, QPair<int, int>(0, 0));
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -116,8 +116,10 @@ public:
QMap<MeasurementDimension, MeasurementDimension_p > Dimensions() const;
QPair<int, int> OneDimensionRestriction(int base) const;
QPair<int, int> TwoDimensionRestriction(int base1, int base2) const;
QMap<QString, QPair<int, int> > GetRestrictions() const;
void SetRestrictions(const QMap<QString, QPair<int, int> > &restrictions);
QPair<int, int> Restriction(int base, int base2=0) const;
static const QString TagVST;
static const QString TagVIT;
@ -134,6 +136,7 @@ public:
static const QString TagDimensions;
static const QString TagDimension;
static const QString TagRestrictions;
static const QString TagRestriction;
static const QString TagCorrections;
static const QString TagCorrection;