Fixed issue #18.

--HG--
branch : develop
This commit is contained in:
dismine 2014-02-19 15:32:02 +02:00
parent d5c4c26444
commit 827dc1f77e
11 changed files with 348 additions and 11 deletions

View file

@ -3,7 +3,10 @@
<!-- XML Schema Generated from XML Document-->
<xs:element name="pattern">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="author" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="increments" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">

View file

@ -0,0 +1,114 @@
/************************************************************************
**
** @file dialogpatternproperties.cpp
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 18 2, 2014
**
** @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) 2013 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 "dialogpatternproperties.h"
#include "ui_dialogpatternproperties.h"
#include <QSettings>
DialogPatternProperties::DialogPatternProperties(VDomDocument *doc, QWidget *parent) :
QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc)
{
ui->setupUi(this);
Q_CHECK_PTR(doc);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
#ifdef Q_OS_WIN32
QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString();
#else
QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString();
#endif
ui->lineEditAuthor->setText(this->doc->UniqueTagText("author", user));
ui->plainTextEditDescription->setPlainText(this->doc->UniqueTagText("description"));
ui->plainTextEditTechNotes->setPlainText(this->doc->UniqueTagText("notes"));
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
Q_CHECK_PTR(bOk);
connect(bOk, &QPushButton::clicked, this, &DialogPatternProperties::Apply);
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
Q_CHECK_PTR(bCansel);
connect(bCansel, &QPushButton::clicked, this, &DialogPatternProperties::close);
connect(this, &DialogPatternProperties::haveChange, this->doc, &VDomDocument::haveLiteChange);
}
DialogPatternProperties::~DialogPatternProperties()
{
delete ui;
}
void DialogPatternProperties::Apply()
{
Write("notes", ui->plainTextEditTechNotes->document()->toPlainText());
Write("description", ui->plainTextEditDescription->document()->toPlainText());
Write("author", ui->lineEditAuthor->text());
emit haveChange();
close();
}
void DialogPatternProperties::Write(const QString &tagName, const QString &text) const
{
QDomNodeList nodeList = doc->elementsByTagName(tagName);
if (nodeList.isEmpty())
{
QDomElement pattern = doc->documentElement();
QDomElement tag = doc->createElement(tagName);
QDomText domText = doc->createTextNode(text);
tag.appendChild(domText);
//Old pattern file doesn't have comment. But here we try insert tag after first child (comment).
// <pattern>
// <!--Valentina pattern format.-->
// -->place for new tag<--
// </pattern>
if (pattern.firstChild().isComment())
{
pattern.insertAfter(tag, pattern.firstChild());
}
else
{
pattern.insertBefore(tag, pattern.firstChild());
}
}
else
{
QDomElement oldTag = nodeList.at(0).toElement();
if (oldTag.isElement())
{
QDomElement newTag = doc->createElement(tagName);
QDomText domText = doc->createTextNode(text);
newTag.appendChild(domText);
QDomElement pattern = doc->documentElement();
pattern.replaceChild(newTag, oldTag);
}
}
}

View file

@ -0,0 +1,56 @@
/************************************************************************
**
** @file dialogpatternproperties.h
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 18 2, 2014
**
** @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) 2013 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 DIALOGPATTERNPROPERTIES_H
#define DIALOGPATTERNPROPERTIES_H
#include <QDialog>
#include "../xml/vdomdocument.h"
namespace Ui {
class DialogPatternProperties;
}
class DialogPatternProperties : public QDialog
{
Q_OBJECT
public:
DialogPatternProperties(VDomDocument *doc, QWidget *parent = 0);
virtual ~DialogPatternProperties();
signals:
void haveChange();
public slots:
void Apply();
private:
Q_DISABLE_COPY(DialogPatternProperties)
Ui::DialogPatternProperties *ui;
VDomDocument *doc;
void Write(const QString &tagName, const QString &text) const;
};
#endif // DIALOGPATTERNPROPERTIES_H

View file

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogPatternProperties</class>
<widget class="QDialog" name="DialogPatternProperties">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>646</width>
<height>605</height>
</rect>
</property>
<property name="windowTitle">
<string>Pattern properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Author name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditAuthor"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Pattern description</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEditDescription">
<property name="documentTitle">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>For technical notes.</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEditTechNotes"/>
</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>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogPatternProperties</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>DialogPatternProperties</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

@ -52,5 +52,6 @@
#include "dialogtriangle.h"
#include "dialogpointofintersection.h"
#include "configdialog.h"
#include "dialogpatternproperties.h"
#endif // DIALOGS_H

View file

@ -24,7 +24,8 @@ HEADERS += \
src/dialogs/dialoguniondetails.h \
src/dialogs/dialogcutarc.h \
src/dialogs/configdialog.h \
src/dialogs/pages.h
src/dialogs/pages.h \
src/dialogs/dialogpatternproperties.h
SOURCES += \
src/dialogs/dialogtriangle.cpp \
@ -51,7 +52,8 @@ SOURCES += \
src/dialogs/dialoguniondetails.cpp \
src/dialogs/dialogcutarc.cpp \
src/dialogs/configdialog.cpp \
src/dialogs/pages.cpp
src/dialogs/pages.cpp \
src/dialogs/dialogpatternproperties.cpp
FORMS += \
src/dialogs/dialogtriangle.ui \
@ -75,4 +77,5 @@ FORMS += \
src/dialogs/dialogcutspline.ui \
src/dialogs/dialogcutsplinepath.ui \
src/dialogs/dialoguniondetails.ui \
src/dialogs/dialogcutarc.ui
src/dialogs/dialogcutarc.ui \
src/dialogs/dialogpatternproperties.ui

View file

@ -545,6 +545,12 @@ void MainWindow::OpenRecentFile()
}
}
void MainWindow::PatternProperties()
{
DialogPatternProperties proper(doc, this);
proper.exec();
}
void MainWindow::showEvent( QShowEvent *event )
{
QMainWindow::showEvent( event );
@ -988,6 +994,7 @@ void MainWindow::Clear()
comboBoxDraws->clear();
ui->actionOptionDraw->setEnabled(false);
ui->actionSave->setEnabled(false);
ui->actionPattern_properties->setEnabled(false);
SetEnableTool(false);
}
@ -1402,6 +1409,8 @@ void MainWindow::CreateActions()
connect(ui->actionAbout_Valentina, &QAction::triggered, this, &MainWindow::About);
connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
connect(ui->actionOptions, &QAction::triggered, this, &MainWindow::Options);
connect(ui->actionPattern_properties, &QAction::triggered, this, &MainWindow::PatternProperties);
ui->actionPattern_properties->setEnabled(false);
//Actions for recent files loaded by a main window application.
for (int i = 0; i < MaxRecentFiles; ++i)
@ -1475,6 +1484,7 @@ void MainWindow::LoadPattern(const QString &fileName)
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
ui->actionPattern_properties->setEnabled(true);
}
catch (const VExceptionObjectError &e)
{

View file

@ -362,6 +362,7 @@ public slots:
*/
void tableClosed();
void OpenRecentFile();
void PatternProperties();
signals:
/**
* @brief ModelChosen emit after calculation all details.

View file

@ -302,7 +302,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<width>137</width>
<height>58</height>
</rect>
</property>
@ -378,7 +378,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<width>137</width>
<height>104</height>
</rect>
</property>
@ -579,7 +579,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<width>137</width>
<height>58</height>
</rect>
</property>
@ -695,6 +695,7 @@
<addaction name="actionHistory"/>
<addaction name="actionLayout"/>
<addaction name="separator"/>
<addaction name="actionPattern_properties"/>
<addaction name="actionOptions"/>
</widget>
<addaction name="menuFile"/>
@ -993,6 +994,11 @@
<string>Options...</string>
</property>
</action>
<action name="actionPattern_properties">
<property name="text">
<string>Pattern properties</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>

View file

@ -125,15 +125,25 @@ bool VDomDocument::find(const QDomElement &node, const QString& id)
void VDomDocument::CreateEmptyFile()
{
QDomElement domElement = this->createElement("pattern");
QDomElement patternElement = this->createElement("pattern");
this->appendChild(patternElement);
this->appendChild(domElement);
QDomComment info = this->createComment("Valentina pattern format.");
domElement.appendChild(info);
patternElement.appendChild(info);
QDomNode xmlNode = this->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
this->insertBefore(xmlNode, this->firstChild());
QDomElement authorElement = this->createElement("author");
patternElement.appendChild(authorElement);
QDomElement descElement = this->createElement("description");
patternElement.appendChild(descElement);
QDomElement notesElement = this->createElement("notes");
patternElement.appendChild(notesElement);
QDomElement incrElement = this->createElement("increments");
domElement.appendChild(incrElement);
patternElement.appendChild(incrElement);
}
bool VDomDocument::CheckNameDraw(const QString& name) const
@ -1364,6 +1374,28 @@ void VDomDocument::setPatternModified(bool value)
patternModified = value;
}
QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVal)
{
QDomNodeList nodeList = this->elementsByTagName(tagName);
if (nodeList.isEmpty())
{
return defVal;
}
else
{
QDomNode domNode = nodeList.at(0);
if (domNode.isNull() == false && domNode.isElement())
{
QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
return domElement.text();
}
}
}
return defVal;
}
void VDomDocument::setCursor(const qint64 &value)
{

View file

@ -241,6 +241,7 @@ public:
qint64 SPointActiveDraw();
bool isPatternModified() const;
void setPatternModified(bool value);
QString UniqueTagText(const QString &tagName, const QString &defVal = QString());
signals:
/**
* @brief ChangedActivDraw change active pattern peace.