Dialog DateTimeEditor.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-19 19:10:57 +03:00
parent 260d1cc5e9
commit a8d8efd889
15 changed files with 861 additions and 10 deletions

View File

@ -30,8 +30,27 @@
#include "ui_preferencespatternpage.h"
#include "../../core/vapplication.h"
#include "../ifc/xml/vabstractpattern.h"
#include "../dialogdatetimeformats.h"
#include <QMessageBox>
#include <QDate>
#include <QTime>
namespace
{
QStringList ComboBoxAllStrings(QComboBox *combo)
{
SCASSERT(combo != nullptr)
QStringList itemsInComboBox;
for (int index = 0; index < combo->count(); ++index)
{
itemsInComboBox << combo->itemText(index);
}
return itemsInComboBox;
}
}
//---------------------------------------------------------------------------------------------------------------------
PreferencesPatternPage::PreferencesPatternPage(QWidget *parent)
@ -44,6 +63,7 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent)
ui->undoCount->setValue(qApp->ValentinaSettings()->GetUndoCount());
InitDefaultSeamAllowance();
InitLabelDateTimeFormats();
ui->forbidFlippingCheck->setChecked(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping());
ui->doublePassmarkCheck->setChecked(qApp->ValentinaSettings()->IsDoublePassmark());
@ -77,13 +97,19 @@ void PreferencesPatternPage::Apply()
settings->SetForbidWorkpieceFlipping(ui->forbidFlippingCheck->isChecked());
settings->SetHideMainPath(ui->checkBoxHideMainPath->isChecked());
qApp->ValentinaSettings()->SetLabelFont(ui->fontComboBoxLabelFont->currentFont());
settings->SetLabelFont(ui->fontComboBoxLabelFont->currentFont());
if (settings->IsDoublePassmark() != ui->doublePassmarkCheck->isChecked())
{
settings->SetDoublePassmark(ui->doublePassmarkCheck->isChecked());
qApp->getCurrentDocument()->LiteParseTree(Document::LiteParse);
}
settings->SetLabelDateFormat(ui->comboBoxDateFormats->currentText());
settings->SetLabelTimeFormat(ui->comboBoxTimeFormats->currentText());
settings->SetUserDefinedDateFormats(ComboBoxAllStrings(ui->comboBoxDateFormats));
settings->SetUserDefinedTimeFormats(ComboBoxAllStrings(ui->comboBoxTimeFormats));
}
//---------------------------------------------------------------------------------------------------------------------
@ -92,3 +118,81 @@ void PreferencesPatternPage::InitDefaultSeamAllowance()
ui->defaultSeamAllowance->setValue(qApp->ValentinaSettings()->GetDefaultSeamAllowance());
ui->defaultSeamAllowance->setSuffix(UnitsToStr(StrToUnits(qApp->ValentinaSettings()->GetUnit()), true));
}
//---------------------------------------------------------------------------------------------------------------------
void PreferencesPatternPage::EditDateTimeFormats()
{
VSettings *settings = qApp->ValentinaSettings();
QPushButton *button = qobject_cast<QPushButton *>(sender());
if (button == ui->pushButtonEditDateFormats)
{
CallDateTimeFormatEditor(QDate::currentDate(), settings->PredefinedDateFormats(),
settings->GetUserDefinedDateFormats(), ui->comboBoxDateFormats);
}
else if (button == ui->pushButtonEditTimeFormats)
{
CallDateTimeFormatEditor(QTime::currentTime(), settings->PredefinedTimeFormats(),
settings->GetUserDefinedTimeFormats(), ui->comboBoxTimeFormats);
}
}
//---------------------------------------------------------------------------------------------------------------------
void PreferencesPatternPage::InitLabelDateTimeFormats()
{
VSettings *settings = qApp->ValentinaSettings();
InitComboBoxFormats(ui->comboBoxDateFormats,
VSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(),
settings->GetLabelDateFormat());
InitComboBoxFormats(ui->comboBoxTimeFormats,
VSettings::PredefinedTimeFormats() + settings->GetUserDefinedTimeFormats(),
settings->GetLabelTimeFormat());
connect(ui->pushButtonEditDateFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats);
connect(ui->pushButtonEditTimeFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats);
}
//---------------------------------------------------------------------------------------------------------------------
void PreferencesPatternPage::InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat)
{
SCASSERT(box != nullptr)
box->addItems(items);
int index = box->findText(currentFormat);
if (index != -1)
{
box->setCurrentIndex(index);
}
else
{
box->setCurrentIndex(0);
}
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
void PreferencesPatternPage::CallDateTimeFormatEditor(const T &type, const QStringList &predefinedFormats,
const QStringList &userDefinedFormats, QComboBox *box)
{
SCASSERT(box != nullptr)
DialogDateTimeFormats dialog(type, predefinedFormats, userDefinedFormats);
if (QDialog::Accepted == dialog.exec())
{
const QString currentFormat = box->currentText();
box->clear();
box->addItems(dialog.GetFormats());
int index = box->findText(currentFormat);
if (index != -1)
{
box->setCurrentIndex(index);
}
else
{
box->setCurrentIndex(0);
}
}
}

View File

@ -36,6 +36,8 @@ namespace Ui
class PreferencesPatternPage;
}
class QComboBox;
class PreferencesPatternPage : public QWidget
{
Q_OBJECT
@ -47,9 +49,19 @@ public:
void Apply();
void InitDefaultSeamAllowance();
private slots:
void EditDateTimeFormats();
private:
Q_DISABLE_COPY(PreferencesPatternPage)
Ui::PreferencesPatternPage *ui;
void InitLabelDateTimeFormats();
void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat);
template <typename T>
void CallDateTimeFormatEditor(const T &type, const QStringList &predefinedFormats,
const QStringList &userDefinedFormats, QComboBox *box);
};
#endif // PREFERENCESPATTERNPAGE_H

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>381</width>
<height>513</height>
<height>705</height>
</rect>
</property>
<property name="windowTitle">
@ -160,6 +160,60 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Label data/time format</string>
</property>
<layout class="QFormLayout" name="formLayout_4">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Date:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="comboBoxDateFormats"/>
</item>
<item>
<widget class="QPushButton" name="pushButtonEditDateFormats">
<property name="text">
<string>Edit formats</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="comboBoxTimeFormats"/>
</item>
<item>
<widget class="QPushButton" name="pushButtonEditTimeFormats">
<property name="text">
<string>Edit formats</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@ -0,0 +1,218 @@
/************************************************************************
**
** @file dialogdatetimeformats.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 19 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 "dialogdatetimeformats.h"
#include "ui_dialogdatetimeformats.h"
//---------------------------------------------------------------------------------------------------------------------
DialogDateTimeFormats::DialogDateTimeFormats(const QDate &date, const QStringList &predefinedFormats,
const QStringList &userDefinedFormats, QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogDateTimeFormats),
m_dateMode(true),
m_date(date),
m_time(),
m_predefined(predefinedFormats)
{
ui->setupUi(this);
Init(predefinedFormats, userDefinedFormats);
}
//---------------------------------------------------------------------------------------------------------------------
DialogDateTimeFormats::DialogDateTimeFormats(const QTime &time, const QStringList &predefinedFormats,
const QStringList &userDefinedFormats, QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogDateTimeFormats),
m_dateMode(false),
m_date(),
m_time(time),
m_predefined(predefinedFormats)
{
ui->setupUi(this);
Init(predefinedFormats, userDefinedFormats);
}
//---------------------------------------------------------------------------------------------------------------------
DialogDateTimeFormats::~DialogDateTimeFormats()
{
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList DialogDateTimeFormats::GetFormats() const
{
QStringList formats;
for (int i=0; i<ui->listWidget->count(); ++i)
{
if (const QListWidgetItem *lineItem = ui->listWidget->item(i))
{
const QString format = lineItem->data(Qt::UserRole).toString();
if (not format.isEmpty())
{
formats.append(lineItem->data(Qt::UserRole).toString());
}
}
}
return formats;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDateTimeFormats::AddLine()
{
int row = ui->listWidget->count();
ui->listWidget->insertItem(++row, new QListWidgetItem(tr("<empty>")));
ui->listWidget->setCurrentRow(row);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDateTimeFormats::RemoveLine()
{
ui->listWidget->blockSignals(true);
if (QListWidgetItem *curLine = ui->listWidget->currentItem())
{
if (not m_predefined.contains(curLine->data(Qt::UserRole).toString()))
{
delete ui->listWidget->takeItem(ui->listWidget->currentRow());
}
}
ui->listWidget->blockSignals(false);
ShowFormatDetails();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDateTimeFormats::SaveFormat(const QString &text)
{
if (QListWidgetItem *curLine = ui->listWidget->currentItem())
{
if (not GetFormats().contains(text))
{
const QString preview = m_dateMode ? m_date.toString(text) : m_time.toString(text);
curLine->setText(preview);
curLine->setData(Qt::UserRole, text);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDateTimeFormats::ShowFormatDetails()
{
if (ui->listWidget->count() > 0)
{
if (const QListWidgetItem *line = ui->listWidget->currentItem())
{
ui->lineEditFormat->blockSignals(true);
ui->lineEditFormat->setText(line->data(Qt::UserRole).toString());
ui->lineEditFormat->blockSignals(false);
}
}
SetupControls();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDateTimeFormats::Init(const QStringList &predefined, const QStringList &userDefined)
{
SetFormatLines(predefined, userDefined);
ui->lineEditFormat->setClearButtonEnabled(true);
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogDateTimeFormats::RemoveLine);
connect(ui->toolButtonAdd, &QToolButton::clicked, this, &DialogDateTimeFormats::AddLine);
connect(ui->lineEditFormat, &QLineEdit::textEdited, this, &DialogDateTimeFormats::SaveFormat);
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogDateTimeFormats::ShowFormatDetails);
ui->listWidget->setCurrentRow(0);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDateTimeFormats::SetFormatLines(const QStringList &predefined, const QStringList &userDefined)
{
ui->listWidget->blockSignals(true);
ui->listWidget->clear();
int row = -1;
for (int i=0; i<predefined.size(); ++i)
{
ui->listWidget->insertItem(++row, AddListLine(predefined.at(i)));
}
for (int i=0; i<userDefined.size(); ++i)
{
ui->listWidget->insertItem(++row, AddListLine(userDefined.at(i)));
}
ui->listWidget->blockSignals(false);
if (ui->listWidget->count() > 0)
{
ui->listWidget->setCurrentRow(0);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogDateTimeFormats::SetupControls()
{
const bool enabled = ui->listWidget->count() > 0;
if (not enabled)
{
ui->lineEditFormat->blockSignals(true);
ui->lineEditFormat->clear();
ui->lineEditFormat->blockSignals(false);
}
ui->toolButtonAdd->setEnabled(true);
ui->lineEditFormat->setEnabled(enabled);
const QListWidgetItem *line = ui->listWidget->currentItem();
if (line != nullptr && m_predefined.contains(line->data(Qt::UserRole).toString()))
{
ui->toolButtonRemove->setEnabled(false);
ui->lineEditFormat->setReadOnly(true);
}
else
{
ui->toolButtonRemove->setEnabled(enabled);
ui->lineEditFormat->setReadOnly(false);
}
}
//---------------------------------------------------------------------------------------------------------------------
QListWidgetItem *DialogDateTimeFormats::AddListLine(const QString &format)
{
const QString preview = m_dateMode ? m_date.toString(format) : m_time.toString(format);
QListWidgetItem *item = new QListWidgetItem(preview);
item->setData(Qt::UserRole, format);
return item;
}

View File

@ -0,0 +1,79 @@
/************************************************************************
**
** @file dialogdatetimeformats.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 19 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 DIALOGDATETIMEFORMATS_H
#define DIALOGDATETIMEFORMATS_H
#include <QDialog>
#include <QDate>
#include <QTime>
namespace Ui
{
class DialogDateTimeFormats;
}
class QListWidgetItem;
class DialogDateTimeFormats : public QDialog
{
Q_OBJECT
public:
DialogDateTimeFormats(const QDate &date, const QStringList &predefinedFormats,
const QStringList &userDefinedFormats, QWidget *parent = nullptr);
DialogDateTimeFormats(const QTime &time, const QStringList &predefinedFormats,
const QStringList &userDefinedFormats, QWidget *parent = nullptr);
virtual ~DialogDateTimeFormats();
QStringList GetFormats() const;
private slots:
void AddLine();
void RemoveLine();
void SaveFormat(const QString &text);
void ShowFormatDetails();
private:
Q_DISABLE_COPY(DialogDateTimeFormats)
Ui::DialogDateTimeFormats *ui;
bool m_dateMode;
QDate m_date;
QTime m_time;
QStringList m_predefined;
void Init(const QStringList &predefined, const QStringList &userDefined);
void SetFormatLines(const QStringList &predefined, const QStringList &userDefined);
void SetupControls();
bool IsPredefined() const;
QListWidgetItem *AddListLine(const QString &format);
};
#endif // DIALOGDATETIMEFORMATS_H

View File

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogDateTimeFormats</class>
<widget class="QDialog" name="DialogDateTimeFormats">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>381</height>
</rect>
</property>
<property name="windowTitle">
<string>Label date time editor</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"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Format:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditFormat">
<property name="enabled">
<bool>false</bool>
</property>
<property name="statusTip">
<string/>
</property>
<property name="placeholderText">
<string>Insert a format</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonAdd">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string notr="true">Add</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">Remove</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>
<resources>
<include location="../../../libs/vmisc/share/resources/icon.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogDateTimeFormats</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>DialogDateTimeFormats</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

@ -73,7 +73,8 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat
SCASSERT(doc != nullptr)
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
VSettings *settings = qApp->ValentinaSettings();
settings->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
if (qApp->GetPPath().isEmpty())
{
@ -180,6 +181,18 @@ 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);
InitComboBoxFormats(ui->comboBoxDateFormat,
VSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(),
doc->GetLabelDateFormat());
InitComboBoxFormats(ui->comboBoxTimeFormat,
VSettings::PredefinedTimeFormats() + settings->GetUserDefinedTimeFormats(),
doc->GetLabelTimeFormat());
connect(ui->comboBoxDateFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogPatternProperties::LabelDataChanged);
connect(ui->comboBoxTimeFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogPatternProperties::LabelDataChanged);
}
//---------------------------------------------------------------------------------------------------------------------
@ -497,6 +510,24 @@ void DialogPatternProperties::InitSizes()
Init(ui->checkBoxS72, static_cast<int>(GSizes::S72), &DialogPatternProperties::CheckStateSize);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::InitComboBoxFormats(QComboBox *box, const QStringList &items,
const QString &currentFormat)
{
SCASSERT(box != nullptr)
box->addItems(items);
int index = box->findText(currentFormat);
if (index != -1)
{
box->setCurrentIndex(index);
}
else
{
box->setCurrentIndex(0);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::CheckApplyOk()
{
@ -561,6 +592,8 @@ void DialogPatternProperties::SaveLabelData()
doc->SetPatternNumber(ui->lineEditPatternNumber->text());
doc->SetCompanyName(ui->lineEditCompanyName->text());
doc->SetCustomerName(ui->lineEditCustomerName->text());
doc->SetLabelDateFormat(ui->comboBoxDateFormat->currentText());
doc->SetLabelTimeFormat(ui->comboBoxTimeFormat->currentText());
labelDataChanged = false;
askSaveLabelData = false;

View File

@ -98,6 +98,7 @@ private:
void SetOptions(const QMap<GVal, bool> &option);
template<typename GVal>
void InitComboBox(QComboBox *box, const QMap<GVal, bool> &option);
void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat);
void CheckApplyOk();
void SaveDescription();
void SaveGradation();

View File

@ -1241,7 +1241,7 @@
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
@ -1299,6 +1299,26 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Date format:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBoxDateFormat"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Time format:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="comboBoxTimeFormat"/>
</item>
</layout>
</widget>
</item>

View File

@ -16,7 +16,8 @@ HEADERS += \
$$PWD/dialogpreferences.h \
$$PWD/configpages/preferencesconfigurationpage.h \
$$PWD/configpages/preferencespatternpage.h \
$$PWD/configpages/preferencespathpage.h
$$PWD/configpages/preferencespathpage.h \
$$PWD/dialogdatetimeformats.h
SOURCES += \
$$PWD/dialogincrements.cpp \
@ -32,7 +33,8 @@ SOURCES += \
$$PWD/dialogpreferences.cpp \
$$PWD/configpages/preferencesconfigurationpage.cpp \
$$PWD/configpages/preferencespatternpage.cpp \
$$PWD/configpages/preferencespathpage.cpp
$$PWD/configpages/preferencespathpage.cpp \
$$PWD/dialogdatetimeformats.cpp
FORMS += \
$$PWD/dialogincrements.ui \
@ -48,4 +50,5 @@ FORMS += \
$$PWD/dialogpreferences.ui \
$$PWD/configpages/preferencesconfigurationpage.ui \
$$PWD/configpages/preferencespatternpage.ui \
$$PWD/configpages/preferencespathpage.ui
$$PWD/configpages/preferencespathpage.ui \
$$PWD/dialogdatetimeformats.ui

View File

@ -105,6 +105,8 @@
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="dateFormat" type="xs:string"/>
<xs:attribute name="timeFormat" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="measurements" type="xs:string"/>

View File

@ -51,6 +51,7 @@
#include "vpatternconverter.h"
#include "vdomdocument.h"
#include "vtoolrecord.h"
#include "../vmisc/vabstractapplication.h"
class QDomElement;
@ -99,6 +100,8 @@ const QString VAbstractPattern::AttrType = QStringLiteral("type");
const QString VAbstractPattern::AttrLetter = QStringLiteral("letter");
const QString VAbstractPattern::AttrQuantity = QStringLiteral("quantity");
const QString VAbstractPattern::AttrOnFold = QStringLiteral("onFold");
const QString VAbstractPattern::AttrDateFormat = QStringLiteral("dateFormat");
const QString VAbstractPattern::AttrTimeFormat = QStringLiteral("timeFormat");
const QString VAbstractPattern::AttrArrows = QStringLiteral("arrows");
const QString VAbstractPattern::AttrNodeReverse = QStringLiteral("reverse");
const QString VAbstractPattern::AttrNodeExcluded = QStringLiteral("excluded");
@ -1326,6 +1329,54 @@ void VAbstractPattern::SetCustomerName(const QString& qsName)
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetLabelDateFormat() const
{
QString globalLabelDateFormat = qApp->Settings()->GetLabelDateFormat();
const QDomNodeList list = elementsByTagName(TagPatternLabel);
if (list.isEmpty())
{
return globalLabelDateFormat;
}
QDomElement tag = list.at(0).toElement();
return GetParametrString(tag, AttrDateFormat, globalLabelDateFormat);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetLabelDateFormat(const QString &format)
{
QDomElement tag = CheckTagExists(TagPatternLabel);
SetAttribute(tag, AttrDateFormat, format);
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetLabelTimeFormat() const
{
QString globalLabelTimeFormat = qApp->Settings()->GetLabelTimeFormat();
const QDomNodeList list = elementsByTagName(TagPatternLabel);
if (list.isEmpty())
{
return globalLabelTimeFormat;
}
QDomElement tag = list.at(0).toElement();
return GetParametrString(tag, AttrTimeFormat, globalLabelTimeFormat);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetLabelTimeFormat(const QString &format)
{
QDomElement tag = CheckTagExists(TagPatternLabel);
SetAttribute(tag, AttrTimeFormat, format);
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetPatternLabelTemplate(const QVector<VLabelTemplateLine> &lines)
{
@ -1334,6 +1385,8 @@ void VAbstractPattern::SetPatternLabelTemplate(const QVector<VLabelTemplateLine>
SetLabelTemplate(tag, lines);
patternLabelLines = lines;
patternLabelWasChanged = true;
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -141,13 +141,22 @@ public:
QString GetPatternName() const;
void SetPatternName(const QString& qsName);
QString GetCompanyName() const;
void SetCompanyName(const QString& qsName);
QString GetPatternNumber() const;
void SetPatternNumber(const QString &qsNum);
QString GetCustomerName() const;
void SetCustomerName(const QString& qsName);
QString GetLabelDateFormat() const;
void SetLabelDateFormat(const QString &format);
QString GetLabelTimeFormat() const;
void SetLabelTimeFormat(const QString &format);
void SetPatternLabelTemplate(const QVector<VLabelTemplateLine> &lines);
QVector<VLabelTemplateLine> GetPatternLabelTemplate() const;
@ -221,6 +230,8 @@ public:
static const QString AttrLetter;
static const QString AttrQuantity;
static const QString AttrOnFold;
static const QString AttrDateFormat;
static const QString AttrTimeFormat;
static const QString AttrArrows;
static const QString AttrNodeReverse;
static const QString AttrNodeExcluded;

View File

@ -45,6 +45,8 @@
#include "../vmisc/vmath.h"
#include "../vpatterndb/pmsystems.h"
namespace
{
const QString settingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements");
const QString settingPathsMultisizeMeasurements = QStringLiteral("paths/standard_measurements");
const QString settingPathsTemplates = QStringLiteral("paths/templates");
@ -67,7 +69,7 @@ const QString settingPatternForbidFlipping = QStringLiteral("pattern/fo
const QString settingPatternHideMainPath = QStringLiteral("pattern/hideMainPath");
const QString settingDoublePassmark = QStringLiteral("pattern/doublePassmark");
const QString settingPatternDefaultSeamAllowance = QStringLiteral("pattern/defaultSeamAllowance");
const QString settingLabelFont = QStringLiteral("pattern/labelFont");
const QString settingPatternLabelFont = QStringLiteral("pattern/labelFont");
const QString settingGeneralRecentFileList = QStringLiteral("recentFileList");
const QString settingGeneralRestoreFileList = QStringLiteral("restoreFileList");
@ -85,6 +87,22 @@ const QString settingCSVWithHeader = QStringLiteral("csv/withHeader");
const QString settingCSVCodec = QStringLiteral("csv/withCodec");
const QString settingCSVSeparator = QStringLiteral("csv/withSeparator");
const QString settingLabelDateFormat = QStringLiteral("label/dateFormat");
const QString settingLabelUserDateFormats = QStringLiteral("label/userDateFormats");
const QString settingLabelTimeFormat = QStringLiteral("label/timeFormat");
const QString settingLabelUserTimeFormats = QStringLiteral("label/userTimeFormats");
//---------------------------------------------------------------------------------------------------------------------
QStringList ClearFormats(const QStringList &predefinedFormats, QStringList formats)
{
for (int i = 0; i < predefinedFormats.size(); ++i)
{
formats.removeAll(predefinedFormats.at(i));
}
return formats;
}
}
static const QString commonIniFilename = QStringLiteral("common");
#if !defined(Q_OS_WIN)
@ -825,11 +843,115 @@ double VCommonSettings::GetDefaultSeamAllowance()
//---------------------------------------------------------------------------------------------------------------------
QFont VCommonSettings::GetLabelFont() const
{
return qvariant_cast<QFont>(value(settingLabelFont, QApplication::font()));
return qvariant_cast<QFont>(value(settingPatternLabelFont, QApplication::font()));
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelFont(const QFont &f)
{
setValue(settingLabelFont, f);
setValue(settingPatternLabelFont, f);
}
//---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::GetLabelDateFormat() const
{
const QString format = value(settingLabelDateFormat, VCommonSettings::PredefinedDateFormats().first()).toString();
const QStringList allFormats = VCommonSettings::PredefinedDateFormats() + GetUserDefinedDateFormats();
if (allFormats.contains(format))
{
return format;
}
else
{
return VCommonSettings::PredefinedDateFormats().first();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelDateFormat(const QString &format)
{
setValue(settingLabelDateFormat, format);
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VCommonSettings::PredefinedDateFormats()
{
QStringList formats = QStringList() << "MM-dd-yyyy"
<< "d/M/yy"
<< "ddddMMMM dd, yyyy"
<< "dd/MM/yy"
<< "dd/MM/yyyy"
<< "MMM d, yy"
<< "MMM d, yyyy"
<< "d. MMM. yyyy"
<< "MMMM d, yyyy"
<< "d. MMMM yyyy"
<< "ddd, MMM d, yy"
<< "ddd dd/MMM yy"
<< "ddd, MMMM d, yyyy"
<< "ddddMMMM d, yyyy"
<< "MM-dd"
<< "yy-MM-dd"
<< "yyyy-MM-dd"
<< "MM/yy"
<< "MMM dd"
<< "MMMM";
return formats;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VCommonSettings::GetUserDefinedDateFormats() const
{
return value(settingLabelUserDateFormats, QStringList()).toStringList();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetUserDefinedDateFormats(const QStringList &formats)
{
setValue(settingLabelUserDateFormats, ClearFormats(VCommonSettings::PredefinedDateFormats(), formats));
}
//---------------------------------------------------------------------------------------------------------------------
QString VCommonSettings::GetLabelTimeFormat() const
{
const QString format = value(settingLabelTimeFormat, VCommonSettings::PredefinedTimeFormats().first()).toString();
const QStringList allFormats = VCommonSettings::PredefinedTimeFormats() + GetUserDefinedTimeFormats();
if (allFormats.contains(format))
{
return format;
}
else
{
return VCommonSettings::PredefinedTimeFormats().first();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelTimeFormat(const QString &format)
{
setValue(settingLabelTimeFormat, format);
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VCommonSettings::PredefinedTimeFormats()
{
QStringList formats = QStringList() << "hh:mm:ss"
<< "hh:mm:ss AP"
<< "hh:mm"
<< "hh:mm AP";
return formats;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VCommonSettings::GetUserDefinedTimeFormats() const
{
return value(settingLabelUserTimeFormats, QStringList()).toStringList();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetUserDefinedTimeFormats(const QStringList &formats)
{
setValue(settingLabelUserTimeFormats, ClearFormats(VCommonSettings::PredefinedTimeFormats(), formats));
}

View File

@ -170,6 +170,20 @@ public:
static const QString unixStandardSharePath;
#endif
QString GetLabelDateFormat() const;
void SetLabelDateFormat(const QString &format);
static QStringList PredefinedDateFormats();
QStringList GetUserDefinedDateFormats() const;
void SetUserDefinedDateFormats(const QStringList &formats);
QString GetLabelTimeFormat() const;
void SetLabelTimeFormat(const QString &format);
static QStringList PredefinedTimeFormats();
QStringList GetUserDefinedTimeFormats() const;
void SetUserDefinedTimeFormats(const QStringList &formats);
private:
Q_DISABLE_COPY(VCommonSettings)
};