diff --git a/AUTHORS b/AUTHORS index 4fdcd9dc8..dd931a02f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,6 @@ Our Team: (*) Christine Neupert Testing, translation. + (*) Patrick Proy + Developing. + diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index cc62e1a08..9e933ef4c 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -93,7 +93,7 @@ void VContainer::setData(const VContainer &data) qDeleteAll(gObjects); gObjects.clear(); const QHash *obj = data.DataGObjects(); - Q_CHECK_PTR(obj); + SCASSERT(obj != nullptr); QHashIterator i(*obj); while (i.hasNext()) { @@ -331,7 +331,7 @@ template void VContainer::UpdateObject(QHash &obj, const quint32 &id, val point) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(point); + SCASSERT(point != nullptr); point->setId(id); if (gObjects.contains(id)) { @@ -542,7 +542,7 @@ void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPoint template quint32 VContainer::AddObject(QHash &obj, val value) { - Q_CHECK_PTR(value); + SCASSERT(value != nullptr); quint32 id = getNextId(); value->setId(id); obj[id] = value; diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 9855e9be5..fd9652895 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -70,7 +70,7 @@ public: try { T obj = dynamic_cast(gObj); - Q_CHECK_PTR(obj); + SCASSERT(obj != nullptr); return obj; } catch (const std::bad_alloc &) diff --git a/src/app/dialogs/app/dialogaboutapp.cpp b/src/app/dialogs/app/dialogaboutapp.cpp index aa9b69050..614f49efa 100644 --- a/src/app/dialogs/app/dialogaboutapp.cpp +++ b/src/app/dialogs/app/dialogaboutapp.cpp @@ -65,7 +65,7 @@ DialogAboutApp::~DialogAboutApp() */ void DialogAboutApp::webButtonClicked() { - if ( ! QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR))) + if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false) { QMessageBox::warning(this, tr("Warning"), tr("Cannot open your default browser")); } diff --git a/src/app/dialogs/app/dialogaboutapp.h b/src/app/dialogs/app/dialogaboutapp.h index f9b98e1cf..66d10afe5 100644 --- a/src/app/dialogs/app/dialogaboutapp.h +++ b/src/app/dialogs/app/dialogaboutapp.h @@ -31,8 +31,9 @@ #include -namespace Ui { -class DialogAboutApp; +namespace Ui +{ + class DialogAboutApp; } class DialogAboutApp : public QDialog diff --git a/src/app/dialogs/app/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index 15c4d68ff..5e08a6e41 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -152,7 +152,7 @@ void DialogHistory::FillTable() { ui->tableWidget->clear(); const QVector *history = doc->getHistory(); - Q_CHECK_PTR(history); + SCASSERT(history != nullptr); qint32 currentRow = -1; qint32 count = 0; ui->tableWidget->setRowCount(history->size()); @@ -187,7 +187,7 @@ void DialogHistory::FillTable() { cursorRow = currentRow; QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); item->setIcon(QIcon("://icon/32x32/put_after.png")); } ui->tableWidget->resizeColumnsToContents(); @@ -289,7 +289,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Valentina::SplineTool: { const VSpline *spl = data->GeometricObject(tool.getId()); - Q_CHECK_PTR(spl); + SCASSERT(spl != nullptr); const QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); const QString splP4Name = data->GeometricObject(spl->GetP4().id())->name(); return QString(tr("Curve %1_%2")).arg(splP1Name, splP4Name); @@ -297,14 +297,14 @@ QString DialogHistory::Record(const VToolRecord &tool) case Valentina::ArcTool: { const VArc *arc = data->GeometricObject(tool.getId()); - Q_CHECK_PTR(arc); + SCASSERT(arc != nullptr); const QString arcCenterName = data->GeometricObject(arc->GetCenter().id())->name(); return QString(tr("Arc with center in point %1")).arg(arcCenterName); } case Valentina::SplinePathTool: { const VSplinePath *splPath = data->GeometricObject(tool.getId()); - Q_CHECK_PTR(splPath); + SCASSERT(splPath != nullptr); const QVector points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) @@ -375,7 +375,7 @@ QString DialogHistory::Record(const VToolRecord &tool) { const quint32 arcId = doc->GetParametrUInt(domElement, VToolCutArc::AttrArc, "0"); const VArc *arc = data->GeometricObject(arcId); - Q_CHECK_PTR(arc); + SCASSERT(arc != nullptr); const QString arcCenterName = data->GeometricObject(arc->GetCenter().id())->name(); const QString toolIdName = data->GeometricObject(tool.getId())->name(); return QString(tr("%1 - cut arc with center %2")).arg(toolIdName, arcCenterName); @@ -384,7 +384,7 @@ QString DialogHistory::Record(const VToolRecord &tool) { const quint32 splineId = doc->GetParametrUInt(domElement, VToolCutSpline::AttrSpline, "0"); const VSpline *spl = data->GeometricObject(splineId); - Q_CHECK_PTR(spl); + SCASSERT(spl != nullptr); const QString toolIdName = data->GeometricObject(tool.getId())->name(); const QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); const QString splP4Name = data->GeometricObject(spl->GetP4().id())->name(); @@ -394,7 +394,7 @@ QString DialogHistory::Record(const VToolRecord &tool) { const quint32 splinePathId = doc->GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, "0"); const VSplinePath *splPath = data->GeometricObject(splinePathId); - Q_CHECK_PTR(splPath); + SCASSERT(splPath != nullptr); const QVector points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) diff --git a/src/app/dialogs/app/dialoghistory.h b/src/app/dialogs/app/dialoghistory.h index 08ab4208f..499da0556 100644 --- a/src/app/dialogs/app/dialoghistory.h +++ b/src/app/dialogs/app/dialoghistory.h @@ -50,6 +50,10 @@ public: virtual ~DialogHistory(); public slots: virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} void cellClicked(int row, int column); void ChangedCursor(quint32 id); void UpdateHistory(); diff --git a/src/app/dialogs/app/dialogincrements.h b/src/app/dialogs/app/dialogincrements.h index 2b4d18e03..244b6e8a7 100644 --- a/src/app/dialogs/app/dialogincrements.h +++ b/src/app/dialogs/app/dialogincrements.h @@ -49,6 +49,10 @@ public: DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent = nullptr); ~DialogIncrements(); public slots: + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} void clickedToolButtonAdd(); void clickedToolButtonRemove(); void IncrementChanged ( qint32 row, qint32 column ); diff --git a/src/app/dialogs/app/dialogindividualmeasurements.cpp b/src/app/dialogs/app/dialogindividualmeasurements.cpp index affede943..0f1870c14 100644 --- a/src/app/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/app/dialogs/app/dialogindividualmeasurements.cpp @@ -44,12 +44,12 @@ DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, con { const QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); connect(bOk, &QPushButton::clicked, this, &DialogIndividualMeasurements::DialogAccepted); } { const QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - Q_CHECK_PTR(bCansel); + SCASSERT(bCansel != nullptr); connect(bCansel, &QPushButton::clicked, this, &DialogIndividualMeasurements::DialogRejected); } @@ -174,7 +174,7 @@ void DialogIndividualMeasurements::CheckState() QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagName && flagPath); } diff --git a/src/app/dialogs/app/dialogpatternproperties.cpp b/src/app/dialogs/app/dialogpatternproperties.cpp index 10a7a0ccc..39b7e1f4e 100644 --- a/src/app/dialogs/app/dialogpatternproperties.cpp +++ b/src/app/dialogs/app/dialogpatternproperties.cpp @@ -37,7 +37,7 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) { ui->setupUi(this); - Q_CHECK_PTR(doc); + SCASSERT(doc != nullptr); QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()); @@ -52,11 +52,11 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) ui->plainTextEditTechNotes->setPlainText(this->doc->UniqueTagText("notes")); QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); connect(bOk, &QPushButton::clicked, this, &DialogPatternProperties::Apply); QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - Q_CHECK_PTR(bCansel); + SCASSERT(bCansel != nullptr); connect(bCansel, &QPushButton::clicked, this, &DialogPatternProperties::close); connect(this, &DialogPatternProperties::haveChange, this->doc, &VPattern::haveLiteChange); diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp new file mode 100644 index 000000000..cc1e92174 --- /dev/null +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -0,0 +1,1259 @@ +/************************************************************************ + ** + ** @file dialogpatternxmledit.cpp + ** @author Patrick Proy + ** @date 14 5, 2014 + ** + ** @brief Code file for the XML editor dialog + ** @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 + ** 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 . + ** + *************************************************************************/ + +#include "dialogpatternxmledit.h" +#include "ui_dialogpatternxmledit.h" + +#include + +const short int DialogPatternXmlEdit::ChangeTypeDelete=1; +const short int DialogPatternXmlEdit::ChangeTypeAdd=2; +const short int DialogPatternXmlEdit::ChangeTypeModify=3; + + +//--------------------------------------------------------------------------------------------------------------------- +DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) + :QDialog(parent), treeChange(false), currentNodeEdited(nullptr), currentNodeEditedStatus(0), + currentNodeEditedStack(nullptr), ui(new Ui::DialogPatternXmlEdit), doc(nullptr), root(QDomElement()), + rootNode(nullptr), rootBases(nullptr), rootBasesNum(0), xmlmodel(nullptr), changeStackRoot(nullptr), + changeStackLast(nullptr) +{ + ui->setupUi(this); + + this->xmlmodel = new VXMLTreeView(); + this->doc=xmldoc; + this->root = this->doc->documentElement(); + // disable edit trigers (no edition directly on tree) + ui->treeView_main->setEditTriggers(QTreeView::NoEditTriggers); + + ui->treeView_main->setWindowTitle("XML"); + + this->rootNode = this->xmlmodel->invisibleRootItem(); + + int drawnum=xmldoc->elementsByTagName("draw").size(); + this->rootBases = new VXMLTreeElement*[drawnum+1]; + this->rootBasesNum=1; + this->rootBases[0]=new VXMLTreeElement("Valentina", VXMLTreeElement::TypeRoot, root, false); + // TODO : OOM exception. + + + VXMLTreeElement* standard_base = new VXMLTreeElement("Valentina", VXMLTreeElement::TypeRoot, root, false); + ui->comboBox_Base_Selection->addItem(tr("All pattern pieces"), QVariant(0)); + + //rootBases[0]=(QDomNode) doc->DocumentNode; + this->rootNode->appendRow(standard_base); + + this->ReadNodes(this->root, standard_base, this->xmlmodel, false); + + ui->treeView_main->setModel(xmlmodel); + + //ui->treeView_main->expandAll(); + + // connectors + connect(ui->comboBox_Base_Selection, static_cast(&QComboBox::currentIndexChanged), + this, &DialogPatternXmlEdit::BaseSelectionChanged); + connect(ui->treeView_main, &QTreeView::clicked, this, &DialogPatternXmlEdit::ElementClicked); + connect(ui->lineEdit_Name, &QLineEdit::textEdited, this, &DialogPatternXmlEdit::NameTextEdited); + connect(ui->lineEdit_Value, &QLineEdit::textEdited, this, &DialogPatternXmlEdit::ValueTextEdited); + connect(ui->pushButton_Set_Values, &QPushButton::clicked, this, &DialogPatternXmlEdit::ButtonSetClicked); + connect(ui->pushButton_Cancel_Values, &QPushButton::clicked, this, &DialogPatternXmlEdit::ButtonCancelClicked); + connect(ui->pushButton_Remove_attribute, &QPushButton::clicked, + this, &DialogPatternXmlEdit::ButtonDeleteAttributeClicked); + connect(ui->pushButton_Add_son, &QPushButton::clicked, this, &DialogPatternXmlEdit::ButtonAddSonClicked); + connect(ui->pushButton_Add_attribute, &QPushButton::clicked, + this, &DialogPatternXmlEdit::ButtonAddAttributeClicked); + connect(ui->pushButton_Apply_Changes, &QPushButton::clicked, + this, &DialogPatternXmlEdit::ButtonApplyChangesClicked); + connect(ui->pushButton_Undo_Last_Change, &QPushButton::clicked, this, &DialogPatternXmlEdit::ButtonUndoLastChange); + connect(ui->pushButton_Remove_Node, &QPushButton::clicked, this, &DialogPatternXmlEdit::ButtonDeleteNode); +} + +bool DialogPatternXmlEdit::CheckChanges(QString &message, QDomNode testRoot) +{ + message="OK"; + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogPatternXmlEdit::ApplyAttributeChange(QDomNode domElement, QString name, QString value) +{ + if (domElement.isElement() == false) + { + return false; + } + domElement.toElement().setAttribute(name,value); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogPatternXmlEdit::ApplyNodeChange(QDomNode domElement, QString name, QString value) +{ + if (domElement.isElement() == false) + { + return false; + } + domElement.toElement().setNodeValue(value); + domElement.toElement().setTagName(name); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogPatternXmlEdit::ApplyNodeAdd(QDomNode domElement, VXMLTreeElement* treeElement, QString name, QString value) +{ + QDomElement newnode = domElement.ownerDocument().createElement(name); + //Q_ASSERT(newnode != nullptr); + newnode.setNodeValue(value); + domElement.appendChild(newnode); + treeElement->SetDocNode(newnode); + return true; +} + +bool DialogPatternXmlEdit::ApplyAttributeDelete(QDomNode domElement, QString name) +{ + if (domElement.isElement() == false) + { + return false; + } + domElement.toElement().removeAttribute(name); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogPatternXmlEdit::ApplyNodeDelete(QDomNode domElement) +{ + QDomNode mother=domElement.parentNode(); + mother.removeChild(domElement); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonDeleteNode() +{ + ChangesStackElement* newstack; + + // TODO : maybe assert functions here + if (this->currentNodeEdited == nullptr) + { + return; + } + if (this->currentNodeEdited->GetelementType() != VXMLTreeElement::TypeNode) + { + return; + } + + if (this->currentNodeEditedStatus != 0) + { + if (this->currentNodeEditedStatus == DialogPatternXmlEdit::ChangeTypeDelete) + { // Change already done ??? ignore... + return; + } + if (this->currentNodeEditedStatus == DialogPatternXmlEdit::ChangeTypeAdd) + { // Attribute was previously added, just undo the change + if ( this->UndoChange(this->currentNodeEditedStack) == false ) + { // Error in undo... warn user + QMessageBox::warning(this, tr("No changes"), tr("Cannot delete previously created node")); + return; + } + this->ClearEditData(); + return; + } + if (this->currentNodeEditedStatus == DialogPatternXmlEdit::ChangeTypeModify) + { // Node was edited : remove change then continue to delete node + this->UndoChange(this->currentNodeEditedStack); + } + } + + // Modify display + QFont textfont=currentNodeEdited->font(); + textfont.setStrikeOut(true); + this->currentNodeEdited->setFont(textfont); + // + this->DeleteNodeAndSons(this->currentNodeEdited, true); + // Create change + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeDelete); + newstack->element= this->currentNodeEdited; + // Activate changes + this->treeChange=true; + ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); + // clear dialog + this->ClearEditData(); + return; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogPatternXmlEdit::DeleteNodeAndSons(VXMLTreeElement * currentNode, bool onlydeactivate) +{ + + QList stack; + VXMLTreeElement * currentNodeStack; + // First undo all changes on sons + stack << currentNode; + while (stack.isEmpty() == false) + { + //pop first element + currentNodeStack=stack.takeFirst(); + // clear all changes made in son node and not on current or it will loop + if (currentNodeStack != currentNode) + { + ChangesStackElement * local = this->changeStackRoot; + while (local != nullptr) + { + if (local->element == currentNodeStack) + { + this->UndoChange(local); + break; + } + local=local->next; + } + } + // add sons to stack + int index=currentNodeStack->rowCount(); + while (index > 0) + { + stack << static_cast (currentNodeStack->child(index-1)); + index--; + } + //stack.removeFirst(); + } + // Next set strike font on all + if (onlydeactivate==true) + { + stack << currentNode; + while (stack.isEmpty() == false) + { + //pop first element + currentNodeStack=stack.takeFirst(); + + currentNodeStack->SetSetlectable(false); + QFont textfont=currentNodeStack->font(); + textfont.setStrikeOut(true); + currentNodeStack->setFont(textfont); + // add sons to stack + int index=currentNodeStack->rowCount(); + while (index > 0) + { + stack << static_cast (currentNodeStack->child(index-1)); + index--; + } + } + } + + currentNode->SetSetlectable(true); + + if (onlydeactivate==false) + { // Remove node from parent + // Get parent node + QStandardItem * parent= currentNode->parent(); + int index=parent->rowCount(); + while (index >= 0) + { + if (static_cast (parent->child(index)) == currentNode) + { + break; + } + index--; + } + if (index < 0) + { + Q_ASSERT(index==0); + return false; + } + parent->removeRow(index); + } + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElement(short int typechange) +{ + ChangesStackElement* tmp; + + tmp= new ChangesStackElement; + //if (tmp==0) TODO + tmp->type=typechange; + tmp->changedText=tmp->changedValue=false; + + if (changeStackLast==nullptr ) + { + changeStackLast=changeStackRoot=tmp; + } + else + { + changeStackLast->next=tmp; + changeStackLast=changeStackLast->next; + } + changeStackLast->newValue=changeStackLast->newText=nullptr; + changeStackLast->oldValue=changeStackLast->oldText=nullptr; + changeStackLast->next=nullptr; + return changeStackLast; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogPatternXmlEdit::UndoChange(DialogPatternXmlEdit::ChangesStackElement* current) +{ + Q_ASSERT(current != nullptr); + + VXMLTreeElement * currentNode = current->element; + + if (current->type == DialogPatternXmlEdit::ChangeTypeDelete) + { + if (currentNode->GetelementType()==VXMLTreeElement::TypeAttr) + { + // Attribute previously deleted -> restore + QFont textfont=currentNode->font(); + textfont.setStrikeOut(false); + currentNode->setFont(textfont); + this->RemoveChangeStackElement(current); + } + else if (currentNode->GetelementType()==VXMLTreeElement::TypeNode) + { + QList stack; + stack << currentNode; + while (stack.isEmpty() == false) + { + currentNode=stack.takeFirst(); + currentNode->SetSetlectable(true); + QFont textfont=currentNode->font(); + textfont.setStrikeOut(false); + currentNode->setFont(textfont); + + int index=currentNode->rowCount(); + while (index > 0) + { + stack << static_cast (currentNode->child(index-1)); + index--; + } + } + this->RemoveChangeStackElement(current); + } + } + else if (current->type == DialogPatternXmlEdit::ChangeTypeAdd) + { + if (currentNode->GetelementType()==VXMLTreeElement::TypeAttr) + { + // Get parent node + VXMLTreeElement * parent= static_cast (currentNode->parent()); + int index=parent->rowCount(); + while (index >= 0) + { + if (static_cast (parent->child(index)) == currentNode) + { + break; + } + index--; + } + if (index < 0) + { + Q_ASSERT(index==0); + return false; + } + parent->removeRow(index); + this->RemoveChangeStackElement(current); + } + else if (currentNode->GetelementType()==VXMLTreeElement::TypeNode) + { + if (this->DeleteNodeAndSons(currentNode, false) == false) + { + // TODO : error message. + return false; + } + this->RemoveChangeStackElement(current); + } + } + else if (current->type == DialogPatternXmlEdit::ChangeTypeModify) + { + if (current->changedText == true) + { + currentNode->SetTreeNodeName(*current->oldText); + } + if (current->changedValue == true) + { + currentNode->SetTreeNodeValue(*current->oldValue); + } + + QFont textfont=currentNode->font(); + textfont.setBold(false); + currentNode->setFont(textfont); + this->RemoveChangeStackElement(current); + } + // Check if last change was undone + if (this->changeStackLast == nullptr) + { + this->treeChange=false; + ui->pushButton_Apply_Changes->setEnabled(false); + ui->pushButton_Undo_Last_Change->setEnabled(false); + } + return true; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonUndoLastChange() +{ + ChangesStackElement* current=this->changeStackLast; + + if (current == nullptr) + { + QMessageBox::warning(this, tr("No changes"), tr("No changes left")); + this->ui->pushButton_Undo_Last_Change->setEnabled(false); + return; + } + if (this->UndoChange(current) == false) + { + QMessageBox::warning(this, tr("No changes"), tr("Cannot undo change")); + } + this->ClearEditData(); + +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonApplyChangesClicked() +{ + QString Changes=""; + QStringList stringtype; + stringtype << "node" << "attribute" << "root"; + QString nodetype; + ChangesStackElement* currentChange; + if (this->changeStackRoot==nullptr) + { + Changes="No Changes"; + } + else + { + currentChange=this->changeStackRoot; + do + { + nodetype=stringtype.at(currentChange->element->GetelementType()-1); + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) + { + Changes += QString("Added type %1 : ").arg(nodetype); + Changes += currentChange->element->GettreeNodeName(); + Changes += "/"; + Changes += (currentChange->element->GettreeNodeValueSet()) ? + currentChange->element->GettreeNodeValue(): QString(tr("")); + Changes += "\n"; + } + else + { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeModify) + { + Changes += QString("Modified type %1 : ").arg(nodetype); + Changes += (currentChange->changedText) ? *currentChange->newText : QString(tr("Unchanged")); + Changes += "/"; + Changes += (currentChange->changedValue) ? *currentChange->newValue: QString(tr("Unchanged")); + Changes += "\n"; + } + else + { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeDelete) + { + Changes += QString("Deleted type %1 : ").arg(nodetype); + Changes += currentChange->element->GettreeNodeName(); + Changes += "/"; + Changes += (currentChange->element->GettreeNodeValueSet()) ? + currentChange->element->GettreeNodeValue(): QString(tr("")); + Changes += "\n"; + } + } + } + currentChange=currentChange->next; + } while (currentChange != nullptr); + } + QMessageBox::information(this, "Changes (not REALLY applied for now)", Changes); + // TODO : clear stack and apply + + currentChange=this->changeStackRoot; + // copy DOM + QDomNode newroot = root.cloneNode(true); + + QString name, value; + while (currentChange != nullptr) + { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeModify) + { + name=(currentChange->changedText == false) ? currentChange->element->GettreeNodeName() + : *currentChange->newText; + value=(currentChange->changedValue == false) ? currentChange->element->GettreeNodeValue() + : *currentChange->newValue; + if (currentChange->element->GetelementType() == VXMLTreeElement::TypeAttr) + { + + this->ApplyAttributeChange(currentChange->element->GetDocNode(), name, value); + } + else if (currentChange->element->GetelementType() == VXMLTreeElement::TypeNode) + { + this->ApplyNodeChange(currentChange->element->GetDocNode(), name, value); + } + else + { + QMessageBox::warning(this, "Error in changes", "Invalid node type"); + return; + } + } + else if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) + { + name=(currentChange->changedText == false) ? currentChange->element->GettreeNodeName() + : *currentChange->newText; + value=(currentChange->changedValue == false) ? currentChange->element->GettreeNodeValue() + : *currentChange->newValue; + if (currentChange->element->GetelementType() == VXMLTreeElement::TypeAttr) + { + this->ApplyAttributeChange(currentChange->element->GetFatherElement()->GetDocNode(), name, value); + } + else if (currentChange->element->GetelementType() == VXMLTreeElement::TypeNode) + { + this->ApplyNodeAdd(currentChange->element->GetFatherElement()->GetDocNode(), currentChange->element, + name, value); + } + else + { + QMessageBox::warning(this, "Error in changes", "Invalid node type"); + return; + } + } + else if (currentChange->type == DialogPatternXmlEdit::ChangeTypeDelete) + { + if (currentChange->element->GetelementType() == VXMLTreeElement::TypeAttr) + { + name=(currentChange->changedText == false) ? currentChange->element->GettreeNodeName() + : *currentChange->newText; + this->ApplyAttributeDelete(currentChange->element->GetDocNode(), name); + } + else if (currentChange->element->GetelementType() == VXMLTreeElement::TypeNode) + { + this->ApplyNodeDelete(currentChange->element->GetDocNode().parentNode()); + } + else + { + QMessageBox::warning(this, "Error in changes", "Invalid node type"); + return; + } + } + currentChange=currentChange->next; + } + QString message; + if (this->CheckChanges(message,newroot) == false) + { + QMessageBox::warning(this, "Error in changes", message); + return; + } + this->doc->LiteParseTree(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonCancelClicked() +{ + this->ClearEditData(); + if (this->currentNodeEditedStatus==DialogPatternXmlEdit::ChangeTypeDelete) + { + if (this->UndoChange(this->currentNodeEditedStack) == false) + { + QMessageBox::warning(this, "Error", "Cannot undo"); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) +{ + ChangesStackElement* index = this->changeStackRoot; + + if (changeStackRoot == elmt) + { + if (elmt->newText != nullptr) + { + delete elmt->newText; + } + if (elmt->newValue != nullptr) + { + delete elmt->newValue; + } + if (elmt->oldText != nullptr) + { + delete elmt->oldText; + } + if (elmt->oldValue != nullptr) + { + delete elmt->oldValue; + } + this->changeStackRoot = elmt->next; + if (this->changeStackLast == elmt) + { + this->changeStackLast= elmt->next; + } + delete elmt; + return; + } + while (index->next!=nullptr) + { + if (index->next == elmt) + { + break; + } + index=index->next; + } + if (index->next == nullptr) + { + Q_ASSERT(index->next != nullptr); + return; + } + if (index->next->newText != nullptr) + { + delete index->next->newText; + } + if (index->next->newValue != nullptr) + { + delete index->next->newValue; + } + if (index->next->oldText != nullptr) + { + delete index->next->oldText; + } + if (index->next->oldValue != nullptr) + { + delete index->next->oldValue; + } + index->next=index->next->next; + if (this->changeStackLast == elmt) + { + this->changeStackLast= index; + } + delete elmt; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() +{ + ChangesStackElement* newstack; + + // TODO : maybe assert functions here + if (this->currentNodeEdited == nullptr) + { + return; + } + if (this->currentNodeEdited->GetelementType() != VXMLTreeElement::TypeAttr) + { + return; + } + + if (this->currentNodeEditedStatus != 0) + { + if (this->currentNodeEditedStatus == DialogPatternXmlEdit::ChangeTypeDelete) + { // Change already done ??? ignore... + return; + } + if (this->currentNodeEditedStatus == DialogPatternXmlEdit::ChangeTypeAdd) + { // Attribute was previously added, just undo the change + if ( this->UndoChange(this->currentNodeEditedStack) == false ) + { // Error in undo... warn user + QMessageBox::warning(this, tr("No changes"), tr("Cannot delete previously created attribute")); + return; + } + this->ClearEditData(); + return; + } + if (this->currentNodeEditedStatus == DialogPatternXmlEdit::ChangeTypeModify) + { // Node was edited : remove change then continue to delete node + this->UndoChange(this->currentNodeEditedStack); + } + } + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeDelete); + newstack->element= this->currentNodeEdited; + + QFont textfont=currentNodeEdited->font(); + textfont.setStrikeOut(true); + this->currentNodeEdited->setFont(textfont); + // Activate changes + this->treeChange=true; + ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); + // clear dialog + this->ClearEditData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonAddSonClicked() +{ + ChangesStackElement* newstack; + bool ok; + //clear_edit_data(); + // TODO : maybe assert functions here + if (this->currentNodeEdited == nullptr) + { + return; + } + if (this->currentNodeEdited->GetelementType() != VXMLTreeElement::TypeNode) + { + return; + } + + + QString name = QInputDialog::getText(this, tr("Node Name"), tr("Name:"), QLineEdit::Normal, "", &ok); + if (ok==false) + { + return; + } + QString value = QInputDialog::getText(this, tr("Node Value (may be empty)"),tr("Value:"), + QLineEdit::Normal,"", &ok); + if (ok==false) + { + return; + } + + // create element tree and put father tree element to catch up with DOM tree. + QDomNode empty; + VXMLTreeElement* tElement = new VXMLTreeElement(name, VXMLTreeElement::TypeNode, empty, true); + tElement->SetFatherElement(this->currentNodeEdited); + + if (value.isEmpty() == false) + { + tElement->SetTreeNodeValue(value); + } + currentNodeEdited->appendRow(tElement); + xmlmodel->appendchain(tElement); + QFont textfont=currentNodeEdited->font(); + textfont.setBold(true); + tElement->setFont(textfont); + + // Add to change stack + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeAdd); + newstack->element=tElement; + newstack->newText=new QString(name); newstack->changedText=true; + if (value.isEmpty()) + { + newstack->changedValue=true;newstack->newValue=new QString(value); + } + // Activate changes + treeChange=true; + ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonAddAttributeClicked() +{ + ChangesStackElement* newstack; + bool ok; + QDomNode empty; // empty QNode to pas to create function : maybe a better way to do this ? + + // TODO : maybe assert functions here + if (this->currentNodeEdited == nullptr) + { + return; + } + if (this->currentNodeEdited->GetelementType() != VXMLTreeElement::TypeNode) + { + return; + } + + QString name = QInputDialog::getText(this, tr("Attribute Name"), + tr("Name:"), QLineEdit::Normal, + "", &ok); + if (ok==false) + { + return; + } + QString value = QInputDialog::getText(this, tr("Attribute Value"), + tr("Value:"), QLineEdit::Normal, + "", &ok); + if (ok==false) + { + return; + } + + // create element tree but do not add attribute in DOM (will be done in apply). + VXMLTreeElement* tElement = new VXMLTreeElement(name, VXMLTreeElement::TypeAttr, empty, true); + // set parent node. + tElement->SetFatherElement(this->currentNodeEdited); + + tElement->SetTreeNodeValue(value); + currentNodeEdited->appendRow(tElement); + xmlmodel->appendchain(tElement); + QFont textfont=currentNodeEdited->font(); + textfont.setBold(true); + tElement->setFont(textfont); + // Add to change stack + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeAdd); + newstack->element= tElement; + newstack->type=VXMLTreeElement::TypeAttr; + newstack->newText=new QString(name); + newstack->newValue=new QString(value); + // Activate changes + treeChange=true; + ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ButtonSetClicked() +{ + QString name, value; + ChangesStackElement* newstack; + + if (this->currentNodeEdited == nullptr) + { + return; + } + name=ui->lineEdit_Name->text(); + value=ui->lineEdit_Value->text(); + bool nameedit, valueedit; + + nameedit = (name != currentNodeEdited->GettreeNodeName()) ? true : false; + valueedit= (value != currentNodeEdited->GettreeNodeValue()) ? true : false; + + if ( nameedit == true || valueedit == true ) + { + if (this->currentNodeEditedStatus != 0) + { // If node was created or edited previously, rewrite + if (this->currentNodeEditedStatus == DialogPatternXmlEdit::ChangeTypeDelete) + { // You shouldn't be able to edit a deleted node... + Q_ASSERT(this->currentNodeEditedStatus != DialogPatternXmlEdit::ChangeTypeDelete); + ClearEditData(); + return; + } + newstack=this->currentNodeEditedStack; + if (nameedit == true) + { + newstack->changedText=true; + *newstack->newText=name; + currentNodeEdited->SetTreeNodeName(name); + } + if (valueedit == true) + { + if (newstack->changedValue==true) + { + *newstack->newValue = value; + } + else + { + newstack->changedValue=true; + newstack->newValue= new QString(value); + newstack->oldValue= new QString(this->currentNodeEdited->GettreeNodeValue()); + } + currentNodeEdited->SetTreeNodeValue(value); + } + } + else + { + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeModify); + newstack->element= this->currentNodeEdited; + + if (nameedit == true) + { + newstack->changedText=true; + newstack->newText=new QString(name); + newstack->oldText=new QString(this->currentNodeEdited->GettreeNodeName()); + currentNodeEdited->SetTreeNodeName(name); + } + if (valueedit == true) + { + newstack->changedValue=true; + newstack->newValue= new QString(value); + newstack->oldValue= new QString(this->currentNodeEdited->GettreeNodeValue()); + currentNodeEdited->SetTreeNodeValue(value); + } + } + QFont textfont=currentNodeEdited->font(); + textfont.setBold(true); + currentNodeEdited->setFont(textfont); + treeChange=true; + ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); + ClearEditData(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::NameTextEdited(QString newtext) +{ + //QMessageBox::information(this, "nameTextEdited", QString("%1").arg(newtext)); + ui->pushButton_Set_Values->setEnabled(true); + ui->pushButton_Cancel_Values->setEnabled(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ValueTextEdited(QString newtext) +{ + //QMessageBox::information(this, "valueTextEdited", QString("%1").arg(newtext)); + ui->pushButton_Set_Values->setEnabled(true); + ui->pushButton_Cancel_Values->setEnabled(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ClearEditData() +{ + ui->lineEdit_Name->setText(""); + ui->lineEdit_Value->setText(""); + ui->lineEdit_Name->setEnabled(false); + ui->lineEdit_Value->setEnabled(false); + + ui->label_type_value->setText(tr("No selection")); + ui->pushButton_Set_Values->setEnabled(false); + ui->pushButton_Add_attribute->setEnabled(false); + ui->pushButton_Add_son->setEnabled(false); + ui->pushButton_Remove_attribute->setEnabled(false); + ui->pushButton_Cancel_Values->setEnabled(false); + ui->pushButton_Remove_Node->setEnabled(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ClearStack() +{ + ChangesStackElement * tmp; + while (changeStackRoot != nullptr) + { + if (changeStackRoot->newText != nullptr) + { + delete changeStackRoot->newText; + } + if (changeStackRoot->newValue != nullptr) + { + delete changeStackRoot->newValue; + } + tmp=changeStackRoot; + changeStackRoot=changeStackRoot->next; + delete tmp; + } + changeStackLast=nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::BaseSelectionChanged(int value) +{ + QDomNode newbase; + + int index; + + if (this->treeChange == true) + {//Changes have been made : warn ? + } + this->ClearStack(); + ui->pushButton_Apply_Changes->setEnabled(false); + + index = ui->comboBox_Base_Selection->itemData(value).toInt(); //.convert(QVariant::Int); + Q_ASSERT(value < rootBasesNum); + // QMessageBox::information(this, "test", QString("%1:%2").arg(value).arg(index)); + + // Clear all tree info and nodes + // TODO : Check + while (rootNode->rowCount() > 0) + { + rootNode->removeRow(0); + } + this->xmlmodel->ClearTree(); + + VXMLTreeElement* standard_base = new VXMLTreeElement( + rootBases[index]->GettreeNodeName(), + VXMLTreeElement::TypeRoot, + rootBases[index]->GetDocNode(), + false); + rootNode->appendRow(standard_base); + ReadNodes(rootBases[index]->GetDocNode(), standard_base, xmlmodel, true); + + ui->treeView_main->setModel(xmlmodel); + this->ClearEditData(); + // TODO : warn if changes ? + this->ClearStack(); + return; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) +{ + + // Get item (function returns parent of clicked item) + VXMLTreeElement *item = static_cast (index.internalPointer()); + + // Get child specified by index row/column + VXMLTreeElement * item2 = static_cast (item->child(index.row(), index.column())); + + // Clear all data and disable buttons + this->ClearEditData(); + // Check if element is selectable at this time + if (item2->IsSelectable() == false) + { + return; + } + // Check status of element in change stack + this->currentNodeEdited=item2; + this->currentNodeEditedStatus=0; + ChangesStackElement * local = this->changeStackRoot; + while (local != nullptr) + { + if (local->element == item2) + { + this->currentNodeEditedStatus=local->type; + this->currentNodeEditedStack=local; + if (local->type == DialogPatternXmlEdit::ChangeTypeDelete) + { + // Node is deleted, only enable cancel button + ui->pushButton_Cancel_Values->setEnabled(true); + return; + } + } + local=local->next; + } + // Fill the dialog and Activate the line edit + if (item2->GetelementType() != VXMLTreeElement::TypeRoot) + { + ui->lineEdit_Name->setText(currentNodeEdited->GettreeNodeName()); + ui->lineEdit_Name->setEnabled(true); + // Fill value + ui->lineEdit_Value->setText(currentNodeEdited->GettreeNodeValue()); + ui->lineEdit_Value->setEnabled(true); + } + if (item2->GetelementType() == VXMLTreeElement::TypeRoot) + { + ui->label_type_value->setText(tr("Root node"));; + ui->pushButton_Add_son->setEnabled(true); + } + else if (item2->GetelementType() == VXMLTreeElement::TypeNode) + { + ui->label_type_value->setText(tr("Node")); + ui->pushButton_Add_attribute->setEnabled(true); + ui->pushButton_Add_son->setEnabled(true); + ui->pushButton_Remove_Node->setEnabled(true); + } + else if (item2->GetelementType() == VXMLTreeElement::TypeAttr) + { + ui->label_type_value->setText(tr("Attribute")); + ui->pushButton_Remove_attribute->setEnabled(true); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogPatternXmlEdit::~DialogPatternXmlEdit() +{ + this->ClearStack(); + this->xmlmodel->ClearTree(); + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXMLTreeView* xmlmodel, bool refresh) +{ + + QDomNode tNode, tNode2; + VXMLTreeElement* tElement, *tElement2; + int totalOfChilds = dNode.childNodes().size(); + if (totalOfChilds == 0) + { + return; // empty xml + } + for (int i=0;iappendchain(tElement); + root->appendRow(tElement); + if (tNode.nodeName() == "draw") + { + for (int i = 0; i < tNode.attributes().size(); i++) + { + if ((tNode.attributes().item(i).nodeName() == "name") + && (refresh == false)) + { + ui->comboBox_Base_Selection->addItem(tNode.attributes().item(i).nodeValue(), + QVariant(rootBasesNum)); + rootBases[rootBasesNum]=new VXMLTreeElement( + QString("Drawing %1").arg(tNode.attributes().item(i).nodeValue()), + VXMLTreeElement::TypeRoot, tNode, false); + rootBasesNum++; + //QStandardItem* rootNode = (QStandardItem*) rootBases[rootBasesNum]->invisibleRootItem(); + //rootNode->appendRow(tElement); + } + } + } + } + } + + do + { + tElement=xmlmodel->getCurrent()->elmt; + tNode=tElement->GetDocNode(); + if (tElement->GetelementType() == VXMLTreeElement::TypeNode) + { + totalOfChilds = tNode.childNodes().size(); + for (int i=0;iappendchain(tElement2); + tElement->appendRow(tElement2); + } + } + + if (tNode.nodeType() == QDomNode::TextNode) + { + tElement->SetTreeNodeValue(tNode.nodeValue()); + } + + for (int i = 0; i < tNode.attributes().size(); i++) + { + tElement2 = new VXMLTreeElement(tNode.attributes().item(i).nodeName(), VXMLTreeElement::TypeAttr, + tNode, false); + tElement2->SetTreeNodeValue(tNode.attributes().item(i).nodeValue()); + tElement->appendRow(tElement2); + xmlmodel->appendchain(tElement2); + } + } + xmlmodel->SetCurrent(xmlmodel->getCurrent()->next); + } + while (xmlmodel->getCurrent() != 0); + return; +} + +//--------------------------------------------------------------------------------------------------------------------- +VXMLTreeView::VXMLTreeView(QObject *parent) + : QStandardItemModel(parent), items(nullptr), current(nullptr), last(nullptr) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VXMLTreeView::ClearTree() +{ + + // TODO check if treeitems are deleted with the delete row command of QDom + + //clear the chain link + TreeElementchain * tmp; + while (items != nullptr) + { + tmp=items; + items=items->next; + delete tmp; + } + // reset chain counters + current=last=items=nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +VXMLTreeView::~VXMLTreeView() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VXMLTreeView::appendchain(VXMLTreeElement* elmt) +{ + if (last == nullptr) + { // first element + current = new TreeElementchain; + if (current == nullptr) + { + Q_ASSERT(current != nullptr); + // TODO : throw exception + } + current->elmt=elmt; + current->next=nullptr; + last=items=current; + return; + } + TreeElementchain* temp= new TreeElementchain; + if (temp == nullptr) + { + Q_ASSERT(temp != nullptr); + // TODO : throw exception + } + temp->elmt=elmt; + temp->next=nullptr; + last->next=temp; + last=temp; +} + +const short int VXMLTreeElement::TypeNode=1; +const short int VXMLTreeElement::TypeAttr=2; +const short int VXMLTreeElement::TypeRoot=3; + +//--------------------------------------------------------------------------------------------------------------------- +//TODO warning: conversion to 'short int' from 'int' may alter its value [-Wconversion] +//treeNodeValueSet(false), treeNodeName(name) +// ^ +VXMLTreeElement::VXMLTreeElement(QString name, short int nodetype, QDomNode source, bool editor) + : QStandardItem(name), DocNode(source), parentnode(nullptr), addedNode(editor), elementType(nodetype), + treeNodeValue(""), treeNodeValueSet(false), treeNodeName(name), selectable(true) +{ + if (editor == false) + { + this->DocNode=source; + } + this->setText(this->DisplayText()); + switch (this->elementType) + { + case VXMLTreeElement::TypeAttr: + this->setBackground(BACKGROUND_COLOR_ATTRIBUTE); + break; + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VXMLTreeElement::~VXMLTreeElement() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VXMLTreeElement::SetTreeNodeValue(QString value) +{ + this->treeNodeValue=value; + this->treeNodeValueSet=true; + this->setText(this->DisplayText()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VXMLTreeElement::SetTreeNodeName(QString value) +{ + this->treeNodeName=value; + this->setText(this->DisplayText()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VXMLTreeElement::DisplayText() +{ + if (this->elementType == VXMLTreeElement::TypeRoot) + { + return this->treeNodeName; + } + return QString("%1 : %2").arg((this->treeNodeName)).arg(this->treeNodeValue); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VXMLTreeElement::GettreeNodeValue() +{ + // Only return value if it's really set. + if (this->treeNodeValueSet) + { + return this->treeNodeValue; + } + else + { + return QString(); + } +} diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h new file mode 100644 index 000000000..498701075 --- /dev/null +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -0,0 +1,388 @@ +/************************************************************************ + ** + ** @file dialogpatternxmledit.h + ** @author Patrick Proy + ** @date 14 5, 2014 + ** + ** @brief Include file for the XML editor dialog + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef DIALOGPATTERNXMLEDIT_H +#define DIALOGPATTERNXMLEDIT_H + +#include +#include +#include "../../xml/vpattern.h" + +//******************************************************************************************** +/** + * @brief The vXMLTreeElement class : node/attribute of xml pattern. Used by vXMLTreeView + * + */ + +#define BACKGROUND_COLOR_ATTRIBUTE QBrush(Qt::GlobalColor::cyan) +#define BACKGROUND_COLOR_INACTIVE_NODE QBrush(Qt::GlobalColor::gray) +class VXMLTreeElement : public QStandardItem +{ + +public: + /** + * @brief vXMLTreeElement + * @param name : display name + * @param nodetype : node type (node, attribute, root) + * @param source : the source dom node + */ + explicit VXMLTreeElement (QString name, short int nodetype, QDomNode source, bool editor); + + explicit VXMLTreeElement (QString name, int nodetype); + + ~VXMLTreeElement (); + static const short int TypeNode; + static const short int TypeAttr; + static const short int TypeRoot; + /** + * @brief setNodeValue : set value of node (content or attribute) + * @param value : the value + */ + void SetTreeNodeValue(QString value); + /** + * @brief displayText : text to display + * @return text to display + */ + QString DisplayText(); + /** + * @brief getDocNode + * @return current document node + */ + QDomNode GetDocNode(); + /** + * @brief SetDocNode set tree element DomNode + * @param node + */ + inline void SetDocNode(QDomNode node) + { + this->DocNode=node; + } + inline void SetAddedNode(bool state) {this->addedNode=state;} + inline bool GetAddedNode() {return this->addedNode;} + + QString GettreeNodeName(); + QString GettreeNodeValue(); + /** + * @brief GettreeNodeValueSet check if value has been set + * @return true if value is set + */ + bool GettreeNodeValueSet(); + void SetTreeNodeName(QString value); + /** + * @brief getelementType + * @return elementType value + */ + short int GetelementType(); + bool IsSelectable(); + void SetSetlectable(bool value); + + inline void SetFatherElement(VXMLTreeElement* parent) + { + this->parentnode=parent; + } + inline VXMLTreeElement* GetFatherElement() + { + return this->parentnode; + } + +private: + /** + * @brief DocNode : link to current document node + */ + QDomNode DocNode; + + /** + * @brief parentnode parent node of this element. If null then the DocNode must be valid + */ + VXMLTreeElement* parentnode; + + /** + * @brief addedNode : true if node is added by editor (implies empty DocNode) + */ + bool addedNode; + /** + * @brief type : element type (node, attribute, text value of node) + */ + short int elementType; + /** + * @brief nodeValue : Attribute or node value + */ + QString treeNodeValue; + /** + * @brief treeNodeValueSet : true if value has been set + */ + bool treeNodeValueSet; + /** + * @brief nodeValue : Attribute or node value + */ + QString treeNodeName; + /** + * @brief selectable : can item be selected to be changed (ex : false if father deleted). + */ + bool selectable; + Q_DISABLE_COPY(VXMLTreeElement) +}; + +inline bool VXMLTreeElement::IsSelectable() +{ + return this->selectable; +} + +inline void VXMLTreeElement::SetSetlectable(bool value) +{ + this->selectable=value; +} + +inline short int VXMLTreeElement::GetelementType() +{ + return this->elementType; +} + +inline QDomNode VXMLTreeElement::GetDocNode() +{ + return this->DocNode; +} + +inline QString VXMLTreeElement::GettreeNodeName() +{ + return this->treeNodeName; +} + +inline bool VXMLTreeElement::GettreeNodeValueSet() +{ + return this->treeNodeValueSet; +} + +//******************************************************************************************** +/** + * @brief The vXMLTreeView class : container to display/edit xml pattern + */ +class VXMLTreeView : public QStandardItemModel +{ +public: + explicit VXMLTreeView (QObject *parent = 0); + void appendchain(VXMLTreeElement* elmt); + + /** + * @brief The TreeElement struct : chained list of vXMLTreeElement + */ + typedef struct TreeElementchain + { + VXMLTreeElement* elmt; + TreeElementchain* next; + } TreeElementchain; + + TreeElementchain * getCurrent(); + void SetCurrent(TreeElementchain * value); + TreeElementchain * GetLast(); + TreeElementchain * GetItems(); + /** + * @brief clearTree : clear tree elements and listed items. + */ + void ClearTree(); + ~VXMLTreeView (); +private: + Q_DISABLE_COPY(VXMLTreeView) + + /** + * @brief items : root of chained list of vXMLTreeElement + */ + TreeElementchain * items; + /** + * @brief current : used to parse in iteration. + */ + TreeElementchain * current; + /** + * @brief last : used to parse in iteration. + */ + TreeElementchain * last; +}; + +inline VXMLTreeView::TreeElementchain * VXMLTreeView::getCurrent() +{ + return this->current; +} +inline void VXMLTreeView::SetCurrent(VXMLTreeView::TreeElementchain * value) +{ + this->current=value; +} +inline VXMLTreeView::TreeElementchain * VXMLTreeView::GetLast() +{ + return this->last; +} +inline VXMLTreeView::TreeElementchain * VXMLTreeView::GetItems() +{ + return this->items; +} + +//******************************************************************************************** + +namespace Ui +{ + class DialogPatternXmlEdit; +} +/** + * @brief The DialogPatternXmlEdit class : ui dialog for XML editing of pattern + */ +class DialogPatternXmlEdit : public QDialog +{ + Q_OBJECT + +public: + explicit DialogPatternXmlEdit(QWidget *parent = 0, VPattern *xmldoc = 0); + ~DialogPatternXmlEdit(); + + /** + * @brief clear_edit_data : clear input boxes and disables buttons. + */ + void ClearEditData(); + + void NameTextEdited(QString newtext); + void ValueTextEdited(QString newtext); + void ButtonSetClicked(); + void ButtonCancelClicked(); + void ButtonDeleteAttributeClicked(); + void ButtonAddSonClicked(); + void ButtonAddAttributeClicked(); + void ButtonApplyChangesClicked(); + void ButtonUndoLastChange(); + void ButtonDeleteNode(); + + // Stack of changes definition + typedef struct ChangesStackElement + { + short int type; + VXMLTreeElement *element; + QString *newText; + QString *oldText; + bool changedText; + QString *newValue; + QString *oldValue; + bool changedValue; + ChangesStackElement* next; + } ChangesStackElement; + + // Change stack functions + ChangesStackElement* CreateStackElement(short int typechange); + void RemoveChangeStackElement(ChangesStackElement* elmt); + void ClearStack(); + bool treeChange; + VXMLTreeElement* currentNodeEdited; + short int currentNodeEditedStatus; + ChangesStackElement* currentNodeEditedStack; + /** + * @brief UndoChange : undo change in change stack element + * @param current : change to undo + * @return true if undo has been done, false on error + */ + bool UndoChange(ChangesStackElement* current); + /** + * @brief DeleteNodeAndSons : delete node and all it's attribute and sons below + * @param currentNode : node to delete + * @param onlydeactivate : if true, dont delete just deactivate sons and attributes + * @return false if changes couldn't be done + */ + bool DeleteNodeAndSons(VXMLTreeElement *currentNode, bool onlydeactivate); + + /** + * @brief ApplyAttributeChange change or add attribute for node + * @param domElement : node containing attribute + * @param name + * @param value + * @return true on success + */ + bool ApplyAttributeChange(QDomNode domElement, QString name, QString value); + /** + * @brief ApplyNodeChange Change name or text content of node + * @param domElement node + * @param name + * @param value text content of node + * @return true on success + */ + bool ApplyNodeChange(QDomNode domElement, QString name, QString value); + /** + * @brief ApplyNodeAdd add node as child of domElement and set DocNode of treeElement + * @param domElement + * @param treeElement the XMLTreeElement of added node + * @param name + * @param value + * @return true on success + */ + bool ApplyNodeAdd(QDomNode domElement, VXMLTreeElement* treeElement, QString name, QString value); + /** + * @brief ApplyAttributeDelete delete attribute for node + * @param domElement + * @param name attribute name + * @return true on success + */ + bool ApplyAttributeDelete(QDomNode domElement, QString name); + /** + * @brief ApplyNodeDelete delete node domElement + * @param domElement + * @return true on success + */ + bool ApplyNodeDelete(QDomNode domElement); + /** + * @brief CheckChanges Check if changes made are OK + * @param message error message returned if false + * @param testRoot root of DOM to test + * @return true if validated, false otherwise + */ + bool CheckChanges(QString &message, QDomNode testRoot); +private slots: + void BaseSelectionChanged(int value); + void ElementClicked ( const QModelIndex & index ); + +private: + Q_DISABLE_COPY(DialogPatternXmlEdit) + Ui::DialogPatternXmlEdit *ui; + + VPattern *doc; + + QDomElement root; + QStandardItem *rootNode; + //typedef struct rootbases { vXMLTreeElement * root; QString name; } rootbases; + VXMLTreeElement ** rootBases; + qint16 rootBasesNum; + + void ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXMLTreeView *xmlmodel, bool refresh); + VXMLTreeView* xmlmodel; + + + // Stack of changes + static const short int ChangeTypeDelete; + static const short int ChangeTypeAdd; + static const short int ChangeTypeModify; + + // Stack of changes + + ChangesStackElement* changeStackRoot; + ChangesStackElement* changeStackLast; +}; + +#endif // DIALOGPATTERNXMLEDIT_H diff --git a/src/app/dialogs/app/dialogpatternxmledit.ui b/src/app/dialogs/app/dialogpatternxmledit.ui new file mode 100644 index 000000000..2b4c4a83a --- /dev/null +++ b/src/app/dialogs/app/dialogpatternxmledit.ui @@ -0,0 +1,367 @@ + + + DialogPatternXmlEdit + + + + 0 + 0 + 664 + 459 + + + + + 1 + 1 + + + + + 400 + 300 + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + XML Editor + + + false + + + false + + + + + + QLayout::SetMaximumSize + + + + + QLayout::SetDefaultConstraint + + + 0 + + + + + false + + + QAbstractItemView::SingleSelection + + + true + + + false + + + + + + + QLayout::SetMinimumSize + + + 9 + + + + + + 0 + 0 + + + + Value : + + + + + + + false + + + + + + + false + + + + + + + + 0 + 0 + + + + Name : + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 10 + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + <No selection> + + + + + + + + 0 + 0 + + + + Type : + + + + + + + false + + + Add attribute + + + + + + + false + + + Add son + + + + + + + + + QLayout::SetNoConstraint + + + QFormLayout::ExpandingFieldsGrow + + + + + false + + + Remove attibute + + + + + + + false + + + Remove node + + + + + + + false + + + Qt::LeftToRight + + + Set + + + + + + + false + + + Qt::LeftToRight + + + Cancel + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + false + + + Apply changes + + + + + + + false + + + Undo last + + + + + + + Immediate apply + + + false + + + + + + + + + + 0 + 0 + + + + Base selection + + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 5 + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogPatternXmlEdit + accept() + + + 248 + 254 + + + 157 + 274 + + + + + diff --git a/src/app/dialogs/app/dialogstandardmeasurements.cpp b/src/app/dialogs/app/dialogstandardmeasurements.cpp index 996f61253..b456d84f9 100644 --- a/src/app/dialogs/app/dialogstandardmeasurements.cpp +++ b/src/app/dialogs/app/dialogstandardmeasurements.cpp @@ -42,12 +42,12 @@ DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, const Q { const QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); connect(bOk, &QPushButton::clicked, this, &DialogStandardMeasurements::DialogAccepted); } { const QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - Q_CHECK_PTR(bCansel); + SCASSERT(bCansel != nullptr); connect(bCansel, &QPushButton::clicked, this, &DialogStandardMeasurements::DialogRejected); } @@ -121,7 +121,7 @@ void DialogStandardMeasurements::CheckState() bool flagTable = false; { const QComboBox *box = ui->comboBoxTables; - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); if (box->count() > 0 && box->currentIndex() != -1) { flagTable = true; @@ -129,7 +129,7 @@ void DialogStandardMeasurements::CheckState() } QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagTable && flagName); } diff --git a/src/app/dialogs/dialogs.h b/src/app/dialogs/dialogs.h index a64ffcdbb..ec4e9c874 100644 --- a/src/app/dialogs/dialogs.h +++ b/src/app/dialogs/dialogs.h @@ -58,5 +58,6 @@ #include "app/dialogindividualmeasurements.h" #include "app/dialogstandardmeasurements.h" #include "app/dialogaboutapp.h" +#include "app/dialogpatternxmledit.h" #endif // DIALOGS_H diff --git a/src/app/dialogs/dialogs.pri b/src/app/dialogs/dialogs.pri index 01e895748..8bbb24693 100644 --- a/src/app/dialogs/dialogs.pri +++ b/src/app/dialogs/dialogs.pri @@ -29,8 +29,9 @@ HEADERS += \ dialogs/app/dialogmeasurements.h \ dialogs/app/dialogstandardmeasurements.h \ dialogs/app/dialogindividualmeasurements.h \ - dialogs/app/dialogaboutapp.h \ - dialogs/tools/dialogeditwrongformula.h + dialogs/app/dialogaboutapp.h \ + dialogs/tools/dialogeditwrongformula.h \ + dialogs/app/dialogpatternxmledit.h SOURCES += \ dialogs/tools/dialogtriangle.cpp \ @@ -62,8 +63,9 @@ SOURCES += \ dialogs/app/dialogmeasurements.cpp \ dialogs/app/dialogstandardmeasurements.cpp \ dialogs/app/dialogindividualmeasurements.cpp \ - dialogs/app/dialogaboutapp.cpp \ - dialogs/tools/dialogeditwrongformula.cpp + dialogs/app/dialogaboutapp.cpp \ + dialogs/app/dialogpatternxmledit.cpp \ + dialogs/tools/dialogeditwrongformula.cpp FORMS += \ dialogs/tools/dialogtriangle.ui \ @@ -92,5 +94,6 @@ FORMS += \ dialogs/app/dialogmeasurements.ui \ dialogs/app/dialogstandardmeasurements.ui \ dialogs/app/dialogindividualmeasurements.ui \ - dialogs/app/dialogaboutapp.ui \ - dialogs/tools/dialogeditwrongformula.ui + dialogs/app/dialogaboutapp.ui \ + dialogs/app/dialogpatternxmledit.ui \ + dialogs/tools/dialogeditwrongformula.ui diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 28fe46024..f5491a0d8 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -38,17 +38,19 @@ * @param parent parent widget */ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0) + :DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), typeLine(QString()), + formula(QString()), firstPointId(0), secondPointId(0), formulaBaseHeight(0) { ui->setupUi(this); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + flagFormula = false; flagName = false; - InitOkCansel(ui); + InitOkCancelApply(ui); CheckState(); FillComboBoxTypeLine(ui->comboBoxLineType); @@ -60,9 +62,38 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogAlongLine::PutHere); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogAlongLine::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit); InitVariables(ui); connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::FormulaTextChanged() +{ + this->FormulaChangedPlainText(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGALONLINE_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGALONLINE_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -108,13 +139,26 @@ void DialogAlongLine::ChoosedObject(quint32 id, const Valentina::Scenes &type) * @brief DialogAccepted save data and emit signal about closed dialog. */ void DialogAlongLine::DialogAccepted() +{ + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- @@ -147,7 +191,12 @@ void DialogAlongLine::setFirstPointId(const quint32 &value, const quint32 &id) void DialogAlongLine::setFormula(const QString &value) { formula = qApp->FormulaToUser(value); - ui->lineEditFormula->setText(formula); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formula); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogalongline.h b/src/app/dialogs/tools/dialogalongline.h index 850a702ea..708fca0c2 100644 --- a/src/app/dialogs/tools/dialogalongline.h +++ b/src/app/dialogs/tools/dialogalongline.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGALONLINE_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogAlongLine; @@ -62,6 +63,18 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogAlongLine) @@ -85,6 +98,14 @@ private: /** @brief secondPointId id second point of line */ quint32 secondPointId; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index 9113f9e04..5bf4d8691 100644 --- a/src/app/dialogs/tools/dialogalongline.ui +++ b/src/app/dialogs/tools/dialogalongline.ui @@ -74,11 +74,17 @@ - - - Formula for the calculation of length of line + + + Qt::Horizontal - + + + 40 + 20 + + + @@ -150,6 +156,55 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + :/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png:/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png + + + + 16 + 16 + + + + true + + + + + @@ -390,14 +445,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula toolButtonEqual lineEditNamePoint comboBoxFirstPoint @@ -414,6 +468,7 @@ + diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index f89723839..44537a814 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -42,7 +42,8 @@ */ DialogArc::DialogArc(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false), - timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(0), radius(QString()), f1(QString()), f2(QString()) + timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(0), radius(QString()), f1(QString()), + f2(QString()), formulaBaseHeight(0) { ui->setupUi(this); @@ -55,7 +56,9 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) timerF2 = new QTimer(this); connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); - InitOkCansel(ui); + InitOkCancelApply(ui); + + this->formulaBaseHeight=ui->plainTextEditFormula->height(); FillComboBoxPoints(ui->comboBoxBasePoint); @@ -71,9 +74,32 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) connect(ui->toolButtonEqualF1, &QPushButton::clicked, this, &DialogArc::EvalF1); connect(ui->toolButtonEqualF2, &QPushButton::clicked, this, &DialogArc::EvalF2); - connect(ui->lineEditRadius, &QLineEdit::textChanged, this, &DialogArc::RadiusChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogArc::RadiusChanged); connect(ui->lineEditF1, &QLineEdit::textChanged, this, &DialogArc::F1Changed); connect(ui->lineEditF2, &QLineEdit::textChanged, this, &DialogArc::F2Changed); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogArc::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGARC_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGARC_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -123,7 +149,12 @@ void DialogArc::SetF1(const QString &value) void DialogArc::SetRadius(const QString &value) { radius = value; - ui->lineEditRadius->setText(radius); + // increase height if needed. + if (radius.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(radius); } //--------------------------------------------------------------------------------------------------------------------- @@ -150,11 +181,24 @@ void DialogArc::ChoosedObject(quint32 id, const Valentina::Scenes &type) */ void DialogArc::DialogAccepted() { - radius = ui->lineEditRadius->text(); + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::SaveData() +{ + radius = ui->plainTextEditFormula->toPlainText(); + radius.replace("\n"," "); f1 = ui->lineEditF1->text(); f2 = ui->lineEditF2->text(); center = getCurrentObjectId(ui->comboBoxBasePoint); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- @@ -185,7 +229,7 @@ void DialogArc::ValChenged(int row) */ void DialogArc::PutRadius() { - PutValHere(ui->lineEditRadius, ui->listWidget); + PutValHere(ui->plainTextEditFormula, ui->listWidget); } //--------------------------------------------------------------------------------------------------------------------- @@ -223,7 +267,7 @@ void DialogArc::LineAngles() void DialogArc::RadiusChanged() { labelEditFormula = ui->labelEditRadius; - ValFormulaChanged(flagRadius, ui->lineEditRadius, timerRadius); + ValFormulaChanged(flagRadius, ui->plainTextEditFormula, timerRadius); } //--------------------------------------------------------------------------------------------------------------------- @@ -252,8 +296,10 @@ void DialogArc::F2Changed() */ void DialogArc::CheckState() { - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagRadius && flagF1 && flagF2); + SCASSERT(bApply != nullptr); + bApply->setEnabled(flagRadius && flagF1 && flagF2); } //--------------------------------------------------------------------------------------------------------------------- @@ -263,7 +309,7 @@ void DialogArc::CheckState() void DialogArc::EvalRadius() { labelEditFormula = ui->labelEditRadius; - Eval(ui->lineEditRadius, flagRadius, timerRadius, ui->labelResultRadius); + Eval(ui->plainTextEditFormula, flagRadius, timerRadius, ui->labelResultRadius); } //--------------------------------------------------------------------------------------------------------------------- @@ -296,7 +342,7 @@ void DialogArc::ShowLineAngles() ui->listWidget->clear(); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); const QHash *lineAnglesTable = data->DataLineAngles(); - Q_CHECK_PTR(lineAnglesTable); + SCASSERT(lineAnglesTable != nullptr); QHashIterator i(*lineAnglesTable); while (i.hasNext()) { diff --git a/src/app/dialogs/tools/dialogarc.h b/src/app/dialogs/tools/dialogarc.h index 667065cb6..361c8d695 100644 --- a/src/app/dialogs/tools/dialogarc.h +++ b/src/app/dialogs/tools/dialogarc.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGARC_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogArc; @@ -60,6 +61,14 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); virtual void ValChenged(int row); void PutRadius(); void PutF1(); @@ -107,10 +116,17 @@ private: /** @brief f2 formula of second angle */ QString f2; + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + void EvalRadius(); void EvalF1(); void EvalF2(); void ShowLineAngles(); + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogarc.ui b/src/app/dialogs/tools/dialogarc.ui index f5705908f..606cf83c4 100644 --- a/src/app/dialogs/tools/dialogarc.ui +++ b/src/app/dialogs/tools/dialogarc.ui @@ -23,6 +23,9 @@ + + QLayout::SetDefaultConstraint + @@ -74,15 +77,48 @@ - - - - 0 - 0 - + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + - Formula for the calculation of radius of arc + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true @@ -580,14 +616,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditRadius lineEditF1 lineEditF2 comboBoxBasePoint diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 6e4f50e81..3240014db 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -39,16 +39,19 @@ * @param parent parent widget */ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0) + :DialogTool(data, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), + formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0), formulaBaseHeight(0) { ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + + InitOkCancelApply(ui); flagFormula = false; flagName = false; CheckState(); @@ -63,7 +66,36 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogBisector::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogBisector::NamePointChanged); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogBisector::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogBisector::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogBisector::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogBisector::FormulaTextChanged() +{ + this->FormulaChangedPlainText(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogBisector::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGBISECTOR_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGBISECTOR_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -152,7 +184,12 @@ void DialogBisector::setTypeLine(const QString &value) void DialogBisector::setFormula(const QString &value) { formula = qApp->FormulaToUser(value); - ui->lineEditFormula->setText(formula); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -193,12 +230,25 @@ void DialogBisector::setThirdPointId(const quint32 &value, const quint32 &id) * @brief DialogAccepted save data and emit signal about closed dialog. */ void DialogBisector::DialogAccepted() +{ + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogBisector::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogBisector::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); thirdPointId = getCurrentObjectId(ui->comboBoxThirdPoint); - emit DialogClosed(QDialog::Accepted); } diff --git a/src/app/dialogs/tools/dialogbisector.h b/src/app/dialogs/tools/dialogbisector.h index 99ce110f4..974a94e31 100644 --- a/src/app/dialogs/tools/dialogbisector.h +++ b/src/app/dialogs/tools/dialogbisector.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGBISECTOR_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogBisector; @@ -67,6 +68,18 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogBisector) @@ -93,6 +106,14 @@ private: /** @brief thirdPointId id of third point */ quint32 thirdPointId; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogbisector.ui b/src/app/dialogs/tools/dialogbisector.ui index 1c5221267..5c634c8aa 100644 --- a/src/app/dialogs/tools/dialogbisector.ui +++ b/src/app/dialogs/tools/dialogbisector.ui @@ -71,17 +71,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Calculation of length of bisector by using the formula + + + 40 + 20 + - + @@ -147,6 +147,54 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -429,14 +477,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula lineEditNamePoint comboBoxFirstPoint comboBoxSecondPoint diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 55132134e..972c28b10 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -38,20 +38,22 @@ * @param data container with data * @param parent parent widget */ -DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), arcId(0) +DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) + : DialogTool(data, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), arcId(0), + formulaBaseHeight(0) { ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; CheckState(); + this->formulaBaseHeight=ui->plainTextEditFormula->height(); FillComboBoxArcs(ui->comboBoxArc); @@ -60,7 +62,36 @@ DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) : connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogCutArc::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutArc::NamePointChanged); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogCutArc::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutArc::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutArc::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::FormulaTextChanged() +{ + this->FormulaChangedPlainText(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGCUTARC_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGCUTARC_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -92,12 +123,25 @@ void DialogCutArc::ChoosedObject(quint32 id, const Valentina::Scenes &type) */ void DialogCutArc::DialogAccepted() { - pointName = ui->lineEditNamePoint->text(); - formula = ui->lineEditFormula->text(); - arcId = getCurrentObjectId(ui->comboBoxArc); + this->SaveData(); emit DialogClosed(QDialog::Accepted); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::SaveData() +{ + pointName = ui->lineEditNamePoint->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); + arcId = getCurrentObjectId(ui->comboBoxArc); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setArcId set id of arc @@ -117,7 +161,12 @@ void DialogCutArc::setArcId(const quint32 &value, const quint32 &id) void DialogCutArc::setFormula(const QString &value) { formula = qApp->FormulaToUser(value); - ui->lineEditFormula->setText(formula); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formula); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutarc.h b/src/app/dialogs/tools/dialogcutarc.h index ece152ef9..9fceca34d 100644 --- a/src/app/dialogs/tools/dialogcutarc.h +++ b/src/app/dialogs/tools/dialogcutarc.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGCUTARC_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogCutArc; @@ -43,6 +44,7 @@ class DialogCutArc : public DialogTool { Q_OBJECT public: + DialogCutArc(const VContainer *data, QWidget *parent = nullptr); ~DialogCutArc(); @@ -57,6 +59,18 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogCutArc) /** @brief ui keeps information about user interface */ @@ -70,6 +84,13 @@ private: /** @brief arcId keep id of arc */ quint32 arcId; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutarc.ui b/src/app/dialogs/tools/dialogcutarc.ui index bfbff85fa..c79294e69 100644 --- a/src/app/dialogs/tools/dialogcutarc.ui +++ b/src/app/dialogs/tools/dialogcutarc.ui @@ -67,17 +67,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for the calculation of the spline + + + 40 + 20 + - + @@ -140,6 +140,56 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -353,7 +403,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 622c02f76..57315db5f 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -47,7 +47,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, QWidget *parent) lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancel(ui); flagFormula = false; flagName = false; diff --git a/src/app/dialogs/tools/dialogcutspline.h b/src/app/dialogs/tools/dialogcutspline.h index 455b127ff..20ef63fa0 100644 --- a/src/app/dialogs/tools/dialogcutspline.h +++ b/src/app/dialogs/tools/dialogcutspline.h @@ -57,6 +57,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogCutSpline) diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index fd7bbfcbb..00e758624 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -49,7 +49,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, QWidget *parent labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancel(ui); flagFormula = false; flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogcutsplinepath.h b/src/app/dialogs/tools/dialogcutsplinepath.h index 06baa4d2a..a93c2c2bc 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.h +++ b/src/app/dialogs/tools/dialogcutsplinepath.h @@ -57,6 +57,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogCutSplinePath) diff --git a/src/app/dialogs/tools/dialogdetail.cpp b/src/app/dialogs/tools/dialogdetail.cpp index 96b8be0eb..717f912f7 100644 --- a/src/app/dialogs/tools/dialogdetail.cpp +++ b/src/app/dialogs/tools/dialogdetail.cpp @@ -48,10 +48,10 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent) labelEditNamePoint = ui.labelEditNameDetail; bOk = ui.buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); - Q_CHECK_PTR(bCansel); + SCASSERT(bCansel != nullptr); connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); flagName = true;//We have default name of detail. @@ -221,7 +221,7 @@ void DialogDetail::BiasXChanged(qreal d) { qint32 row = ui.listWidget->currentRow(); QListWidgetItem *item = ui.listWidget->item( row ); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); node.setMx(qApp->toPixel(d)); item->setData(Qt::UserRole, QVariant::fromValue(node)); @@ -236,7 +236,7 @@ void DialogDetail::BiasYChanged(qreal d) { qint32 row = ui.listWidget->currentRow(); QListWidgetItem *item = ui.listWidget->item( row ); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); node.setMy(qApp->toPixel(d)); item->setData(Qt::UserRole, QVariant::fromValue(node)); diff --git a/src/app/dialogs/tools/dialogdetail.h b/src/app/dialogs/tools/dialogdetail.h index adaa2067e..ad6cc48b2 100644 --- a/src/app/dialogs/tools/dialogdetail.h +++ b/src/app/dialogs/tools/dialogdetail.h @@ -47,6 +47,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} void BiasXChanged(qreal d); void BiasYChanged(qreal d); void ClickedSeams(bool checked); diff --git a/src/app/dialogs/tools/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index 33fcbed3a..c303e8895 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -39,7 +39,7 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, QWidget * lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelFormula; - InitOkCansel(ui); + InitOkCancel(ui); flagFormula = false; CheckState(); @@ -83,7 +83,7 @@ void DialogEditWrongFormula::DialogRejected() //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::CheckState() { - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagFormula); } diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 1aa7782b3..ac78ce73e 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -39,17 +39,19 @@ * @param parent parent widget */ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), - formula(QString()), angle(0), basePointId(0) + :DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), formula(QString()), + angle(0), basePointId(0), formulaBaseHeight(0) { ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + + InitOkCancelApply(ui); flagFormula = false; flagName = false; CheckState(); @@ -63,7 +65,37 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEndLine::PutVal); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEndLine::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogEndLine::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::FormulaTextChanged() +{ + this->FormulaChangedPlainText(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGENDLINE_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGENDLINE_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -113,7 +145,16 @@ void DialogEndLine::setTypeLine(const QString &value) void DialogEndLine::setFormula(const QString &value) { formula = qApp->FormulaToUser(value); - ui->lineEditFormula->setText(formula); + // increase height if needed. TODO : see if I can get the max number of caracters in one line + // of this PlainTextEdit to change 80 to this value + if (formula.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formula); + //QTextCursor cursor = ui->plainTextEditFormula->textCursor(); + //cursor.insertText(value); + //ui->plainTextEditFormula->setCursor(cursor); } //--------------------------------------------------------------------------------------------------------------------- @@ -143,13 +184,26 @@ void DialogEndLine::setBasePointId(const quint32 &value, const quint32 &id) * @brief DialogAccepted save data and emit signal about closed dialog. */ void DialogEndLine::DialogAccepted() +{ + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); angle = ui->doubleSpinBoxAngle->value(); basePointId = getCurrentObjectId(ui->comboBoxBasePoint); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogendline.h b/src/app/dialogs/tools/dialogendline.h index 55fb4cdff..7cba81c13 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -31,6 +31,8 @@ #include "dialogtool.h" + +#define DIALOGENDLINE_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogEndLine; @@ -63,6 +65,18 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogEndLine) @@ -83,6 +97,13 @@ private: /** @brief basePointId id base point of line */ quint32 basePointId; + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 1b88dd92b..12be8bf7a 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -6,8 +6,8 @@ 0 0 - 584 - 718 + 486 + 586 @@ -80,17 +80,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for calculation of length of line + + + 40 + 20 + - + @@ -153,6 +153,58 @@ + + + + + + + 16777215 + 24 + + + + + 4 + 0 + + + + QPlainTextEdit::NoWrap + + + + + + + + 16 + 16 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + :/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png:/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png + + + + 16 + 16 + + + + true + + + + + @@ -594,14 +646,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula comboBoxBasePoint lineEditNamePoint doubleSpinBoxAngle @@ -626,6 +677,7 @@ + diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index 082d87c47..a3e0534b0 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -44,7 +44,7 @@ DialogHeight::DialogHeight(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogheight.h b/src/app/dialogs/tools/dialogheight.h index fe3a1c498..25f443cf0 100644 --- a/src/app/dialogs/tools/dialogheight.h +++ b/src/app/dialogs/tools/dialogheight.h @@ -63,6 +63,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogHeight) diff --git a/src/app/dialogs/tools/dialogline.cpp b/src/app/dialogs/tools/dialogline.cpp index 6ff5fd3a3..231c62dce 100644 --- a/src/app/dialogs/tools/dialogline.cpp +++ b/src/app/dialogs/tools/dialogline.cpp @@ -42,7 +42,7 @@ DialogLine::DialogLine(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0), typeLine(QString()) { ui->setupUi(this); - InitOkCansel(ui); + InitOkCancel(ui); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); diff --git a/src/app/dialogs/tools/dialogline.h b/src/app/dialogs/tools/dialogline.h index ce22b1ff7..62b61d918 100644 --- a/src/app/dialogs/tools/dialogline.h +++ b/src/app/dialogs/tools/dialogline.h @@ -57,6 +57,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogLine) diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 577decc3c..4914312c0 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -44,7 +44,7 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent { ui->setupUi(this); number = 0; - InitOkCansel(ui); + InitOkCancel(ui); labelEditNamePoint = ui->labelEditNamePoint; flagName = false; @@ -209,7 +209,7 @@ void DialogLineIntersect::P2Line2Changed(int index) */ void DialogLineIntersect::CheckState() { - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagName && flagPoint); } diff --git a/src/app/dialogs/tools/dialoglineintersect.h b/src/app/dialogs/tools/dialoglineintersect.h index 91775f608..be7f400f6 100644 --- a/src/app/dialogs/tools/dialoglineintersect.h +++ b/src/app/dialogs/tools/dialoglineintersect.h @@ -63,6 +63,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} void P1Line1Changed( int index); void P2Line1Changed( int index); void P1Line2Changed( int index); diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index def5affab..4d53897d7 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -36,16 +36,18 @@ * @param parent parent widget */ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), angle(0), firstPointId(0), secondPointId(0) + :DialogTool(data, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()), + formula(QString()), angle(0), firstPointId(0), secondPointId(0), formulaBaseHeight(0) { ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancelApply(ui); + + this->formulaBaseHeight=ui->plainTextEditFormula->height(); flagFormula = false; flagName = false; @@ -61,7 +63,34 @@ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogNormal::PutVal); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogNormal::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogNormal::NamePointChanged); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogNormal::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogNormal::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogNormal::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogNormal::FormulaTextChanged() +{ + this->FormulaChangedPlainText(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogNormal::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGNORMAL_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGNORMAL_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next")); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -107,14 +136,27 @@ void DialogNormal::ChoosedObject(quint32 id, const Valentina::Scenes &type) * @brief DialogAccepted save data and emit signal about closed dialog. */ void DialogNormal::DialogAccepted() +{ + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogNormal::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogNormal::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); angle = ui->doubleSpinBoxAngle->value(); firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- @@ -158,7 +200,12 @@ void DialogNormal::setAngle(const qreal &value) void DialogNormal::setFormula(const QString &value) { formula = qApp->FormulaToUser(value); - ui->lineEditFormula->setText(formula); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formula); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialognormal.h b/src/app/dialogs/tools/dialognormal.h index a3c29a207..a2e8f7336 100644 --- a/src/app/dialogs/tools/dialognormal.h +++ b/src/app/dialogs/tools/dialognormal.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGNORMAL_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogNormal; @@ -66,6 +67,18 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogNormal) @@ -92,6 +105,14 @@ private: /** @brief secondPointId id second point of line */ quint32 secondPointId; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialognormal.ui b/src/app/dialogs/tools/dialognormal.ui index 781fd810d..a135ba36a 100644 --- a/src/app/dialogs/tools/dialognormal.ui +++ b/src/app/dialogs/tools/dialognormal.ui @@ -74,17 +74,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for calculation of length of normal + + + 40 + 20 + - + @@ -150,6 +150,56 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -601,14 +651,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula lineEditNamePoint comboBoxFirstPoint comboBoxSecondPoint diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index c66b8955c..f56b92013 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -38,60 +38,93 @@ * @param parent parent widget */ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *parent) - :DialogTool(data, parent), ui(), number(0), pointName(QString()), radius(QString()), center(0), - firstPoint(0), secondPoint(0) + :DialogTool(data, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), radius(QString()), + center(0), firstPoint(0), secondPoint(0), formulaBaseHeight(0) { - ui.setupUi(this); - listWidget = ui.listWidget; - labelResultCalculation = ui.labelResultCalculation; - labelDescription = ui.labelDescription; - radioButtonSizeGrowth = ui.radioButtonSizeGrowth; - radioButtonStandardTable = ui.radioButtonStandardTable; - radioButtonIncrements = ui.radioButtonIncrements; - radioButtonLengthLine = ui.radioButtonLengthLine; - radioButtonLengthArc = ui.radioButtonLengthArc; - radioButtonLengthCurve = ui.radioButtonLengthSpline; - lineEditFormula = ui.lineEditFormula; - labelEditFormula = ui.labelEditFormula; - labelEditNamePoint = ui.labelEditNamePoint; + ui->setupUi(this); + InitVariables(ui); + listWidget = ui->listWidget; + labelResultCalculation = ui->labelResultCalculation; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandardTable = ui->radioButtonStandardTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; + plainTextEditFormula = ui->plainTextEditFormula; + labelEditFormula = ui->labelEditFormula; + labelEditNamePoint = ui->labelEditNamePoint; - bOk = ui.buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + InitOkCancelApply(ui); + + /* bOk = ui.buttonBox->button(QDialogButtonBox::Ok); + SCASSERT(bOk != nullptr); connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); - Q_CHECK_PTR(bCansel); + SCASSERT(bCansel != nullptr); connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); - + */ flagFormula = false; flagName = false; CheckState(); - FillComboBoxPoints(ui.comboBoxCenter); - FillComboBoxPoints(ui.comboBoxFirstPoint); - FillComboBoxPoints(ui.comboBoxSecondPoint); + FillComboBoxPoints(ui->comboBoxCenter); + FillComboBoxPoints(ui->comboBoxFirstPoint); + FillComboBoxPoints(ui->comboBoxSecondPoint); - connect(ui.toolButtonPutHere, &QPushButton::clicked, this, &DialogPointOfContact::PutHere); - connect(ui.listWidget, &QListWidget::itemDoubleClicked, this, &DialogPointOfContact::PutVal); - connect(ui.listWidget, &QListWidget::currentRowChanged, this, &DialogPointOfContact::ValChenged); + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogPointOfContact::PutHere); + connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogPointOfContact::PutVal); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogPointOfContact::ValChenged); if (qApp->patternType() == Pattern::Standard) { SizeHeight(); - connect(ui.radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogTool::SizeHeight); + connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogTool::SizeHeight); } else { radioButtonSizeGrowth->setVisible(false); Measurements(); } - connect(ui.radioButtonStandardTable, &QRadioButton::clicked, this, &DialogPointOfContact::Measurements); - connect(ui.radioButtonIncrements, &QRadioButton::clicked, this, &DialogPointOfContact::Increments); - connect(ui.radioButtonLengthLine, &QRadioButton::clicked, this, &DialogPointOfContact::LengthLines); - connect(ui.radioButtonLengthArc, &QRadioButton::clicked, this, &DialogPointOfContact::LengthArcs); - connect(ui.radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogPointOfContact::LengthCurves); - connect(ui.toolButtonEqual, &QPushButton::clicked, this, &DialogPointOfContact::EvalFormula); - connect(ui.lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfContact::NamePointChanged); - connect(ui.lineEditFormula, &QLineEdit::textChanged, this, &DialogPointOfContact::FormulaChanged); + connect(ui->radioButtonStandardTable, &QRadioButton::clicked, this, &DialogPointOfContact::Measurements); + connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogPointOfContact::Increments); + connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogPointOfContact::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogPointOfContact::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogPointOfContact::LengthCurves); + connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogPointOfContact::EvalFormula); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfContact::NamePointChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogPointOfContact::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogPointOfContact::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfContact::FormulaTextChanged() +{ + this->FormulaChangedPlainText(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfContact::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGPOINTOFCONTACT_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGPOINTOFCONTACT_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -107,10 +140,10 @@ void DialogPointOfContact::ChoosedObject(quint32 id, const Valentina::Scenes &ty const VPointF *point = data->GeometricObject(id); if (number == 0) { - qint32 index = ui.comboBoxFirstPoint->findText(point->name()); + qint32 index = ui->comboBoxFirstPoint->findText(point->name()); if ( index != -1 ) { // -1 for not found - ui.comboBoxFirstPoint->setCurrentIndex(index); + ui->comboBoxFirstPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select second point of line")); return; @@ -118,10 +151,10 @@ void DialogPointOfContact::ChoosedObject(quint32 id, const Valentina::Scenes &ty } if (number == 1) { - qint32 index = ui.comboBoxSecondPoint->findText(point->name()); + qint32 index = ui->comboBoxSecondPoint->findText(point->name()); if ( index != -1 ) { // -1 for not found - ui.comboBoxSecondPoint->setCurrentIndex(index); + ui->comboBoxSecondPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select point of center of arc")); return; @@ -129,10 +162,10 @@ void DialogPointOfContact::ChoosedObject(quint32 id, const Valentina::Scenes &ty } if (number == 2) { - qint32 index = ui.comboBoxCenter->findText(point->name()); + qint32 index = ui->comboBoxCenter->findText(point->name()); if ( index != -1 ) { // -1 for not found - ui.comboBoxCenter->setCurrentIndex(index); + ui->comboBoxCenter->setCurrentIndex(index); number = 0; emit ToolTip(""); } @@ -150,14 +183,27 @@ void DialogPointOfContact::ChoosedObject(quint32 id, const Valentina::Scenes &ty */ void DialogPointOfContact::DialogAccepted() { - pointName = ui.lineEditNamePoint->text(); - radius = ui.lineEditFormula->text(); - center = getCurrentObjectId(ui.comboBoxCenter); - firstPoint = getCurrentObjectId(ui.comboBoxFirstPoint); - secondPoint = getCurrentObjectId(ui.comboBoxSecondPoint); + this->SaveData(); emit DialogClosed(QDialog::Accepted); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfContact::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfContact::SaveData() +{ + pointName = ui->lineEditNamePoint->text(); + radius = ui->plainTextEditFormula->toPlainText(); + radius.replace("\n"," "); + center = getCurrentObjectId(ui->comboBoxCenter); + firstPoint = getCurrentObjectId(ui->comboBoxFirstPoint); + secondPoint = getCurrentObjectId(ui->comboBoxSecondPoint); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setSecondPoint set id second point @@ -166,7 +212,7 @@ void DialogPointOfContact::DialogAccepted() */ void DialogPointOfContact::setSecondPoint(const quint32 &value, const quint32 &id) { - setCurrentPointId(ui.comboBoxSecondPoint, secondPoint, value, id); + setCurrentPointId(ui->comboBoxSecondPoint, secondPoint, value, id); } //--------------------------------------------------------------------------------------------------------------------- @@ -177,7 +223,7 @@ void DialogPointOfContact::setSecondPoint(const quint32 &value, const quint32 &i */ void DialogPointOfContact::setFirstPoint(const quint32 &value, const quint32 &id) { - setCurrentPointId(ui.comboBoxFirstPoint, firstPoint, value, id); + setCurrentPointId(ui->comboBoxFirstPoint, firstPoint, value, id); } //--------------------------------------------------------------------------------------------------------------------- @@ -188,7 +234,7 @@ void DialogPointOfContact::setFirstPoint(const quint32 &value, const quint32 &id */ void DialogPointOfContact::setCenter(const quint32 &value, const quint32 &id) { - setCurrentPointId(ui.comboBoxCenter, center, value, id); + setCurrentPointId(ui->comboBoxCenter, center, value, id); center = value; } @@ -200,7 +246,12 @@ void DialogPointOfContact::setCenter(const quint32 &value, const quint32 &id) void DialogPointOfContact::setRadius(const QString &value) { radius = value; - ui.lineEditFormula->setText(radius); + // increase height if needed. + if (radius.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(radius); } //--------------------------------------------------------------------------------------------------------------------- @@ -211,5 +262,5 @@ void DialogPointOfContact::setRadius(const QString &value) void DialogPointOfContact::setPointName(const QString &value) { pointName = value; - ui.lineEditNamePoint->setText(pointName); + ui->lineEditNamePoint->setText(pointName); } diff --git a/src/app/dialogs/tools/dialogpointofcontact.h b/src/app/dialogs/tools/dialogpointofcontact.h index a9f8ea652..cc96ef85c 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.h +++ b/src/app/dialogs/tools/dialogpointofcontact.h @@ -32,6 +32,11 @@ #include "ui_dialogpointofcontact.h" #include "dialogtool.h" +#define DIALOGPOINTOFCONTACT_MAX_FORMULA_HEIGHT 64 +namespace Ui +{ + class DialogPointOfContact; +} /** * @brief The DialogPointOfContact class dialog for ToolPointOfContact. Help create point and edit option. */ @@ -58,11 +63,23 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogPointOfContact) /** @brief ui keeps information about user interface */ - Ui::DialogPointOfContact ui; + Ui::DialogPointOfContact *ui; /** @brief number number of handled objects */ qint32 number; @@ -81,6 +98,14 @@ private: /** @brief secondPoint id second point of line */ quint32 secondPoint; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogpointofcontact.ui b/src/app/dialogs/tools/dialogpointofcontact.ui index 532648eeb..147765832 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.ui +++ b/src/app/dialogs/tools/dialogpointofcontact.ui @@ -74,17 +74,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for calculation of radius of arc + + + 40 + 20 + - + @@ -150,6 +150,56 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -441,14 +491,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula lineEditNamePoint comboBoxCenter comboBoxFirstPoint diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index b4f4f00ee..3551b7d06 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -44,7 +44,7 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, QWi { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogpointofintersection.h b/src/app/dialogs/tools/dialogpointofintersection.h index bde7baa1c..326c5fe91 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.h +++ b/src/app/dialogs/tools/dialogpointofintersection.h @@ -57,6 +57,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogPointOfIntersection) diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index d47629bea..fdfdd08bf 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -40,16 +40,18 @@ */ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0) + typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0), formulaBaseHeight(0) { ui->setupUi(this); number = 0; InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancelApply(ui); + + this->formulaBaseHeight=ui->plainTextEditFormula->height(); flagFormula = false; flagName = false; @@ -64,7 +66,36 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogShoulderPoint::PutVal); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogShoulderPoint::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogShoulderPoint::NamePointChanged); - connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogShoulderPoint::FormulaChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogShoulderPoint::FormulaTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogShoulderPoint::DeployFormulaTextEdit); + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::FormulaTextChanged() +{ + this->FormulaChangedPlainText(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < DIALOGSHOULDERPOINT_MAX_FORMULA_HEIGHT) + { + ui->plainTextEditFormula->setFixedHeight(DIALOGSHOULDERPOINT_MAX_FORMULA_HEIGHT); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-next.png"))); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -128,14 +159,27 @@ void DialogShoulderPoint::ChoosedObject(quint32 id, const Valentina::Scenes &typ * @brief DialogAccepted save data and emit signal about closed dialog. */ void DialogShoulderPoint::DialogAccepted() +{ + this->SaveData(); + emit DialogClosed(QDialog::Accepted); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::DialogApply() +{ + this->SaveData(); + emit DialogApplied(); +} +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); + formula.replace("\n"," "); p1Line = getCurrentObjectId(ui->comboBoxP1Line); p2Line = getCurrentObjectId(ui->comboBoxP2Line); pShoulder = getCurrentObjectId(ui->comboBoxPShoulder); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- @@ -179,7 +223,12 @@ void DialogShoulderPoint::setP1Line(const quint32 &value, const quint32 &id) void DialogShoulderPoint::setFormula(const QString &value) { formula = qApp->FormulaToUser(value); - ui->lineEditFormula->setText(formula); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployFormulaTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formula); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogshoulderpoint.h b/src/app/dialogs/tools/dialogshoulderpoint.h index 3684c8d02..6e7e947fc 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.h +++ b/src/app/dialogs/tools/dialogshoulderpoint.h @@ -31,6 +31,7 @@ #include "dialogtool.h" +#define DIALOGSHOULDERPOINT_MAX_FORMULA_HEIGHT 64 namespace Ui { class DialogShoulderPoint; @@ -66,6 +67,18 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); + /** + * @brief FormulaTextChanged when formula text changes for validation and calc + */ + void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogShoulderPoint) @@ -92,6 +105,14 @@ private: /** @brief pShoulder id shoulder point */ quint32 pShoulder; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeight; + + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogshoulderpoint.ui b/src/app/dialogs/tools/dialogshoulderpoint.ui index 27bd11328..a9ed3dc8b 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.ui +++ b/src/app/dialogs/tools/dialogshoulderpoint.ui @@ -74,17 +74,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for calculation of length of line + + + 40 + 20 + - + @@ -150,6 +150,56 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -462,14 +512,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula lineEditNamePoint comboBoxP1Line comboBoxP2Line diff --git a/src/app/dialogs/tools/dialogsinglepoint.cpp b/src/app/dialogs/tools/dialogsinglepoint.cpp index c508eadbd..e7caa1d34 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.cpp +++ b/src/app/dialogs/tools/dialogsinglepoint.cpp @@ -43,7 +43,7 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) ui->doubleSpinBoxX->setRange(0, qApp->fromPixel(SceneSize)); ui->doubleSpinBoxY->setRange(0, qApp->fromPixel(SceneSize)); labelEditNamePoint = ui->labelEditName; - InitOkCansel(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogsinglepoint.h b/src/app/dialogs/tools/dialogsinglepoint.h index 5c99e7e79..6ee4ff4fb 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.h +++ b/src/app/dialogs/tools/dialogsinglepoint.h @@ -51,6 +51,10 @@ public: public slots: void mousePress(const QPointF &scenePos); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogSinglePoint) diff --git a/src/app/dialogs/tools/dialogspline.cpp b/src/app/dialogs/tools/dialogspline.cpp index 9b0ccae43..f8dfabe04 100644 --- a/src/app/dialogs/tools/dialogspline.cpp +++ b/src/app/dialogs/tools/dialogspline.cpp @@ -43,7 +43,7 @@ DialogSpline::DialogSpline(const VContainer *data, QWidget *parent) kAsm1(1), kAsm2(1), kCurve(1) { ui->setupUi(this); - InitOkCansel(ui); + InitOkCancel(ui); FillComboBoxPoints(ui->comboBoxP1); FillComboBoxPoints(ui->comboBoxP4); diff --git a/src/app/dialogs/tools/dialogspline.h b/src/app/dialogs/tools/dialogspline.h index 979e29dc2..8d6cd84ca 100644 --- a/src/app/dialogs/tools/dialogspline.h +++ b/src/app/dialogs/tools/dialogspline.h @@ -69,6 +69,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogSpline) diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index 7dbf8e54c..80bdcea4e 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -41,7 +41,7 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) { ui->setupUi(this); - InitOkCansel(ui); + InitOkCancel(ui); bOk->setEnabled(false); FillComboBoxPoints(ui->comboBoxPoint); @@ -159,7 +159,7 @@ void DialogSplinePath::Angle1Changed(qreal index) { qint32 row = ui->listWidget->currentRow(); QListWidgetItem *item = ui->listWidget->item( row ); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); p.SetAngle1(index); DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2()); @@ -175,7 +175,7 @@ void DialogSplinePath::Angle2Changed(qreal index) { qint32 row = ui->listWidget->currentRow(); QListWidgetItem *item = ui->listWidget->item( row ); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); p.SetAngle2(index); DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2()); diff --git a/src/app/dialogs/tools/dialogsplinepath.h b/src/app/dialogs/tools/dialogsplinepath.h index 30e0b4c60..41bf0282c 100644 --- a/src/app/dialogs/tools/dialogsplinepath.h +++ b/src/app/dialogs/tools/dialogsplinepath.h @@ -52,6 +52,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} void PointChanged(int row); void currentPointChanged( int index ); void Angle1Changed(qreal index ); diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 92496546e..8be3dd860 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -43,13 +43,13 @@ */ DialogTool::DialogTool(const VContainer *data, QWidget *parent) :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(nullptr), - bOk(nullptr), spinBoxAngle(nullptr), lineEditFormula(nullptr), listWidget(nullptr), - labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), + bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), lineEditFormula(nullptr), plainTextEditFormula(nullptr), + listWidget(nullptr), labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), - radioButtonLengthCurve(nullptr), lineStyles(QStringList()) + radioButtonLengthCurve(nullptr), lineStyles(QStringList()), associatedTool(nullptr) { - Q_CHECK_PTR(data); + SCASSERT(data != nullptr); timerFormula = new QTimer(this); connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula); //Keep synchronize with VAbstractTool styles list!!! @@ -97,7 +97,7 @@ void DialogTool::showEvent(QShowEvent *event) */ void DialogTool::FillComboBoxPoints(QComboBox *box, const quint32 &id) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); const QHash *objs = data->DataGObjects(); QHashIterator i(*objs); QMap list; @@ -120,7 +120,7 @@ void DialogTool::FillComboBoxPoints(QComboBox *box, const quint32 &id) const //--------------------------------------------------------------------------------------------------------------------- void DialogTool::FillComboBoxArcs(QComboBox *box, const quint32 &id, ComboMode::ComboBoxCutArc cut) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); const QHash *objs = data->DataGObjects(); QHashIterator i(*objs); QMap list; @@ -164,7 +164,7 @@ void DialogTool::FillComboBoxArcs(QComboBox *box, const quint32 &id, ComboMode:: */ void DialogTool::FillComboBoxSplines(QComboBox *box, const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); const QHash *objs = data->DataGObjects(); QHashIterator i(*objs); QMap list; @@ -208,7 +208,7 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const quint32 &id, ComboMod */ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); const QHash *objs = data->DataGObjects(); QHashIterator i(*objs); QMap list; @@ -250,7 +250,7 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const quint32 &id, Comb */ void DialogTool::FillComboBoxTypeLine(QComboBox *box) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); box->addItems(lineStyles); box->setCurrentIndex(1); } @@ -347,16 +347,36 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const quint32 &value) const */ void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) { - Q_CHECK_PTR(lineEdit); - Q_CHECK_PTR(listWidget); + SCASSERT(lineEdit != nullptr); + SCASSERT(listWidget != nullptr); QListWidgetItem *item = listWidget->currentItem(); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); + int pos = lineEdit->cursorPosition(); lineEdit->setText(lineEdit->text().insert(lineEdit->cursorPosition(), item->text())); lineEdit->setFocus(); lineEdit->setCursorPosition(pos + item->text().size()); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget) +{ + SCASSERT(plainTextEdit != nullptr); + SCASSERT(listWidget != nullptr); + QListWidgetItem *item = listWidget->currentItem(); + SCASSERT(item != nullptr); + + QTextCursor cursor = plainTextEdit->textCursor(); + cursor.insertText(item->text()); + plainTextEdit->setTextCursor(cursor); + /* + int pos = lineEdit->cursorPosition(); + lineEdit->setText(lineEdit->text().insert(lineEdit->cursorPosition(), item->text())); + lineEdit->setFocus(); + lineEdit->setCursorPosition(pos + item->text().size()); + */ +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ValFormulaChanged handle change formula @@ -366,9 +386,9 @@ void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) */ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) { - Q_CHECK_PTR(edit); - Q_CHECK_PTR(timer); - Q_CHECK_PTR(labelEditFormula); + SCASSERT(edit != nullptr); + SCASSERT(timer != nullptr); + SCASSERT(labelEditFormula != nullptr); if (edit->text().isEmpty()) { flag = false; @@ -380,6 +400,23 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) } timer->start(1000); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *timer) +{ + SCASSERT(edit != nullptr); + SCASSERT(timer != nullptr); + SCASSERT(labelEditFormula != nullptr); + if (edit->toPlainText().isEmpty()) + { + flag = false; + CheckState(); + QPalette palette = labelEditFormula->palette(); + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + labelEditFormula->setPalette(palette); + return; + } + timer->start(1000); +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -391,10 +428,10 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) */ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) { - Q_CHECK_PTR(edit); - Q_CHECK_PTR(timer); - Q_CHECK_PTR(label); - Q_CHECK_PTR(labelEditFormula); + SCASSERT(edit != nullptr); + SCASSERT(timer != nullptr); + SCASSERT(label != nullptr); + SCASSERT(labelEditFormula != nullptr); QPalette palette = labelEditFormula->palette(); if (edit->text().isEmpty()) { @@ -447,16 +484,70 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setCurrentPointId set current point id in combobox - * @param box combobox - * @param pointId save current point id - * @param value point id - * @param id don't show this id in list - */ +void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label) +{ + SCASSERT(edit != nullptr); + SCASSERT(timer != nullptr); + SCASSERT(label != nullptr); + SCASSERT(labelEditFormula != nullptr); + QPalette palette = labelEditFormula->palette(); + if (edit->toPlainText().isEmpty()) + { + flag = false; + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + } + else + { + try + { + // Replace line return with spaces for calc + QString formula = edit->toPlainText(); + formula.replace("\n"," "); + formula = qApp->FormulaFromUser(formula); + Calculator *cal = new Calculator(data); + const qreal result = cal->EvalFormula(formula); + delete cal; + + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName()); + bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool(); + + if (osSeparatorValue) + { + QLocale loc = QLocale::system(); + label->setText(loc.toString(result)); + } + else + { + QLocale loc = QLocale(QLocale::C); + label->setText(loc.toString(result)); + } + flag = true; + palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); + emit ToolTip(""); + } + catch(qmu::QmuParserError &e) + { + label->setText(tr("Error")); + flag = false; + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + emit ToolTip("Parser error: "+e.GetMsg()); + qDebug() << "\nMath parser error:\n" + << "--------------------------------------\n" + << "Message: " << e.GetMsg() << "\n" + << "Expression: " << e.GetExpr() << "\n" + << "--------------------------------------"; + } + } + CheckState(); + timer->stop(); + labelEditFormula->setPalette(palette); +} + +//--------------------------------------------------------------------------------------------------------------------- void DialogTool::setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); FillComboBoxPoints(box, id); pointId = value; ChangeCurrentData(box, value); @@ -474,7 +565,7 @@ void DialogTool::setCurrentPointId(QComboBox *box, quint32 &pointId, const quint void DialogTool::setCurrentSplineId(QComboBox *box, quint32 &splineId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); FillComboBoxSplines(box, id, cut); splineId = value; ChangeCurrentData(box, value); @@ -492,7 +583,7 @@ void DialogTool::setCurrentSplineId(QComboBox *box, quint32 &splineId, const qui void DialogTool::setCurrentArcId(QComboBox *box, quint32 &arcId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutArc cut) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); FillComboBoxArcs(box, id, cut); arcId = value; ChangeCurrentData(box, value); @@ -510,7 +601,7 @@ void DialogTool::setCurrentArcId(QComboBox *box, quint32 &arcId, const quint32 & void DialogTool::setCurrentSplinePathId(QComboBox *box, quint32 &splinePathId, const quint32 &value, const quint32 &id, ComboMode::ComboBoxCutSpline cut) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); FillComboBoxSplinesPath(box, id, cut); splinePathId = value; ChangeCurrentData(box, value); @@ -524,7 +615,7 @@ void DialogTool::setCurrentSplinePathId(QComboBox *box, quint32 &splinePathId, c */ quint32 DialogTool::getCurrentObjectId(QComboBox *box) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); qint32 index = box->currentIndex(); Q_ASSERT(index != -1); if (index != -1) @@ -540,9 +631,9 @@ quint32 DialogTool::getCurrentObjectId(QComboBox *box) const //--------------------------------------------------------------------------------------------------------------------- bool DialogTool::ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip) { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); const VPointF *point = data->GeometricObject(id); - Q_CHECK_PTR(point); + SCASSERT(point != nullptr); const qint32 index = box->findText(point->name()); if ( index != -1 ) { // -1 for not found @@ -561,7 +652,7 @@ bool DialogTool::ChoosedPoint(const quint32 &id, QComboBox *box, const QString & */ void DialogTool::FillList(QComboBox *box, const QMap &list) const { - Q_CHECK_PTR(box); + SCASSERT(box != nullptr); box->clear(); QMapIterator iter(list); @@ -578,8 +669,13 @@ void DialogTool::FillList(QComboBox *box, const QMap &list) co */ void DialogTool::CheckState() { - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagFormula && flagName); + // In case dialog hasn't apply button + if ( bApply != nullptr) + { + bApply->setEnabled(flagFormula && flagName); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -600,7 +696,7 @@ void DialogTool::ChoosedObject(quint32 id, const Valentina::Scenes &type) */ void DialogTool::NamePointChanged() { - Q_CHECK_PTR(labelEditNamePoint); + SCASSERT(labelEditNamePoint != nullptr); QLineEdit* edit = qobject_cast(sender()); if (edit) { @@ -653,6 +749,15 @@ void DialogTool::FormulaChanged() ValFormulaChanged(flagFormula, edit, timerFormula); } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::FormulaChangedPlainText() +{ + QPlainTextEdit* edit = qobject_cast(sender()); + if (edit) + { + ValFormulaChanged(flagFormula, edit, timerFormula); + } +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -660,7 +765,7 @@ void DialogTool::FormulaChanged() */ void DialogTool::ArrowUp() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(90); } @@ -670,7 +775,7 @@ void DialogTool::ArrowUp() */ void DialogTool::ArrowDown() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(270); } @@ -680,7 +785,7 @@ void DialogTool::ArrowDown() */ void DialogTool::ArrowLeft() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(180); } @@ -690,7 +795,7 @@ void DialogTool::ArrowLeft() */ void DialogTool::ArrowRight() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(0); } @@ -700,7 +805,7 @@ void DialogTool::ArrowRight() */ void DialogTool::ArrowLeftUp() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(135); } @@ -710,7 +815,7 @@ void DialogTool::ArrowLeftUp() */ void DialogTool::ArrowLeftDown() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(225); } @@ -720,7 +825,7 @@ void DialogTool::ArrowLeftDown() */ void DialogTool::ArrowRightUp() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(45); } @@ -730,7 +835,7 @@ void DialogTool::ArrowRightUp() */ void DialogTool::ArrowRightDown() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(315); } @@ -740,9 +845,9 @@ void DialogTool::ArrowRightDown() */ void DialogTool::EvalFormula() { - Q_CHECK_PTR(lineEditFormula); - Q_CHECK_PTR(labelResultCalculation); - Eval(lineEditFormula, flagFormula, timerFormula, labelResultCalculation); + SCASSERT(plainTextEditFormula != nullptr); + SCASSERT(labelResultCalculation != nullptr); + Eval(plainTextEditFormula, flagFormula, timerFormula, labelResultCalculation); } //--------------------------------------------------------------------------------------------------------------------- @@ -751,7 +856,7 @@ void DialogTool::EvalFormula() */ void DialogTool::SizeHeight() { - Q_CHECK_PTR(listWidget); + SCASSERT(listWidget != nullptr); disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); listWidget->clear(); @@ -820,7 +925,7 @@ void DialogTool::Increments() */ void DialogTool::PutHere() { - PutValHere(lineEditFormula, listWidget); + PutValHere(plainTextEditFormula, listWidget); } //--------------------------------------------------------------------------------------------------------------------- @@ -830,13 +935,17 @@ void DialogTool::PutHere() */ void DialogTool::PutVal(QListWidgetItem *item) { - Q_CHECK_PTR(lineEditFormula); - Q_CHECK_PTR(item); - int pos = lineEditFormula->cursorPosition(); + SCASSERT(plainTextEditFormula != nullptr); + SCASSERT(item != nullptr); + QTextCursor cursor = plainTextEditFormula->textCursor(); + cursor.insertText(item->text()); + plainTextEditFormula->setTextCursor(cursor); + /*int pos = plainTextEditFormula->cursorPosition(); lineEditFormula->setText(lineEditFormula->text().insert(lineEditFormula->cursorPosition(), item->text())); lineEditFormula->setFocus(); lineEditFormula->setCursorPosition(pos + item->text().size()); + */ } //--------------------------------------------------------------------------------------------------------------------- @@ -846,14 +955,14 @@ void DialogTool::PutVal(QListWidgetItem *item) */ void DialogTool::ValChenged(int row) { - Q_CHECK_PTR(listWidget); - Q_CHECK_PTR(labelDescription); - Q_CHECK_PTR(radioButtonSizeGrowth); - Q_CHECK_PTR(radioButtonStandardTable); - Q_CHECK_PTR(radioButtonIncrements); - Q_CHECK_PTR(radioButtonLengthLine); - Q_CHECK_PTR(radioButtonLengthArc); - Q_CHECK_PTR(radioButtonLengthCurve); + SCASSERT(listWidget != nullptr); + SCASSERT(labelDescription != nullptr); + SCASSERT(radioButtonSizeGrowth != nullptr); + SCASSERT(radioButtonStandardTable != nullptr); + SCASSERT(radioButtonIncrements != nullptr); + SCASSERT(radioButtonLengthLine != nullptr); + SCASSERT(radioButtonLengthArc != nullptr); + SCASSERT(radioButtonLengthCurve != nullptr); if (listWidget->count() == 0) { return; @@ -919,12 +1028,12 @@ void DialogTool::ValChenged(int row) */ void DialogTool::UpdateList() { - Q_CHECK_PTR(radioButtonSizeGrowth); - Q_CHECK_PTR(radioButtonStandardTable); - Q_CHECK_PTR(radioButtonIncrements); - Q_CHECK_PTR(radioButtonLengthLine); - Q_CHECK_PTR(radioButtonLengthArc); - Q_CHECK_PTR(radioButtonLengthCurve); + SCASSERT(radioButtonSizeGrowth != nullptr); + SCASSERT(radioButtonStandardTable != nullptr); + SCASSERT(radioButtonIncrements != nullptr); + SCASSERT(radioButtonLengthLine != nullptr); + SCASSERT(radioButtonLengthArc != nullptr); + SCASSERT(radioButtonLengthCurve != nullptr); if (radioButtonSizeGrowth->isChecked()) { @@ -960,7 +1069,7 @@ void DialogTool::UpdateList() template void DialogTool::ShowVariable(const QHash *var) { - Q_CHECK_PTR(listWidget); + SCASSERT(listWidget != nullptr); disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); listWidget->clear(); @@ -983,3 +1092,9 @@ void DialogTool::ShowVariable(const QHash *var) connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); listWidget->setCurrentRow (0); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::DialogApply() +{ + +} diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 029191aec..ecdf78202 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -41,6 +41,8 @@ class QListWidgetItem; class QLineEdit; class QListWidget; class VContainer; +class QPlainTextEdit; +class VAbstractTool; namespace ComboMode { @@ -65,12 +67,18 @@ class DialogTool : public QDialog public: DialogTool(const VContainer *data, QWidget *parent = nullptr); virtual ~DialogTool() {} + VAbstractTool* GetAssociatedTool(); + void SetAssociatedTool(VAbstractTool* tool); signals: /** * @brief DialogClosed signal dialog closed * @param result keep result */ void DialogClosed(int result); + /** + * @brief DialogApplied emit signal dialog apply changes + */ + void DialogApplied(); /** * @brief ToolTip emit tooltipe for tool * @param toolTip text tooltipe @@ -80,8 +88,16 @@ public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); void NamePointChanged(); virtual void DialogAccepted(); + /** + * @brief DialogApply save data and emit signal DialogApplied. + */ + virtual void DialogApply(); virtual void DialogRejected(); void FormulaChanged(); + /** + * @brief FormulaChangedPlainText check formula (plain text editor editor) + */ + void FormulaChangedPlainText(); void ArrowUp(); void ArrowDown(); void ArrowLeft(); @@ -122,12 +138,15 @@ protected: /** @brief bOk button ok */ QPushButton *bOk; + /** @brief bApply button apply */ + QPushButton *bApply; + /** @brief spinBoxAngle spinbox for angle */ QDoubleSpinBox *spinBoxAngle; /** @brief lineEditFormula linEdit for formula */ QLineEdit *lineEditFormula; - + QPlainTextEdit *plainTextEditFormula; /** @brief listWidget listWidget with variables */ QListWidget *listWidget; @@ -182,7 +201,10 @@ protected: void ChangeCurrentText(QComboBox *box, const QString &value); void ChangeCurrentData(QComboBox *box, const quint32 &value) const; void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget); + void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget); void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); + void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); + void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); void setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const; void setCurrentSplineId(QComboBox *box, quint32 &splineId, const quint32 &value, const quint32 &id, @@ -197,7 +219,7 @@ protected: template void InitArrow(T *ui) { - Q_CHECK_PTR(ui); + SCASSERT(ui != nullptr); spinBoxAngle = ui->doubleSpinBoxAngle; connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, &DialogTool::ArrowDown); connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, &DialogTool::ArrowUp); @@ -240,18 +262,50 @@ protected: connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves); } template - void InitOkCansel(T *ui) + /** + * @brief InitOkCancelApply initialise OK / Cancel and Apply buttons + * @param ui Dialog container + */ + void InitOkCancelApply(T *ui) + { + InitOkCancel(ui); + bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + SCASSERT(bApply != nullptr); + connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); + } + template + /** + * @brief InitOkCancel initialise OK and Cancel buttons + * @param ui Dialog container + */ + void InitOkCancel(T *ui) { bOk = ui->buttonBox->button(QDialogButtonBox::Ok); - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); - QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); - Q_CHECK_PTR(bCansel); - connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected); + QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel); + SCASSERT(bCancel != nullptr); + connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); } + /** + * @brief associatedTool vdrawtool associated with opened dialog. + */ + VAbstractTool* associatedTool; private: void FillList(QComboBox *box, const QMap &list)const; }; +//--------------------------------------------------------------------------------------------------------------------- +inline VAbstractTool *DialogTool::GetAssociatedTool() +{ + return this->associatedTool; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void DialogTool::SetAssociatedTool(VAbstractTool *tool) +{ + this->associatedTool=tool; +} + #endif // DIALOGTOOL_H diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index ec87941e2..c2977052b 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -43,7 +43,7 @@ DialogTriangle::DialogTriangle(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogtriangle.h b/src/app/dialogs/tools/dialogtriangle.h index 17561c879..0281b1f2e 100644 --- a/src/app/dialogs/tools/dialogtriangle.h +++ b/src/app/dialogs/tools/dialogtriangle.h @@ -63,6 +63,10 @@ public: public slots: virtual void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogTriangle) diff --git a/src/app/dialogs/tools/dialoguniondetails.cpp b/src/app/dialogs/tools/dialoguniondetails.cpp index 2aa4a22b5..d11281b13 100644 --- a/src/app/dialogs/tools/dialoguniondetails.cpp +++ b/src/app/dialogs/tools/dialoguniondetails.cpp @@ -42,7 +42,7 @@ DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) numberP(0), p1(0), p2(0) { ui->setupUi(this); - InitOkCansel(ui); + InitOkCancel(ui); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialoguniondetails.h b/src/app/dialogs/tools/dialoguniondetails.h index faf401d1c..4e72252cd 100644 --- a/src/app/dialogs/tools/dialoguniondetails.h +++ b/src/app/dialogs/tools/dialoguniondetails.h @@ -53,6 +53,10 @@ public: public slots: void ChoosedObject(quint32 id, const Valentina::Scenes &type); virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} private: Q_DISABLE_COPY(DialogUnionDetails) diff --git a/src/app/geometry/vequidistant.cpp b/src/app/geometry/vequidistant.cpp index a3f7268e4..a6cb7555f 100644 --- a/src/app/geometry/vequidistant.cpp +++ b/src/app/geometry/vequidistant.cpp @@ -39,7 +39,7 @@ //--------------------------------------------------------------------------------------------------------------------- QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer *data) const { - Q_CHECK_PTR(data); + SCASSERT(data != nullptr); VDetail detail = data->GetDetail(idDetail); QVector points; QVector pointsEkv; diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index dfedb197b..5f1093561 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -185,7 +185,7 @@ void MainWindow::ActionNewPP() connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); QHash* tools = doc->getTools(); - Q_CHECK_PTR(tools); + SCASSERT(tools != nullptr); tools->insert(id, spoint); VDrawTool::AddRecord(id, Valentina::SinglePointTool, doc); SetEnableTool(true); @@ -254,12 +254,50 @@ void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString & { if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())) { - Q_CHECK_PTR(tButton); + SCASSERT(tButton != nullptr); tButton->setChecked(true); } } } +//--------------------------------------------------------------------------------------------------------------------- +template +/** + * @brief SetToolButtonWithApply set tool and show dialog. + * @param checked true if tool button checked. + * @param t tool type. + * @param cursor path tool cursor icon. + * @param toolTip first tooltipe. + * @param closeDialogSlot function to handle close of dialog. + * @param applyDialogSlot function to handle apply in dialog. + */ +void MainWindow::SetToolButtonWithApply(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, + Func closeDialogSlot, Func2 applyDialogSlot) +{ + if (checked) + { + CancelTool(); + tool = t; + QPixmap pixmap(cursor); + QCursor cur(pixmap, 2, 3); + view->setCursor(cur); + helpLabel->setText(toolTip); + dialogTool = new Dialog(pattern, this); + connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChoosedObject); + connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); + connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot); + connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); + connect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); + } + else + { + if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())) + { + SCASSERT(tButton != nullptr); + tButton->setChecked(true); + } + } +} //--------------------------------------------------------------------------------------------------------------------- /** * @brief ClosedDialog handle close dialog @@ -268,7 +306,7 @@ void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString & template void MainWindow::ClosedDialog(int result) { - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); if (result == QDialog::Accepted) { DrawTool::Create(dialogTool, currentScene, doc, pattern); @@ -276,6 +314,59 @@ void MainWindow::ClosedDialog(int result) ArrowTool(); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ClosedDialogWithApply handle close dialog that has apply button + * @param result result working dialog. + */ +template +void MainWindow::ClosedDialogWithApply(int result) +{ + SCASSERT(dialogTool != nullptr); + if (result == QDialog::Accepted) + { + // Only create tool if not already created with apply + if (dialogTool->GetAssociatedTool() == nullptr) + { + dialogTool->SetAssociatedTool( + dynamic_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + } + else + { // Or update associated tool with data + VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + vtool->FullUpdateFromGuiApply(); + } + } + if (dialogTool->GetAssociatedTool() != nullptr) + { + VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + vtool->DialogLinkDestroy(); + } + ArrowTool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialog handle apply in dialog + */ +template +void MainWindow::ApplyDialog() +{ + SCASSERT(dialogTool != nullptr); + + // Only create tool if not already created with apply + if (dialogTool->GetAssociatedTool() == nullptr) + { + dialogTool->SetAssociatedTool( + static_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + } + else + { // Or update associated tool with data + VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + vtool->FullUpdateFromGuiApply(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolEndLine handler tool endLine. @@ -283,8 +374,17 @@ void MainWindow::ClosedDialog(int result) */ void MainWindow::ToolEndLine(bool checked) { - SetToolButton(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), - &MainWindow::ClosedDialogEndLine); + SetToolButtonWithApply(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), + &MainWindow::ClosedDialogEndLine,&MainWindow::ApplyDialogEndLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogEndLine actions after apply in DialogEndLine. + */ +void MainWindow::ApplyDialogEndLine() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -294,7 +394,7 @@ void MainWindow::ToolEndLine(bool checked) */ void MainWindow::ClosedDialogEndLine(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -325,8 +425,17 @@ void MainWindow::ClosedDialogLine(int result) */ void MainWindow::ToolAlongLine(bool checked) { - SetToolButton(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", - tr("Select point"), &MainWindow::ClosedDialogAlongLine); + SetToolButtonWithApply(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", + tr("Select point"), &MainWindow::ClosedDialogAlongLine, &MainWindow::ApplyDialogAlongLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogAlongLine actions after apply in DialogAlongLine. + */ +void MainWindow::ApplyDialogAlongLine() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -336,7 +445,7 @@ void MainWindow::ToolAlongLine(bool checked) */ void MainWindow::ClosedDialogAlongLine(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -346,8 +455,18 @@ void MainWindow::ClosedDialogAlongLine(int result) */ void MainWindow::ToolShoulderPoint(bool checked) { - SetToolButton(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", - tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint); + SetToolButtonWithApply(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint, + &MainWindow::ApplyDialogShoulderPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogShoulderPoint actions after apply in DialogShoulderPoint. + */ +void MainWindow::ApplyDialogShoulderPoint() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -357,7 +476,7 @@ void MainWindow::ToolShoulderPoint(bool checked) */ void MainWindow::ClosedDialogShoulderPoint(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -367,8 +486,18 @@ void MainWindow::ClosedDialogShoulderPoint(int result) */ void MainWindow::ToolNormal(bool checked) { - SetToolButton(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png", - tr("Select first point of line"), &MainWindow::ClosedDialogNormal); + SetToolButtonWithApply(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogNormal, + &MainWindow::ApplyDialogNormal); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogNormal actions after apply in DialogNormal. + */ +void MainWindow::ApplyDialogNormal() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -378,7 +507,7 @@ void MainWindow::ToolNormal(bool checked) */ void MainWindow::ClosedDialogNormal(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -388,8 +517,18 @@ void MainWindow::ClosedDialogNormal(int result) */ void MainWindow::ToolBisector(bool checked) { - SetToolButton(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png", - tr("Select first point of angle"), &MainWindow::ClosedDialogBisector); + SetToolButtonWithApply(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png", + tr("Select first point of angle"), &MainWindow::ClosedDialogBisector, + &MainWindow::ApplyDialogBisector); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogBisector actions after apply in DialogBisector. + */ +void MainWindow::ApplyDialogBisector() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -399,7 +538,7 @@ void MainWindow::ToolBisector(bool checked) */ void MainWindow::ClosedDialogBisector(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -472,8 +611,18 @@ void MainWindow::ClosedDialogCutSpline(int result) */ void MainWindow::ToolArc(bool checked) { - SetToolButton(checked, Valentina::ArcTool, ":/cursor/arc_cursor.png", - tr("Select point of center of arc"), &MainWindow::ClosedDialogArc); + SetToolButtonWithApply(checked, Valentina::ArcTool, ":/cursor/arc_cursor.png", + tr("Select point of center of arc"), &MainWindow::ClosedDialogArc, + &MainWindow::ApplyDialogArc); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogArc actions after apply in DialogArc. + */ +void MainWindow::ApplyDialogArc() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -483,7 +632,7 @@ void MainWindow::ToolArc(bool checked) */ void MainWindow::ClosedDialogArc(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -536,8 +685,18 @@ void MainWindow::ClosedDialogCutSplinePath(int result) */ void MainWindow::ToolPointOfContact(bool checked) { - SetToolButton(checked, Valentina::PointOfContact, ":/cursor/pointcontact_cursor.png", - tr("Select first point of line"), &MainWindow::ClosedDialogPointOfContact); + SetToolButtonWithApply(checked, Valentina::PointOfContact, ":/cursor/pointcontact_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogPointOfContact, + &MainWindow::ApplyDialogPointOfContact); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogPointOfContact actions after apply in DialogPointOfContact. + */ +void MainWindow::ApplyDialogPointOfContact() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -547,7 +706,7 @@ void MainWindow::ToolPointOfContact(bool checked) */ void MainWindow::ClosedDialogPointOfContact(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -671,8 +830,17 @@ void MainWindow::ClosedDialogUnionDetails(int result) */ void MainWindow::ToolCutArc(bool checked) { - SetToolButton(checked, Valentina::CutArcTool, ":/cursor/arc_cut_cursor.png", tr("Select arc"), - &MainWindow::ClosedDialogCutArc); + SetToolButtonWithApply(checked, Valentina::CutArcTool, ":/cursor/arc_cut_cursor.png", + tr("Select arc"), &MainWindow::ClosedDialogCutArc, &MainWindow::ApplyDialogCutArc); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogCutArc actions after apply in DialogCutArc. + */ +void MainWindow::ApplyDialogCutArc() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -682,7 +850,7 @@ void MainWindow::ToolCutArc(bool checked) */ void MainWindow::ClosedDialogCutArc(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -692,7 +860,7 @@ void MainWindow::ClosedDialogCutArc(int result) void MainWindow::About() { DialogAboutApp * about_dialog = new DialogAboutApp(this); - about_dialog->setAttribute(Qt::WA_DeleteOnClose,true); + about_dialog->setAttribute(Qt::WA_DeleteOnClose, true); about_dialog->show(); } @@ -742,6 +910,14 @@ void MainWindow::PatternProperties() proper.exec(); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::EditPatternCode() +{ + DialogPatternXmlEdit *Pattern = new DialogPatternXmlEdit (this, doc); + Pattern->setAttribute(Qt::WA_DeleteOnClose, true); + Pattern->show(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief showEvent handle after show window. @@ -1488,7 +1664,9 @@ void MainWindow::SetEnableWidgets(bool enable) } ui->actionTable->setEnabled(enable); ui->actionHistory->setEnabled(enable); - ui->actionZoomIn->setEnabled(enable); + ui->actionPattern_properties->setEnabled(enable); + ui->actionEdit_pattern_code->setEnabled(enable); + ui->actionZoomIn->setEnabled(enable); ui->actionZoomOut->setEnabled(enable); } @@ -1851,6 +2029,8 @@ void MainWindow::CreateActions() connect(ui->actionPreferences, &QAction::triggered, this, &MainWindow::Preferences); connect(ui->actionPattern_properties, &QAction::triggered, this, &MainWindow::PatternProperties); ui->actionPattern_properties->setEnabled(false); + connect(ui->actionEdit_pattern_code, &QAction::triggered, this, &MainWindow::EditPatternCode); + ui->actionEdit_pattern_code->setEnabled(false); //Actions for recent files loaded by a main window application. for (int i = 0; i < MaxRecentFiles; ++i) diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 09a548a0b..d8a17b4eb 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -103,17 +103,24 @@ public slots: void ToolCutArc(bool checked); void ClosedDialogEndLine(int result); + void ApplyDialogEndLine(); void ClosedDialogLine(int result); void ClosedDialogAlongLine(int result); + void ApplyDialogAlongLine(); void ClosedDialogShoulderPoint(int result); + void ApplyDialogShoulderPoint(); void ClosedDialogNormal(int result); + void ApplyDialogNormal(); void ClosedDialogBisector(int result); + void ApplyDialogBisector(); void ClosedDialogLineIntersect(int result); void ClosedDialogSpline(int result); void ClosedDialogArc(int result); + void ApplyDialogArc(); void ClosedDialogSplinePath(int result); void ClosedDialogCutSplinePath(int result); void ClosedDialogPointOfContact(int result); + void ApplyDialogPointOfContact(); void ClosedDialogDetail(int result); void ClosedDialogHeight(int result); void ClosedDialogTriangle(int result); @@ -121,6 +128,7 @@ public slots: void ClosedDialogUnionDetails(int result); void ClosedDialogCutSpline(int result); void ClosedDialogCutArc(int result); + void ApplyDialogCutArc(); void About(); void AboutQt(); @@ -129,6 +137,10 @@ public slots: void ShowToolTip(const QString &toolTip); void OpenRecentFile(); void Clear(); + /** + * @brief Edit XML code of pattern + */ + void EditPatternCode(); void FullParseFile(); signals: /** @@ -217,10 +229,15 @@ private: template void SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot); - + template + void SetToolButtonWithApply(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, + Func closeDialogSlot, Func2 applyDialogSlot); template void ClosedDialog(int result); - + template + void ClosedDialogWithApply(int result); + template + void ApplyDialog(); bool SavePattern(const QString &curFile); void AutoSavePattern(); void setCurrentFile(const QString &fileName); diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index 3ba2bcbfe..3cab66be0 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -699,6 +699,7 @@ + @@ -1056,6 +1057,11 @@ Zoom out + + + Edit pattern XML code + + diff --git a/src/app/options.h b/src/app/options.h index d832eb9ac..de38a59af 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -340,6 +340,8 @@ extern const QString in_Oprt; } \ #endif /* Q_OS_WIN32 */ +#else // define but disable this function if debugging is not set +#define SCASSERT(cond) qt_noop(); #endif /* QT_NO_DEBUG */ #endif // OPTIONS_H diff --git a/src/app/share/resources/icons/win.icon.theme/16x16/actions/go-down.png b/src/app/share/resources/icons/win.icon.theme/16x16/actions/go-down.png new file mode 100644 index 000000000..a74287892 Binary files /dev/null and b/src/app/share/resources/icons/win.icon.theme/16x16/actions/go-down.png differ diff --git a/src/app/share/resources/icons/win.icon.theme/24x24/actions/go-down.png b/src/app/share/resources/icons/win.icon.theme/24x24/actions/go-down.png new file mode 100755 index 000000000..d53d924b9 Binary files /dev/null and b/src/app/share/resources/icons/win.icon.theme/24x24/actions/go-down.png differ diff --git a/src/app/share/resources/icons/win.icon.theme/24x24/actions/go-next.png b/src/app/share/resources/icons/win.icon.theme/24x24/actions/go-next.png old mode 100644 new mode 100755 index 8eabaafe8..989e8d435 Binary files a/src/app/share/resources/icons/win.icon.theme/24x24/actions/go-next.png and b/src/app/share/resources/icons/win.icon.theme/24x24/actions/go-next.png differ diff --git a/src/app/share/resources/icons/win.icon.theme/24x24/actions/process-stop.png b/src/app/share/resources/icons/win.icon.theme/24x24/actions/process-stop.png old mode 100644 new mode 100755 index fc2c75622..95cc6e0e1 Binary files a/src/app/share/resources/icons/win.icon.theme/24x24/actions/process-stop.png and b/src/app/share/resources/icons/win.icon.theme/24x24/actions/process-stop.png differ diff --git a/src/app/share/resources/icons/win.icon.theme/32x32/actions/go-down.png b/src/app/share/resources/icons/win.icon.theme/32x32/actions/go-down.png new file mode 100755 index 000000000..e44828414 Binary files /dev/null and b/src/app/share/resources/icons/win.icon.theme/32x32/actions/go-down.png differ diff --git a/src/app/stable.h b/src/app/stable.h index c49a78395..b41aa249f 100644 --- a/src/app/stable.h +++ b/src/app/stable.h @@ -39,9 +39,6 @@ #if defined __cplusplus /* Add C++ includes here */ -#ifdef Q_CC_MSVC -#define _USE_MATH_DEFINES -#endif #ifdef QT_CORE_LIB # include diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp index 64e5af6eb..a71eaa79e 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/tablewindow.cpp @@ -97,7 +97,7 @@ void TableWindow::AddDetail() { tableScene->clearSelection(); VItem* Detail = listDetails[indexDetail]; - Q_CHECK_PTR(Detail); + SCASSERT(Detail != nullptr); connect(Detail, &VItem::itemOut, this, &TableWindow::itemOut); connect(Detail, &VItem::itemColliding, this, &TableWindow::itemColliding); connect(this, &TableWindow::LengthChanged, Detail, &VItem::LengthChanged); @@ -329,7 +329,7 @@ void TableWindow::itemColliding(QList list, int number) if (lis.size()-2 <= 0) { VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(i) ); - Q_CHECK_PTR(bitem); + SCASSERT(bitem != nullptr); bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); listCollidingItems.removeAt(i); } @@ -338,7 +338,7 @@ void TableWindow::itemColliding(QList list, int number) else if (listCollidingItems.size()==1) { VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(0) ); - Q_CHECK_PTR(bitem); + SCASSERT(bitem != nullptr); bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); listCollidingItems.clear(); collidingItems = true; diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 7cfa9665e..ad67f9a89 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -124,6 +124,25 @@ void VDrawTool::FullUpdateFromGui(int result) dialog = nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +void VDrawTool::FullUpdateFromGuiApply() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + SaveDialog(domElement); + + emit FullUpdateTree(); + emit toolhaveChange(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDrawTool::DialogLinkDestroy() +{ + this->dialog=nullptr; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetFactor set current scale factor of scene. @@ -170,9 +189,9 @@ qreal VDrawTool::CheckFormula(QString &formula, VContainer *data) //Need delete dialog here because parser in dialog don't allow use correct separator for parsing here. //Don't know why. delete dialog; - Calculator *cal = new Calculator(data); - result = cal->EvalFormula(formula); - delete cal;//Here can be memory leak, but dialog already check this formula and probability very low. + Calculator *cal1 = new Calculator(data); + result = cal1->EvalFormula(formula); + delete cal1;//Here can be memory leak, but dialog already check this formula and probability very low. } else { diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index 3718d2253..60bc4950a 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -30,7 +30,6 @@ #define VDRAWTOOL_H #include "../vabstracttool.h" - #include #include #include @@ -51,6 +50,10 @@ public: /** @brief setDialog set dialog when user want change tool option. */ virtual void setDialog() {} + /** + * @brief DialogLinkDestroy removes dialog pointer + */ + virtual void DialogLinkDestroy(); void ignoreContextMenu(bool enable); static qreal CheckFormula(QString &formula, VContainer *data); @@ -59,6 +62,10 @@ public slots: virtual void ChangedActivDraw(const QString &newName); void ChangedNameDraw(const QString &oldName, const QString &newName); virtual void FullUpdateFromGui(int result); + /** + * @brief FullUpdateFromGuiApply refresh tool data after change in options but do not delete dialog + */ + virtual void FullUpdateFromGuiApply(); virtual void SetFactor(qreal factor); protected: /** @brief ignoreContextMenuEvent ignore or not context menu events. */ @@ -119,6 +126,7 @@ protected: connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject, dialog, &DialogTool::ChoosedObject); connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGui); + connect(dialog, &DialogTool::DialogApplied, tool, &Tool::FullUpdateFromGuiApply); if (ignoreFullUpdate == false) { connect(doc, &VPattern::FullUpdateFromFile, dialog, &DialogTool::UpdateList); diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 40e046af1..bb9d8da92 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -133,9 +133,9 @@ void VToolAlongLine::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolAlongLine::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogAlongLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); @@ -146,9 +146,9 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement) //--------------------------------------------------------------------------------------------------------------------- void VToolAlongLine::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogAlongLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); dialogTool->setFormula(formula); @@ -158,22 +158,28 @@ void VToolAlongLine::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolAlongLine* VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogAlongLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); QString formula = dialogTool->getFormula(); const quint32 firstPointId = dialogTool->getFirstPointId(); const quint32 secondPointId = dialogTool->getSecondPointId(); const QString typeLine = dialogTool->getTypeLine(); const QString pointName = dialogTool->getPointName(); - Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, + VToolAlongLine *point=nullptr; + point = Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, +VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) @@ -212,5 +218,7 @@ void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const Q doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); + return point; } + return nullptr; } diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index 8276c3954..a5f9795bb 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -64,7 +64,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolAlongLine* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -81,7 +81,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, + static VToolAlongLine* Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 6cc624f2e..20f752e71 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -63,9 +63,9 @@ VToolArc::VToolArc(VPattern *doc, VContainer *data, quint32 id, const Valentina: //--------------------------------------------------------------------------------------------------------------------- void VToolArc::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogArc *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VArc *arc = VAbstractTool::data.GeometricObject(id); dialogTool->SetCenter(arc->GetCenter().id()); dialogTool->SetF1(arc->GetFormulaF1()); @@ -74,20 +74,26 @@ void VToolArc::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolArc* VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogArc *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const quint32 center = dialogTool->GetCenter(); QString radius = dialogTool->GetRadius(); QString f1 = dialogTool->GetF1(); QString f2 = dialogTool->GetF2(); - Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Valentina::FromGui); + VToolArc* point = nullptr; + point=Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, +VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { @@ -122,7 +128,9 @@ void VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &radius, connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); doc->AddTool(id, toolArc); doc->IncrementReferens(center); + return toolArc; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -269,9 +277,9 @@ void VToolArc::keyReleaseEvent(QKeyEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolArc::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogArc *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetCenter())); doc->SetAttribute(domElement, AttrRadius, dialogTool->GetRadius()); doc->SetAttribute(domElement, AttrAngle1, dialogTool->GetF1()); diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index b601a230a..88e3ef809 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -61,7 +61,7 @@ public: * @param doc dom document container * @param data container with variables */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolArc* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool form GUI. * @param _id tool id, 0 if tool doesn't exist yet. @@ -75,7 +75,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, + static VToolArc* Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString TagName; diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 03b8aef62..891444211 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -75,9 +75,9 @@ QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secon //--------------------------------------------------------------------------------------------------------------------- void VToolBisector::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogBisector *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); dialogTool->setFormula(formula); @@ -88,24 +88,30 @@ void VToolBisector::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, +VToolBisector* VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogBisector *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); QString formula = dialogTool->getFormula(); const quint32 firstPointId = dialogTool->getFirstPointId(); const quint32 secondPointId = dialogTool->getSecondPointId(); const quint32 thirdPointId = dialogTool->getThirdPointId(); const QString typeLine = dialogTool->getTypeLine(); const QString pointName = dialogTool->getPointName(); - Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data, + VToolBisector *point = nullptr; + point=Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolBisector::Create(const quint32 _id, QString &formula, const quint32 &firstPointId, +VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, @@ -146,7 +152,9 @@ void VToolBisector::Create(const quint32 _id, QString &formula, const quint32 &f doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); doc->IncrementReferens(thirdPointId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -233,9 +241,9 @@ void VToolBisector::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolBisector::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogBisector *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index f49d6fa5b..1640da520 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -75,7 +75,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolBisector* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -93,7 +93,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, QString &formula, const quint32 &firstPointId, + static VToolBisector* Create(const quint32 _id, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const quint32 &thirdPointId, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index b40651ae9..4a93a3dbd 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -69,9 +69,9 @@ VToolCutArc::VToolCutArc(VPattern *doc, VContainer *data, const quint32 &id, con //--------------------------------------------------------------------------------------------------------------------- void VToolCutArc::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutArc *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *point = VAbstractTool::data.GeometricObject(id); dialogTool->setFormula(formula); dialogTool->setArcId(arcId, id); @@ -79,20 +79,26 @@ void VToolCutArc::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, +VToolCutArc* VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutArc *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); const quint32 arcId = dialogTool->getArcId(); - Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + VToolCutArc* point = nullptr; + point=Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId, +VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { @@ -151,7 +157,9 @@ void VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &f doc->AddTool(arc1id, point); doc->AddTool(arc2id, point); doc->IncrementReferens(arcId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -252,9 +260,9 @@ void VToolCutArc::RefreshGeometry() //--------------------------------------------------------------------------------------------------------------------- void VToolCutArc::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutArc *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); doc->SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId())); diff --git a/src/app/tools/drawTools/vtoolcutarc.h b/src/app/tools/drawTools/vtoolcutarc.h index 53dbcd740..f53e64523 100644 --- a/src/app/tools/drawTools/vtoolcutarc.h +++ b/src/app/tools/drawTools/vtoolcutarc.h @@ -65,7 +65,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolCutArc* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -80,7 +80,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId, + static VToolCutArc* Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); static const QString ToolType; diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 83240a84a..ebb3ffc26 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -70,9 +70,9 @@ VToolCutSpline::VToolCutSpline(VPattern *doc, VContainer *data, const quint32 &i //--------------------------------------------------------------------------------------------------------------------- void VToolCutSpline::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutSpline *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *point = VAbstractTool::data.GeometricObject(id); dialogTool->setFormula(formula); dialogTool->setSplineId(splineId, id); @@ -83,9 +83,9 @@ void VToolCutSpline::setDialog() void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutSpline *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); const quint32 splineId = dialogTool->getSplineId(); @@ -254,9 +254,9 @@ void VToolCutSpline::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolCutSpline::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutSpline *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); doc->SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId())); diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 63b25a8bf..f49a1f58e 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -71,9 +71,9 @@ VToolCutSplinePath::VToolCutSplinePath(VPattern *doc, VContainer *data, const qu //--------------------------------------------------------------------------------------------------------------------- void VToolCutSplinePath::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutSplinePath *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *point = VAbstractTool::data.GeometricObject(id); dialogTool->setFormula(formula); dialogTool->setSplinePathId(splinePathId, id); @@ -83,9 +83,9 @@ void VToolCutSplinePath::setDialog() //--------------------------------------------------------------------------------------------------------------------- void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutSplinePath *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); const quint32 splinePathId = dialogTool->getSplinePathId(); @@ -99,7 +99,7 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VSplinePath *splPath = data->GeometricObject(splinePathId); - Q_CHECK_PTR(splPath); + SCASSERT(splPath != nullptr); const qreal result = CheckFormula(formula, data); @@ -329,9 +329,9 @@ void VToolCutSplinePath::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolCutSplinePath::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogCutSplinePath *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); doc->SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogTool->getSplinePathId())); diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 95d2c384c..d14f1fb81 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -55,9 +55,9 @@ VToolEndLine::VToolEndLine(VPattern *doc, VContainer *data, const quint32 &id, //--------------------------------------------------------------------------------------------------------------------- void VToolEndLine::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogEndLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); dialogTool->setFormula(formula); @@ -67,26 +67,32 @@ void VToolEndLine::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data) +VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogEndLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool); const QString pointName = dialogTool->getPointName(); const QString typeLine = dialogTool->getTypeLine(); QString formula = dialogTool->getFormula(); const qreal angle = dialogTool->getAngle(); const quint32 basePointId = dialogTool->getBasePointId(); - Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, - Valentina::FromGui); + + VToolEndLine *point = nullptr; + point=Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, + Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, - QString &formula, const qreal &angle, const quint32 &basePointId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) +VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, + QString &formula, const qreal &angle, const quint32 &basePointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { const VPointF *basePoint = data->GeometricObject(basePointId); QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); @@ -118,7 +124,9 @@ void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QSt connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(basePointId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -187,9 +195,9 @@ void VToolEndLine::RefreshDataInFile() //--------------------------------------------------------------------------------------------------------------------- void VToolEndLine::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogEndLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 17a272f19..2e65d6e89 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -63,8 +63,9 @@ public: * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. + * @return the created tool */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolEndLine *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -80,8 +81,9 @@ public: * @param data container with variables. * @param parse parser file mode. * @param typeCreation way we create this tool. + * @return the created tool */ - static void Create(const quint32 _id, const QString &pointName, const QString &typeLine, + static VToolEndLine *Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, const qreal &angle, const quint32 &basePointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); diff --git a/src/app/tools/drawTools/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index 240e1eb84..3dcaecda7 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -52,9 +52,9 @@ VToolHeight::VToolHeight(VPattern *doc, VContainer *data, const quint32 &id, con //--------------------------------------------------------------------------------------------------------------------- void VToolHeight::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogHeight *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); dialogTool->setBasePointId(basePointId, id); @@ -67,9 +67,9 @@ void VToolHeight::setDialog() void VToolHeight::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogHeight *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); disconnect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogHeight::UpdateList); const QString pointName = dialogTool->getPointName(); const QString typeLine = dialogTool->getTypeLine(); @@ -199,9 +199,9 @@ void VToolHeight::RefreshDataInFile() //--------------------------------------------------------------------------------------------------------------------- void VToolHeight::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogHeight *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index c7a2418f5..a613c8e3b 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -64,9 +64,9 @@ VToolLine::VToolLine(VPattern *doc, VContainer *data, quint32 id, quint32 firstP //--------------------------------------------------------------------------------------------------------------------- void VToolLine::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); dialogTool->setFirstPoint(firstPoint); dialogTool->setSecondPoint(secondPoint); dialogTool->setTypeLine(typeLine); @@ -75,9 +75,9 @@ void VToolLine::setDialog() //--------------------------------------------------------------------------------------------------------------------- void VToolLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const quint32 firstPoint = dialogTool->getFirstPoint(); const quint32 secondPoint = dialogTool->getSecondPoint(); const QString typeLine = dialogTool->getTypeLine(); @@ -89,9 +89,9 @@ void VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, const quin const QString &typeLine, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) { - Q_CHECK_PTR(scene); - Q_CHECK_PTR(doc); - Q_CHECK_PTR(data); + SCASSERT(scene != nullptr); + SCASSERT(doc != nullptr); + SCASSERT(data != nullptr); quint32 id = _id; if (typeCreation == Valentina::FromGui) { @@ -245,9 +245,9 @@ void VToolLine::keyReleaseEvent(QKeyEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolLine::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogLine *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 768563317..629120bcc 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -54,9 +54,9 @@ VToolLineIntersect::VToolLineIntersect(VPattern *doc, VContainer *data, const qu //--------------------------------------------------------------------------------------------------------------------- void VToolLineIntersect::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogLineIntersect *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setP1Line1(p1Line1); dialogTool->setP2Line1(p2Line1); @@ -68,9 +68,9 @@ void VToolLineIntersect::setDialog() //--------------------------------------------------------------------------------------------------------------------- void VToolLineIntersect::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogLineIntersect *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const quint32 p1Line1Id = dialogTool->getP1Line1(); const quint32 p2Line1Id = dialogTool->getP2Line1(); const quint32 p1Line2Id = dialogTool->getP1Line2(); @@ -218,9 +218,9 @@ void VToolLineIntersect::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolLineIntersect::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogLineIntersect *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrP1Line1, QString().setNum(dialogTool->getP1Line1())); doc->SetAttribute(domElement, AttrP2Line1, QString().setNum(dialogTool->getP2Line1())); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index c575a750d..0f8790662 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -54,9 +54,9 @@ VToolNormal::VToolNormal(VPattern *doc, VContainer *data, const quint32 &id, con //--------------------------------------------------------------------------------------------------------------------- void VToolNormal::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogNormal *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); dialogTool->setFormula(formula); @@ -67,23 +67,29 @@ void VToolNormal::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolNormal::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolNormal* VToolNormal::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogNormal *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); QString formula = dialogTool->getFormula(); const quint32 firstPointId = dialogTool->getFirstPointId(); const quint32 secondPointId = dialogTool->getSecondPointId(); const QString typeLine = dialogTool->getTypeLine(); const QString pointName = dialogTool->getPointName(); const qreal angle = dialogTool->getAngle(); - Create(0, formula, firstPointId, secondPointId, typeLine, pointName, angle, 5, 10, scene, doc, data, + VToolNormal *point = nullptr; + point=Create(0, formula, firstPointId, secondPointId, typeLine, pointName, angle, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolNormal::Create(const quint32 _id, QString &formula, const quint32 &firstPointId, +VToolNormal* VToolNormal::Create(const quint32 _id, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const QString &typeLine, const QString &pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, @@ -122,7 +128,9 @@ void VToolNormal::Create(const quint32 _id, QString &formula, const quint32 &fir doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -219,9 +227,9 @@ void VToolNormal::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolNormal::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogNormal *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); diff --git a/src/app/tools/drawTools/vtoolnormal.h b/src/app/tools/drawTools/vtoolnormal.h index f054b3280..16d84e471 100644 --- a/src/app/tools/drawTools/vtoolnormal.h +++ b/src/app/tools/drawTools/vtoolnormal.h @@ -66,7 +66,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolNormal* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -84,7 +84,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, QString &formula, const quint32 &firstPointId, + static VToolNormal* Create(const quint32 _id, QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const QString &typeLine, const QString &pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 79a9ed9c4..74fc8d18f 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -54,9 +54,9 @@ VToolPointOfContact::VToolPointOfContact(VPattern *doc, VContainer *data, const //--------------------------------------------------------------------------------------------------------------------- void VToolPointOfContact::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogPointOfContact *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setRadius(arcRadius); dialogTool->setCenter(center, id); @@ -93,22 +93,28 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e } //--------------------------------------------------------------------------------------------------------------------- -void VToolPointOfContact::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolPointOfContact* VToolPointOfContact::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogPointOfContact *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); QString radius = dialogTool->getRadius(); const quint32 center = dialogTool->getCenter(); const quint32 firstPointId = dialogTool->getFirstPoint(); const quint32 secondPointId = dialogTool->getSecondPoint(); const QString pointName = dialogTool->getPointName(); - Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, scene, doc, data, + VToolPointOfContact *point = nullptr; + point=Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolPointOfContact::Create(const quint32 _id, QString &radius, const quint32 ¢er, const quint32 &firstPointId, +VToolPointOfContact* VToolPointOfContact::Create(const quint32 _id, QString &radius, const quint32 ¢er, const quint32 &firstPointId, const quint32 &secondPointId, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation) @@ -152,7 +158,9 @@ void VToolPointOfContact::Create(const quint32 _id, QString &radius, const quint doc->IncrementReferens(center); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -236,9 +244,9 @@ void VToolPointOfContact::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolPointOfContact::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogPointOfContact *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrRadius, dialogTool->getRadius()); doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->getCenter())); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index 5a95e6b19..04670c7e2 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -74,7 +74,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolPointOfContact* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -91,7 +91,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, QString &arcRadius, const quint32 ¢er, + static VToolPointOfContact* Create(const quint32 _id, QString &arcRadius, const quint32 ¢er, const quint32 &firstPointId, const quint32 &secondPointId, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index 0fd0ef287..b70231326 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -52,9 +52,9 @@ VToolPointOfIntersection::VToolPointOfIntersection(VPattern *doc, VContainer *da //--------------------------------------------------------------------------------------------------------------------- void VToolPointOfIntersection::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogPointOfIntersection *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setFirstPointId(firstPointId, id); dialogTool->setSecondPointId(secondPointId, id); @@ -65,9 +65,9 @@ void VToolPointOfIntersection::setDialog() void VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogPointOfIntersection *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const quint32 firstPointId = dialogTool->getFirstPointId(); const quint32 secondPointId = dialogTool->getSecondPointId(); const QString pointName = dialogTool->getPointName(); @@ -178,9 +178,9 @@ void VToolPointOfIntersection::RefreshDataInFile() //--------------------------------------------------------------------------------------------------------------------- void VToolPointOfIntersection::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogPointOfIntersection *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index e9b079991..d20f0c60b 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -53,9 +53,9 @@ VToolShoulderPoint::VToolShoulderPoint(VPattern *doc, VContainer *data, const qu //--------------------------------------------------------------------------------------------------------------------- void VToolShoulderPoint::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogShoulderPoint *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); dialogTool->setFormula(formula); @@ -95,23 +95,29 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li } //--------------------------------------------------------------------------------------------------------------------- -void VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolShoulderPoint* VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogShoulderPoint *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool); QString formula = dialogTool->getFormula(); const quint32 p1Line = dialogTool->getP1Line(); const quint32 p2Line = dialogTool->getP2Line(); const quint32 pShoulder = dialogTool->getPShoulder(); const QString typeLine = dialogTool->getTypeLine(); const QString pointName = dialogTool->getPointName(); - Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data, + VToolShoulderPoint * point = nullptr; + point=Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- -void VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint32 &p1Line, +VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint32 &p1Line, const quint32 &p2Line, const quint32 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, @@ -155,7 +161,9 @@ void VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint doc->IncrementReferens(p1Line); doc->IncrementReferens(p2Line); doc->IncrementReferens(pShoulder); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -242,9 +250,9 @@ void VToolShoulderPoint::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolShoulderPoint::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogShoulderPoint *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index 9e9462d9d..e9eec3e8a 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -76,7 +76,7 @@ public: * @param doc dom document container. * @param data container with variables. */ - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolShoulderPoint* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); /** * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. @@ -94,7 +94,7 @@ public: * @param parse parser file mode. * @param typeCreation way we create this tool. */ - static void Create(const quint32 _id, QString &formula, const quint32 &p1Line, const quint32 &p2Line, + static VToolShoulderPoint* Create(const quint32 _id, QString &formula, const quint32 &p1Line, const quint32 &p2Line, const quint32 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation); diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 78479971f..5091c67f8 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -61,9 +61,9 @@ VToolSinglePoint::VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSinglePoint *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setData(p->name(), p->toQPointF()); } @@ -158,9 +158,9 @@ void VToolSinglePoint::decrementReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSinglePoint *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); QPointF p = dialogTool->getPoint(); QString name = dialogTool->getName(); doc->SetAttribute(domElement, AttrName, name); diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 3bb061074..7d14ea5ce 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -76,9 +76,9 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Vale //--------------------------------------------------------------------------------------------------------------------- void VToolSpline::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSpline *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VSpline *spl = VAbstractTool::data.GeometricObject(id); dialogTool->setP1(spl->GetP1().id()); dialogTool->setP4(spl->GetP4().id()); @@ -93,9 +93,9 @@ void VToolSpline::setDialog() void VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSpline *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const quint32 p1 = dialogTool->getP1(); const quint32 p4 = dialogTool->getP4(); const qreal kAsm1 = dialogTool->getKAsm1(); @@ -227,9 +227,9 @@ void VToolSpline::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolSpline::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSpline *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); VPointF point1 = *VAbstractTool::data.GeometricObject(dialogTool->getP1()); VPointF point4 = *VAbstractTool::data.GeometricObject(dialogTool->getP4()); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 337d5c869..d4eac7fb4 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -76,9 +76,9 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co //--------------------------------------------------------------------------------------------------------------------- void VToolSplinePath::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSplinePath *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VSplinePath *splPath = VAbstractTool::data.GeometricObject(id); dialogTool->SetPath(*splPath); } @@ -86,9 +86,9 @@ void VToolSplinePath::setDialog() //--------------------------------------------------------------------------------------------------------------------- void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSplinePath *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); VSplinePath *path = new VSplinePath(dialogTool->GetPath()); for (qint32 i = 0; i < path->CountPoint(); ++i) { @@ -287,9 +287,9 @@ void VToolSplinePath::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolSplinePath::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogSplinePath *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); VSplinePath splPath = dialogTool->GetPath(); RefreshSplinePath(splPath); diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index c80391cd5..22b7a29bf 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -53,9 +53,9 @@ VToolTriangle::VToolTriangle(VPattern *doc, VContainer *data, const quint32 &id, //--------------------------------------------------------------------------------------------------------------------- void VToolTriangle::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogTriangle *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setAxisP1Id(axisP1Id, id); dialogTool->setAxisP2Id(axisP2Id, id); @@ -68,9 +68,9 @@ void VToolTriangle::setDialog() void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogTriangle *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); const quint32 axisP1Id = dialogTool->getAxisP1Id(); const quint32 axisP2Id = dialogTool->getAxisP2Id(); const quint32 firstPointId = dialogTool->getFirstPointId(); @@ -239,9 +239,9 @@ void VToolTriangle::RefreshDataInFile() //--------------------------------------------------------------------------------------------------------------------- void VToolTriangle::SaveDialog(QDomElement &domElement) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogTriangle *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrAxisP1, QString().setNum(dialogTool->getAxisP1Id())); doc->SetAttribute(domElement, AttrAxisP2, QString().setNum(dialogTool->getAxisP2Id())); diff --git a/src/app/tools/nodeDetails/vnodearc.cpp b/src/app/tools/nodeDetails/vnodearc.cpp index 63f520b12..a4e84b312 100644 --- a/src/app/tools/nodeDetails/vnodearc.cpp +++ b/src/app/tools/nodeDetails/vnodearc.cpp @@ -66,7 +66,7 @@ void VNodeArc::Create(VPattern *doc, VContainer *data, quint32 id, quint32 idArc doc->IncrementReferens(idTool); //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); arc->setParent(tool); } else diff --git a/src/app/tools/nodeDetails/vnodepoint.cpp b/src/app/tools/nodeDetails/vnodepoint.cpp index fe872bef4..9e58cc23f 100644 --- a/src/app/tools/nodeDetails/vnodepoint.cpp +++ b/src/app/tools/nodeDetails/vnodepoint.cpp @@ -78,7 +78,7 @@ void VNodePoint::Create(VPattern *doc, VContainer *data, quint32 id, quint32 idP doc->IncrementReferens(idTool); //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); point->setParent(tool); } else diff --git a/src/app/tools/nodeDetails/vnodespline.cpp b/src/app/tools/nodeDetails/vnodespline.cpp index 70ca47377..c0704f5eb 100644 --- a/src/app/tools/nodeDetails/vnodespline.cpp +++ b/src/app/tools/nodeDetails/vnodespline.cpp @@ -69,7 +69,7 @@ VNodeSpline *VNodeSpline::Create(VPattern *doc, VContainer *data, quint32 id, qu doc->IncrementReferens(idTool); //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); spl->setParent(tool); } else diff --git a/src/app/tools/nodeDetails/vnodesplinepath.cpp b/src/app/tools/nodeDetails/vnodesplinepath.cpp index 8020597f6..6ab7cbc33 100644 --- a/src/app/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/app/tools/nodeDetails/vnodesplinepath.cpp @@ -72,7 +72,7 @@ void VNodeSplinePath::Create(VPattern *doc, VContainer *data, quint32 id, quint3 doc->IncrementReferens(idTool); //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); splPath->setParent(tool); } else diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 8a4d4bb08..abfcaaf81 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -75,7 +75,7 @@ const QString VAbstractTool::TypeLineDashDotDotLine = QStringLiteral("dashDotDot VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent) :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine) { - Q_CHECK_PTR(doc); + SCASSERT(doc != nullptr); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange); connect(this->doc, &VPattern::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VPattern::LiteParseTree); diff --git a/src/app/tools/vdatatool.cpp b/src/app/tools/vdatatool.cpp index 9207c3337..119885360 100644 --- a/src/app/tools/vdatatool.cpp +++ b/src/app/tools/vdatatool.cpp @@ -31,7 +31,7 @@ //--------------------------------------------------------------------------------------------------------------------- VDataTool::VDataTool(VContainer *data, QObject *parent): QObject(parent), data(*data), _referens(1) { - Q_CHECK_PTR(data); + SCASSERT(data != nullptr); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/vtooluniondetails.cpp b/src/app/tools/vtooluniondetails.cpp index cadcaf981..dc288b177 100644 --- a/src/app/tools/vtooluniondetails.cpp +++ b/src/app/tools/vtooluniondetails.cpp @@ -316,7 +316,7 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data, VSplinePath *path = new VSplinePath(); path->setMode(Valentina::Modeling); const VSplinePath *splinePath = data->GeometricObject(det.at(i).getId()); - Q_CHECK_PTR(splinePath); + SCASSERT(splinePath != nullptr); qint32 k = splinePath->getMaxCountPoints(); for (qint32 i = 1; i <= splinePath->Count(); ++i) { @@ -391,9 +391,9 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q //--------------------------------------------------------------------------------------------------------------------- void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogUnionDetails *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); VDetail d1 = data->GetDetail(dialogTool->getD1()); VDetail d2 = data->GetDetail(dialogTool->getD2()); quint32 indexD1 = static_cast(dialogTool->getIndexD1()); @@ -496,16 +496,16 @@ void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDeta newDetail.setName("Detail"); VToolDetail::Create(0, newDetail, scene, doc, data, parse, Valentina::FromTool); QHash* tools = doc->getTools(); - Q_CHECK_PTR(tools); + SCASSERT(tools != nullptr); { VToolDetail *toolDet = qobject_cast(tools->value(d1id)); - Q_CHECK_PTR(toolDet); + SCASSERT(toolDet != nullptr); toolDet->Remove(); } VToolDetail *toolDet = qobject_cast(tools->value(d2id)); - Q_CHECK_PTR(toolDet); + SCASSERT(toolDet != nullptr); toolDet->Remove(); } else diff --git a/src/app/version.h b/src/app/version.h index c3a089864..ab146190a 100644 --- a/src/app/version.h +++ b/src/app/version.h @@ -29,6 +29,8 @@ #ifndef VERSION_H #define VERSION_H +class QString; + extern const int MAJOR_VERSION; extern const int MINOR_VERSION; extern const int DEBUG_VERSION; diff --git a/src/app/widgets/doubledelegate.cpp b/src/app/widgets/doubledelegate.cpp index 8f611b1ee..e36704f77 100644 --- a/src/app/widgets/doubledelegate.cpp +++ b/src/app/widgets/doubledelegate.cpp @@ -27,8 +27,8 @@ *************************************************************************/ #include "doubledelegate.h" - #include +#include "../options.h" //--------------------------------------------------------------------------------------------------------------------- //cppcheck-suppress unusedFunction @@ -51,7 +51,7 @@ void DoubleSpinBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &in qreal value = index.model()->data(index, Qt::EditRole).toDouble(); QDoubleSpinBox *spinBox = qobject_cast(editor); - Q_CHECK_PTR(spinBox); + SCASSERT(spinBox != nullptr); spinBox->setValue(value); } @@ -60,7 +60,7 @@ void DoubleSpinBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &in void DoubleSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QDoubleSpinBox *spinBox = qobject_cast(editor); - Q_CHECK_PTR(spinBox); + SCASSERT(spinBox != nullptr); spinBox->interpretText(); qreal value = spinBox->value(); @@ -80,7 +80,7 @@ void DoubleSpinBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOp void DoubleSpinBoxDelegate::commitAndCloseEditor() { QDoubleSpinBox *spinBox = qobject_cast(sender()); - Q_CHECK_PTR(spinBox); + SCASSERT(spinBox != nullptr); qreal value = spinBox->value(); if (qFuzzyCompare ( lastValue, value ) == false) { diff --git a/src/app/widgets/textdelegate.cpp b/src/app/widgets/textdelegate.cpp index 1584ebc18..d3605d3a6 100644 --- a/src/app/widgets/textdelegate.cpp +++ b/src/app/widgets/textdelegate.cpp @@ -27,8 +27,8 @@ *************************************************************************/ #include "textdelegate.h" - #include +#include "../options.h" //--------------------------------------------------------------------------------------------------------------------- TextDelegate::TextDelegate(const QString ®ex, QObject *parent): QItemDelegate(parent), lastText(QString("Name_")), @@ -56,7 +56,7 @@ void TextDelegate::setEditorData(QWidget *editor, const QModelIndex &index) cons QString text = index.model()->data(index, Qt::EditRole).toString(); QLineEdit *lineEdit = qobject_cast(editor); - Q_CHECK_PTR(lineEdit); + SCASSERT(lineEdit != nullptr); if ( lastText != text && text.isEmpty() == false) { //Here need save text, but method is const, so, we use signal instead. @@ -69,7 +69,7 @@ void TextDelegate::setEditorData(QWidget *editor, const QModelIndex &index) cons void TextDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QLineEdit *lineEdit = qobject_cast(editor); - Q_CHECK_PTR(lineEdit); + SCASSERT(lineEdit != nullptr); QString text = lineEdit->text(); if (text.isEmpty()) { @@ -91,7 +91,7 @@ void TextDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewI void TextDelegate::commitAndCloseEditor() { QLineEdit *lineEdit = qobject_cast(sender()); - Q_CHECK_PTR(lineEdit); + SCASSERT(lineEdit != nullptr); QString text = lineEdit->text(); if ( lastText != text && text.isEmpty() == false) { diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index 9754ef21d..8a3a19653 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -168,7 +168,7 @@ QString VApplication::pathToTables() const return QApplication::applicationDirPath() + QStringLiteral("/tables/standard"); #else QDir dir(QApplication::applicationDirPath() + QStringLiteral("/tables/standard")); - if(dir.exist()) + if (dir.exist()) { return dir.absolutePath(); } @@ -191,7 +191,7 @@ QString VApplication::translationsPath() const return QApplication::applicationDirPath() + QStringLiteral("/translations"); #else QDir dir(QApplication::applicationDirPath() + QStringLiteral("/translations")); - if(dir.exist()) + if (dir.exist()) { return dir.absolutePath(); } diff --git a/src/app/widgets/vtablegraphicsview.cpp b/src/app/widgets/vtablegraphicsview.cpp index 79478647c..37e17eb32 100644 --- a/src/app/widgets/vtablegraphicsview.cpp +++ b/src/app/widgets/vtablegraphicsview.cpp @@ -30,6 +30,7 @@ #include #include +#include "../options.h" //--------------------------------------------------------------------------------------------------------------------- VTableGraphicsView::VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent) @@ -64,7 +65,7 @@ void VTableGraphicsView::MirrorItem() for ( qint32 i = 0; i < list.count(); ++i ) { QGraphicsItem *item = list.at(i); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); QRectF itemRectOld = item->sceneBoundingRect(); //Get the current transform QTransform transform(item->transform()); @@ -177,7 +178,7 @@ void VTableGraphicsView::rotateIt() for ( qint32 i = 0; i < list.count(); ++i ) { QGraphicsItem *item = list.at(i); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); item->setTransformOriginPoint(item->boundingRect().center()); item->setRotation(item->rotation() + 90); } diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 8098e413d..1994ff5c4 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -236,14 +236,9 @@ bool VPattern::SetNameDraw(const QString &name) */ void VPattern::Parse(const Document::Documents &parse) { - if (parse == Document::FullParse) - { -#ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); -#endif - } SCASSERT(sceneDraw != nullptr); SCASSERT(sceneDetail != nullptr); + QStringList tags{TagDraw, TagIncrements, TagAuthor, TagDescription, TagNotes, TagMeasurements, TagVersion}; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -253,8 +248,6 @@ void VPattern::Parse(const Document::Documents &parse) const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - QStringList tags{TagDraw, TagIncrements, TagAuthor, TagDescription, TagNotes, TagMeasurements, - TagVersion}; switch (tags.indexOf(domElement.tagName())) { case 0: // TagDraw @@ -297,12 +290,6 @@ void VPattern::Parse(const Document::Documents &parse) } domNode = domNode.nextSibling(); } - if (parse == Document::FullParse) - { -#ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); -#endif - } } //--------------------------------------------------------------------------------------------------------------------- @@ -657,7 +644,7 @@ bool VPattern::SaveDocument(const QString &fileName) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief FullUpdateTree lite parse file. + * @brief LiteParseTree lite parse file. */ void VPattern::LiteParseTree() { @@ -763,6 +750,7 @@ void VPattern::ClearScene() void VPattern::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, const QDomNode &node, const Document::Documents &parse) { + QStringList tags{TagCalculation, TagModeling, TagDetails}; QDomNode domNode = node.firstChild(); while (domNode.isNull() == false) { @@ -771,7 +759,6 @@ void VPattern::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScen const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - QStringList tags{TagCalculation, TagModeling, TagDetails}; switch (tags.indexOf(domElement.tagName())) { case 0: // TagCalculation @@ -806,8 +793,8 @@ void VPattern::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScen void VPattern::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, const QDomNode &node, const Document::Documents &parse, const Valentina::Draws &mode) { - Q_CHECK_PTR(sceneDraw); - Q_CHECK_PTR(sceneDetail); + SCASSERT(sceneDraw != nullptr); + SCASSERT(sceneDetail != nullptr); VMainGraphicsScene *scene = nullptr; if (mode == Valentina::Calculation) { @@ -817,6 +804,7 @@ void VPattern::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene * { scene = sceneDetail; } + QStringList tags{TagPoint, TagLine, TagSpline, TagArc, TagTools}; const QDomNodeList nodeList = node.childNodes(); const qint32 num = nodeList.size(); for (qint32 i = 0; i < num; ++i) @@ -824,7 +812,6 @@ void VPattern::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene * QDomElement domElement = nodeList.at(i).toElement(); if (domElement.isNull() == false) { - QStringList tags{TagPoint, TagLine, TagSpline, TagArc, TagTools}; switch (tags.indexOf(domElement.tagName())) { case 0: // TagPoint @@ -860,7 +847,7 @@ void VPattern::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene * void VPattern::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, const Document::Documents &parse) { - Q_CHECK_PTR(sceneDetail); + SCASSERT(sceneDetail != nullptr); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); try { @@ -873,6 +860,8 @@ void VPattern::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomEle detail.setWidth(GetParametrDouble(domElement, VToolDetail::AttrWidth, "10.0")); detail.setClosed(GetParametrUInt(domElement, VToolDetail::AttrClosed, "1")); + QStringList types{VToolDetail::NodePoint, VToolDetail::NodeArc, VToolDetail::NodeSpline, + VToolDetail::NodeSplinePath}; const QDomNodeList nodeList = domElement.childNodes(); const qint32 num = nodeList.size(); for (qint32 i = 0; i < num; ++i) @@ -889,8 +878,7 @@ void VPattern::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomEle const QString t = GetParametrString(element, AttrType, "NodePoint"); Valentina::Tools tool; - QStringList types{VToolDetail::NodePoint, VToolDetail::NodeArc, VToolDetail::NodeSpline, - VToolDetail::NodeSplinePath}; + switch (types.indexOf(t)) { case 0: // VToolDetail::NodePoint @@ -933,7 +921,7 @@ void VPattern::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomEle void VPattern::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, const Document::Documents &parse) { - Q_CHECK_PTR(sceneDetail); + SCASSERT(sceneDetail != nullptr); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); QDomNode domNode = domElement.firstChild(); while (domNode.isNull() == false) @@ -964,7 +952,7 @@ void VPattern::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement & void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document::Documents &parse, const QString &type) { - Q_CHECK_PTR(scene); + SCASSERT(scene != nullptr); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of point is empty"); @@ -1470,7 +1458,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem void VPattern::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement, const Document::Documents &parse) { - Q_CHECK_PTR(scene); + SCASSERT(scene != nullptr); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); try { @@ -1501,7 +1489,7 @@ void VPattern::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &do void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement, const Document::Documents &parse, const QString &type) { - Q_CHECK_PTR(scene); + SCASSERT(scene != nullptr); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); @@ -1630,7 +1618,7 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement & void VPattern::ParseArcElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document::Documents &parse, const QString &type) { - Q_CHECK_PTR(scene); + SCASSERT(scene != nullptr); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); @@ -1711,7 +1699,7 @@ void VPattern::ParseArcElement(VMainGraphicsScene *scene, QDomElement &domElemen void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &domElement, const Document::Documents &parse, const QString &type) { - Q_CHECK_PTR(scene); + SCASSERT(scene != nullptr); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); diff --git a/src/libs/qmuparser/qmuparser.h b/src/libs/qmuparser/qmuparser.h index e36f52b5d..e65bdfa40 100644 --- a/src/libs/qmuparser/qmuparser.h +++ b/src/libs/qmuparser/qmuparser.h @@ -80,7 +80,7 @@ namespace qmu static qreal Avg(const qreal*, int); // mean value static qreal Min(const qreal*, int); // minimum static qreal Max(const qreal*, int); // maximum -}; + }; //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/libs/qmuparser/qmuparsererror.cpp b/src/libs/qmuparser/qmuparsererror.cpp index 7d788d00e..fdcc0a27a 100644 --- a/src/libs/qmuparser/qmuparsererror.cpp +++ b/src/libs/qmuparser/qmuparsererror.cpp @@ -111,8 +111,8 @@ QmuParserError::QmuParserError ( EErrorCodes a_iErrc ) m_ErrMsg ( QmuParserErrorMsg::Instance() ) { m_sMsg = m_ErrMsg[m_iErrc]; - ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) ); - ReplaceSubString ( m_sMsg, "$TOK$", m_sTok ); + m_sMsg.replace("$POS$", QString().setNum ( m_iPos )); + m_sMsg.replace("$TOK$", m_sTok ); } //--------------------------------------------------------------------------------------------------------------------- @@ -137,8 +137,8 @@ QmuParserError::QmuParserError ( EErrorCodes iErrc, const QString &sTok, const Q m_ErrMsg ( QmuParserErrorMsg::Instance() ) { m_sMsg = m_ErrMsg[m_iErrc]; - ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) ); - ReplaceSubString ( m_sMsg, "$TOK$", m_sTok ); + m_sMsg.replace("$POS$", QString().setNum ( m_iPos )); + m_sMsg.replace("$TOK$", m_sTok ); } //--------------------------------------------------------------------------------------------------------------------- @@ -153,8 +153,8 @@ QmuParserError::QmuParserError ( EErrorCodes a_iErrc, int a_iPos, const QString m_ErrMsg ( QmuParserErrorMsg::Instance() ) { m_sMsg = m_ErrMsg[m_iErrc]; - ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) ); - ReplaceSubString ( m_sMsg, "$TOK$", m_sTok ); + m_sMsg.replace("$POS$", QString().setNum ( m_iPos )); + m_sMsg.replace("$TOK$", m_sTok ); } //--------------------------------------------------------------------------------------------------------------------- @@ -167,8 +167,8 @@ QmuParserError::QmuParserError ( const QString &szMsg, int iPos, const QString & : QException(), m_sMsg ( szMsg ), m_sExpr(), m_sTok ( sTok ), m_iPos ( iPos ), m_iErrc ( ecGENERIC ), m_ErrMsg ( QmuParserErrorMsg::Instance() ) { - ReplaceSubString ( m_sMsg, "$POS$", QString().setNum ( m_iPos ) ); - ReplaceSubString ( m_sMsg, "$TOK$", m_sTok ); + m_sMsg.replace("$POS$", QString().setNum ( m_iPos )); + m_sMsg.replace("$TOK$", m_sTok ); } //--------------------------------------------------------------------------------------------------------------------- @@ -197,34 +197,6 @@ QmuParserError& QmuParserError::operator= ( const QmuParserError &a_Obj ) return *this; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Replace all ocuurences of a substring with another string. - * @param strFind The string that shall be replaced. - * @param strReplaceWith The string that should be inserted instead of strFind - */ -void QmuParserError::ReplaceSubString ( QString &strSource, const QString &strFind, const QString &strReplaceWith ) -{ - QString strResult; - int iPos ( 0 ); - - for ( ;; ) - { - int iNext = strSource.indexOf ( strFind, iPos ); - strResult.append ( strSource.mid ( iPos, iNext - iPos ) ); - - if ( iNext == -1 ) - { - break; - } - - strResult.append ( strReplaceWith ); - iPos = iNext + strFind.length(); - } - - strSource.swap ( strResult ); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Reset the erro object. diff --git a/src/libs/qmuparser/qmuparsererror.h b/src/libs/qmuparser/qmuparsererror.h index 49b16e972..e90ec29b7 100644 --- a/src/libs/qmuparser/qmuparsererror.h +++ b/src/libs/qmuparser/qmuparsererror.h @@ -157,10 +157,6 @@ private: int m_iPos; ///< Formula position related to the error EErrorCodes m_iErrc; ///< Error code const QmuParserErrorMsg &m_ErrMsg; - /** - * @brief Replace all ocuurences of a substring with another string. - */ - static void ReplaceSubString ( QString &strSource, const QString &strFind, const QString &strReplaceWith ); void Reset(); }; diff --git a/src/libs/qmuparser/qmuparsertokenreader.cpp b/src/libs/qmuparser/qmuparsertokenreader.cpp index bbcf768bf..e7ae392f7 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.cpp +++ b/src/libs/qmuparser/qmuparsertokenreader.cpp @@ -22,7 +22,6 @@ #include "qmuparsertokenreader.h" #include "qmuparserbase.h" - #include #include