From 9bf2c4662da7f0d155c414b55af2cd8eaf02bee0 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Fri, 16 May 2014 13:19:22 +0200 Subject: [PATCH 01/42] Branch create --HG-- branch : XML Editor --- src/app/mainwindow.ui | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index ce4f28639..7c407b282 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -696,6 +696,7 @@ + @@ -999,6 +1000,11 @@ Pattern properties + + + Edit pattern XML code + + From f51f7030263ad6adcf41eda4d16c36d7c01e582b Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Fri, 16 May 2014 14:51:39 +0200 Subject: [PATCH 02/42] Main code push after branch creation --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 692 +++++++++++++++++++ src/app/dialogs/app/dialogpatternxmledit.h | 245 +++++++ src/app/dialogs/app/dialogpatternxmledit.ui | 351 ++++++++++ src/app/dialogs/dialogs.h | 1 + src/app/dialogs/dialogs.pri | 9 +- src/app/mainwindow.cpp | 10 + src/app/mainwindow.h | 5 + 7 files changed, 1310 insertions(+), 3 deletions(-) create mode 100644 src/app/dialogs/app/dialogpatternxmledit.cpp create mode 100644 src/app/dialogs/app/dialogpatternxmledit.h create mode 100644 src/app/dialogs/app/dialogpatternxmledit.ui diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp new file mode 100644 index 000000000..85c068c1c --- /dev/null +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -0,0 +1,692 @@ +/************************************************************************ + ** + ** @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" + + +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), + ui(new Ui::DialogPatternXmlEdit) +{ + ui->setupUi(this); + + xmlmodel = new vXMLTreeView(); + current_node_edited=0; + treeChange=false; + this->changeStackRoot = this->changeStackLast =0; + + doc=xmldoc; + root = doc->documentElement(); + // disable edit trigers : + //ui->treeView_main->editTriggers(QTreeView::NoEditTriggers); + ui->treeView_main->setEditTriggers(QTreeView::NoEditTriggers); + + ui->treeView_main->setWindowTitle("XML"); + + + rootNode = (QStandardItem*) xmlmodel->invisibleRootItem(); + + qint16 drawnum=xmldoc->elementsByTagName("draw").size(); + rootBases = (vXMLTreeElement**)malloc(sizeof(vXMLTreeElement*)*(drawnum+1)); + rootBasesNum=1; + 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 drawings"),QVariant(0)); + + //rootBases[0]=(QDomNode) doc->DocumentNode; + rootNode->appendRow(standard_base); + + readNodes(root,standard_base,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::Element_clicked); + 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); +} + +DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElement(short int typechange) { + ChangesStackElement* tmp; + + tmp= (ChangesStackElement* ) malloc(sizeof(ChangesStackElement)); + //if (tmp==0) TODO + tmp->type=typechange; + tmp->changedText=tmp->changedValue=false; + + if (changeStackLast==0) { + changeStackLast=changeStackRoot=tmp; + } else { + changeStackLast->next=tmp; + changeStackLast=changeStackLast->next; + } + changeStackLast->newValue=changeStackLast->newText=0; + changeStackLast->next=0; + return changeStackLast; +} + +void DialogPatternXmlEdit::ButtonApplyChangesClicked() { + QString Changes=""; + ChangesStackElement* currentChange; + if (this->changeStackRoot==0) Changes="No Changes"; + else { + currentChange=this->changeStackRoot; + do { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) { + Changes += QString("Added type %1 : ").arg(currentChange->element->getelementType()); + 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(currentChange->element->getelementType()); + 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(currentChange->element->getelementType()); + Changes += currentChange->element->gettreeNodeName(); + Changes += "/"; + Changes += (currentChange->element->gettreeNodeValueSet()) ? + currentChange->element->gettreeNodeValue(): QString(tr("")); + Changes += "\n"; + } + } + } + currentChange=currentChange->next; + } while (currentChange != 0); + } + QMessageBox::information(this, "Changes (not REALLY applied for now)", Changes); + // TODO : clear stack and apply +} + +void DialogPatternXmlEdit::ButtonCancelClicked(){ + this->clear_edit_data(); + if (this->current_node_edited_status=DialogPatternXmlEdit::ChangeTypeDelete) { + if (this->current_node_edited->getelementType() == vXMLTreeElement::TypeAttr) { + // Attribute previously deleted -> resore + QFont textfont=current_node_edited->font(); + textfont.setStrikeOut(false); + this->current_node_edited->setFont(textfont); + this->removeChangeStackElement(this->current_node_edited_stack); + } else { + QMessageBox::information(this, "Not Implemented", "Not Implemented"); + } + } +} + +void DialogPatternXmlEdit::removeChangeStackElement(ChangesStackElement* elmt) { + ChangesStackElement* index = this->changeStackRoot; + + if (changeStackRoot == elmt) { + if (elmt->newText != 0) free (elmt->newText); + if (elmt->newValue != 0) free (elmt->newValue); + this->changeStackRoot = elmt->next; + if (this->changeStackLast == elmt) { this->changeStackLast= elmt->next; } + free(elmt); + return; + } + while (index->next!=0) { + if (index->next == elmt) { + break; + } + index=index->next; + } + if (index->next == 0) { + // TODO : debug error here + return; + } + if (index->next->newText != 0) free (index->next->newText); + if (index->next->newValue != 0) free (index->next->newValue); + index->next=index->next->next; + if (this->changeStackLast == elmt) { this->changeStackLast= index;} + free(elmt); +} + +void DialogPatternXmlEdit::ButtonDeleteAttributeClicked(){ + ChangesStackElement* newstack; + + // TODO : maybe assert functions here + if (this->current_node_edited == 0) return; + if (this->current_node_edited->getelementType() != vXMLTreeElement::TypeAttr) return; + + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeDelete); + newstack->element= this->current_node_edited; + + QFont textfont=current_node_edited->font(); + textfont.setStrikeOut(true); + this->current_node_edited->setFont(textfont); + // Activate changes + this->treeChange=true; + ui->pushButton_Apply_Changes->setEnabled(true); + // clear dialog + this->clear_edit_data(); +} + +void DialogPatternXmlEdit::ButtonAddSonClicked(){ + ChangesStackElement* newstack; + //clear_edit_data(); + // TODO : maybe assert functions here + if (this->current_node_edited == 0) return; + if (this->current_node_edited->getelementType() != vXMLTreeElement::TypeNode) return; + + bool ok; + QString name = QInputDialog::getText(this, tr("Node Name"), + tr("Name:"), QLineEdit::Normal, + "", &ok); + if (!ok) return; + QString value = QInputDialog::getText(this, tr("Node Value (may be empty)"), + tr("Value:"), QLineEdit::Normal, + "", &ok); + if (!ok) return; + + // create element tree but do not add attribute in DOM (will be done in apply). + QDomNode empty; + vXMLTreeElement* tElement = new vXMLTreeElement( + name, + vXMLTreeElement::TypeNode, + empty,true); + + if (value !="") tElement->setTreeNodeValue(value); + current_node_edited->appendRow(tElement); + xmlmodel->appendchain(tElement); + QFont textfont=current_node_edited->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 !="") { newstack->changedValue=true;newstack->newValue=new QString(value);} + // Activate changes + treeChange=true; + ui->pushButton_Apply_Changes->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->current_node_edited == 0) return; + if (this->current_node_edited->getelementType() != vXMLTreeElement::TypeNode) return; + + QString name = QInputDialog::getText(this, tr("Attribute Name"), + tr("Name:"), QLineEdit::Normal, + "", &ok); + if (!ok) return; + QString value = QInputDialog::getText(this, tr("Attribute Value"), + tr("Value:"), QLineEdit::Normal, + "", &ok); + if (!ok) 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); + + tElement->setTreeNodeValue(value); + current_node_edited->appendRow(tElement); + xmlmodel->appendchain(tElement); + QFont textfont=current_node_edited->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); +} + +void DialogPatternXmlEdit::ButtonSetClicked(){ + QString name,value; + ChangesStackElement* newstack; + + // TODO : check if a change has already been done + if (this->current_node_edited == 0) return; + name=ui->lineEdit_Name->text(); + value=ui->lineEdit_Value->text(); + bool nameedit,valueedit; + + nameedit = (name != current_node_edited->gettreeNodeName()) ? true : false; + valueedit= (value != current_node_edited->gettreeNodeValue()) ? true : false; + + if ( nameedit == true || valueedit == true ) { + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeModify); + newstack->element= this->current_node_edited; + + if (nameedit == true) { + newstack->changedText=true; + newstack->newText=new QString(name); + current_node_edited->setTreeNodeName(name); + } + if (valueedit == true) { + newstack->changedValue=true; + newstack->newValue= new QString(value); + current_node_edited->setTreeNodeValue(value); + } + + QFont textfont=current_node_edited->font(); + textfont.setBold(true); + current_node_edited->setFont(textfont); + treeChange=true; + ui->pushButton_Apply_Changes->setEnabled(true); + clear_edit_data(); + } +} + +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::clear_edit_data() { + 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); +} + +void DialogPatternXmlEdit::clearStack() { + ChangesStackElement * tmp; + while (changeStackRoot != 0) { + if (changeStackRoot->newText != 0) free (changeStackRoot->newText); + if (changeStackRoot->newValue != 0) free (changeStackRoot->newValue); + tmp=changeStackRoot; + changeStackRoot=changeStackRoot->next; + free(tmp); + } + changeStackLast=0; +} + +void DialogPatternXmlEdit::baseSelectionChanged(int value) +{ + QDomNode newbase; + + int index; + + if (this->treeChange == true) {//Changes have been made : warn ? + } + 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); + } + 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->clear_edit_data(); + // TODO : warn if changes ? + this->clearStack(); + return; +} + +void DialogPatternXmlEdit::Element_clicked ( const QModelIndex & index ) { + + // Get item (function returns parent of clicked item) + vXMLTreeElement *item = (vXMLTreeElement *)index.internalPointer(); + + // Get child specified by index row/column + vXMLTreeElement * item2 = (vXMLTreeElement *) item->child(index.row(),index.column()); + + // Clear all data and disable buttons + this->clear_edit_data(); + // Check status of element in change stack + this->current_node_edited=item2; + this->current_node_edited_status=0; + DialogPatternXmlEdit::ChangesStackElement * local = this->changeStackRoot; + while (local != 0) { + if (local->element == item2) { + this->current_node_edited_status=local->type; + this->current_node_edited_stack=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(current_node_edited->gettreeNodeName()); + ui->lineEdit_Name->setEnabled(true); + // Fill value + ui->lineEdit_Value->setText(current_node_edited->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); + } else if (item2->getelementType() == vXMLTreeElement::TypeAttr) { + ui->label_type_value->setText(tr("Attribute")); + ui->pushButton_Remove_attribute->setEnabled(true); + } +} + +DialogPatternXmlEdit::~DialogPatternXmlEdit() +{ + //xmlmodel->clearTree(); + delete ui; + ChangesStackElement * tmp; while (changeStackRoot != 0) { + tmp=changeStackRoot->next; + free(changeStackRoot); + changeStackRoot=tmp; + } + //delete rootBases[0]; + //free(rootBases); + //delete xmlmodel; +} + +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 Code ----------------------------------------------------------------- +vXMLTreeView::vXMLTreeView(QObject *parent) : QStandardItemModel(parent) +{ + current=last=items=0; +} + +void vXMLTreeView::clearTree() { + + // TODO check if treeitems are deleted with the delete row command of QDom + + //clear the chain link + TreeElementchain * tmp; + while (items != 0) { + tmp=items; + items=items->next; + free (tmp); + } + // reset chain counters + current=last=items=0; + +} + +vXMLTreeView::~vXMLTreeView() +{ + +} + +void vXMLTreeView::appendchain(vXMLTreeElement* elmt) +{ + if (last == 0) { // first element + current=(TreeElementchain*)malloc(sizeof(TreeElementchain)); + if (current == 0) { + Q_ASSERT(current != 0); + // TODO : throw exception + } + current->elmt=elmt; + current->next=0; + last=items=current; + return; + } + TreeElementchain* temp=(TreeElementchain*)malloc(sizeof(TreeElementchain)); + if (temp == 0) { + Q_ASSERT(temp != 0); + // TODO : throw exception + } + temp->elmt=elmt; + temp->next=0; + last->next=temp; + last=temp; +} + +vXMLTreeView::TreeElementchain * vXMLTreeView::getCurrent() { return this->current;} +void vXMLTreeView::setCurrent(vXMLTreeView::TreeElementchain * value) { this->current=value;} +vXMLTreeView::TreeElementchain * vXMLTreeView::getLast() { return this->last;} +vXMLTreeView::TreeElementchain * vXMLTreeView::getItems() { return this->items;} + + +// vXMLTreeElement code ----------------------------------------------------------------- + +const short int vXMLTreeElement::TypeNode=1; +const short int vXMLTreeElement::TypeAttr=2; +const short int vXMLTreeElement::TypeRoot=3; + + +vXMLTreeElement::vXMLTreeElement(QString name, int nodetype, QDomNode source,bool editor) + : QStandardItem(name) +{ + this->elementType=nodetype; + this->DocNode=source; + this->addedNode=editor; + if (!editor) this->DocNode=source; + this->treeNodeName=name; + this->treeNodeValue=""; // TODO : translation ? + this->treeNodeValueSet=false, + 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); +} + +short int vXMLTreeElement::getelementType() { return this->elementType;} + +QDomNode vXMLTreeElement::getDocNode() +{ + return this->DocNode; +} + +QString vXMLTreeElement::gettreeNodeName() { return this->treeNodeName;} +QString vXMLTreeElement::gettreeNodeValue() { + // Only return value if it's really set. + if (this->treeNodeValueSet) + return this->treeNodeValue; + else + return ""; +} +bool vXMLTreeElement::gettreeNodeValueSet() {return this->treeNodeValueSet;} diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h new file mode 100644 index 000000000..6332c05d3 --- /dev/null +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -0,0 +1,245 @@ +/************************************************************************ + ** + ** @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) +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, 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(); + QString gettreeNodeName(); + QString gettreeNodeValue(); + bool gettreeNodeValueSet(); + void setTreeNodeName(QString value); + /** + * @brief getelementType + * @return elementType value + */ + short int getelementType(); + +private: + /** + * @brief DocNode : link to current document node + */ + QDomNode DocNode; + + /** + * @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; + Q_DISABLE_COPY(vXMLTreeElement) +}; + +//******************************************************************************************** +/** + * @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; + +}; + +//******************************************************************************************** + +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 clear_edit_data(); + + void nameTextEdited(QString newtext); + void valueTextEdited(QString newtext); + void ButtonSetClicked(); + void ButtonCancelClicked(); + void ButtonDeleteAttributeClicked(); + void ButtonAddSonClicked(); + void ButtonAddAttributeClicked(); + void ButtonApplyChangesClicked() ; + + + // Stack of changes definition + typedef struct ChangesStackElement { + short int type; + vXMLTreeElement *element; + QString *newText; + bool changedText; + QString *newValue; + bool changedValue; + ChangesStackElement* next; + } ChangesStackElement; + + // Change stack functions + ChangesStackElement* CreateStackElement(short int typechange); + void removeChangeStackElement(ChangesStackElement* elmt); + void clearStack(); + bool treeChange; + vXMLTreeElement* current_node_edited; + short int current_node_edited_status; + ChangesStackElement* current_node_edited_stack; + +private slots: + void baseSelectionChanged(int value); + void Element_clicked ( 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..8b4a7238e --- /dev/null +++ b/src/app/dialogs/app/dialogpatternxmledit.ui @@ -0,0 +1,351 @@ + + + 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 + + + + + + + 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 + + + Cancel changes + + + + + + + + + + 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/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 62dd44ef5..03bff16a2 100644 --- a/src/app/dialogs/dialogs.pri +++ b/src/app/dialogs/dialogs.pri @@ -29,7 +29,8 @@ HEADERS += \ dialogs/app/dialogmeasurements.h \ dialogs/app/dialogstandardmeasurements.h \ dialogs/app/dialogindividualmeasurements.h \ - dialogs/app/dialogaboutapp.h + dialogs/app/dialogaboutapp.h \ + dialogs/app/dialogpatternxmledit.h SOURCES += \ dialogs/tools/dialogtriangle.cpp \ @@ -61,7 +62,8 @@ SOURCES += \ dialogs/app/dialogmeasurements.cpp \ dialogs/app/dialogstandardmeasurements.cpp \ dialogs/app/dialogindividualmeasurements.cpp \ - dialogs/app/dialogaboutapp.cpp + dialogs/app/dialogaboutapp.cpp \ + dialogs/app/dialogpatternxmledit.cpp FORMS += \ dialogs/tools/dialogtriangle.ui \ @@ -90,4 +92,5 @@ FORMS += \ dialogs/app/dialogmeasurements.ui \ dialogs/app/dialogstandardmeasurements.ui \ dialogs/app/dialogindividualmeasurements.ui \ - dialogs/app/dialogaboutapp.ui + dialogs/app/dialogaboutapp.ui \ + dialogs/app/dialogpatternxmledit.ui diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 47155b812..288cfcd39 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -543,6 +543,14 @@ void MainWindow::PatternProperties() proper.exec(); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::EditPatternCode() +{ + //TODO : free dialog pointer at end of dialog + DialogPatternXmlEdit *Pattern = new DialogPatternXmlEdit (this,doc); + Pattern->show(); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::showEvent( QShowEvent *event ) { @@ -1359,6 +1367,8 @@ void MainWindow::CreateActions() connect(ui->actionOptions, &QAction::triggered, this, &MainWindow::Options); 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 9a8f8407f..ebb067940 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -363,6 +363,11 @@ public slots: void tableClosed(); void OpenRecentFile(); void PatternProperties(); + /** + * @brief Edit XML code of pattern + */ + void EditPatternCode(); + signals: /** * @brief ModelChosen emit after calculation all details. From c1bf6c8a73084c24cce27b1c0839785a089bf235 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Fri, 16 May 2014 16:49:58 +0200 Subject: [PATCH 03/42] Code style --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 525 +++++++++++-------- src/app/dialogs/app/dialogpatternxmledit.h | 95 +++- src/app/mainwindow.cpp | 2 +- 3 files changed, 369 insertions(+), 253 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index 85c068c1c..815df0454 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -35,14 +35,12 @@ 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), - ui(new Ui::DialogPatternXmlEdit) +DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent,VPattern *xmldoc):QDialog(parent),ui(new Ui::DialogPatternXmlEdit) { ui->setupUi(this); - xmlmodel = new vXMLTreeView(); - current_node_edited=0; + xmlmodel = new VXMLTreeView(); + currentNodeEdited=0; treeChange=false; this->changeStackRoot = this->changeStackLast =0; @@ -58,80 +56,52 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent,VPattern *xmldoc) : rootNode = (QStandardItem*) xmlmodel->invisibleRootItem(); qint16 drawnum=xmldoc->elementsByTagName("draw").size(); - rootBases = (vXMLTreeElement**)malloc(sizeof(vXMLTreeElement*)*(drawnum+1)); + rootBases = new VXMLTreeElement*[drawnum+1]; rootBasesNum=1; - rootBases[0]=new vXMLTreeElement("Valentina",vXMLTreeElement::TypeRoot,root,false); + rootBases[0]=new VXMLTreeElement("Valentina",VXMLTreeElement::TypeRoot,root,false); // TODO : OOM exception. - vXMLTreeElement* standard_base = new vXMLTreeElement("Valentina",vXMLTreeElement::TypeRoot,root,false); + VXMLTreeElement* standard_base = new VXMLTreeElement("Valentina",VXMLTreeElement::TypeRoot,root,false); ui->comboBox_Base_Selection->addItem(tr("All drawings"),QVariant(0)); //rootBases[0]=(QDomNode) doc->DocumentNode; rootNode->appendRow(standard_base); - readNodes(root,standard_base,xmlmodel,false); + ReadNodes(root,standard_base,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::Element_clicked); - 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->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); } -DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElement(short int typechange) { +DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElement(short int typechange) +{ ChangesStackElement* tmp; - tmp= (ChangesStackElement* ) malloc(sizeof(ChangesStackElement)); + tmp= new ChangesStackElement; //if (tmp==0) TODO tmp->type=typechange; tmp->changedText=tmp->changedValue=false; - if (changeStackLast==0) { + if (changeStackLast==0) + { changeStackLast=changeStackRoot=tmp; - } else { + } + else + { changeStackLast->next=tmp; changeStackLast=changeStackLast->next; } @@ -140,29 +110,42 @@ DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElem return changeStackLast; } -void DialogPatternXmlEdit::ButtonApplyChangesClicked() { +void DialogPatternXmlEdit::ButtonApplyChangesClicked() +{ QString Changes=""; ChangesStackElement* currentChange; - if (this->changeStackRoot==0) Changes="No Changes"; - else { + if (this->changeStackRoot==0) + { + Changes="No Changes"; + } + else + { currentChange=this->changeStackRoot; - do { - if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) { + do + { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) + { Changes += QString("Added type %1 : ").arg(currentChange->element->getelementType()); Changes += currentChange->element->gettreeNodeName(); Changes += "/"; Changes += (currentChange->element->gettreeNodeValueSet()) ? currentChange->element->gettreeNodeValue(): QString(tr("")); Changes += "\n"; - } else { - if (currentChange->type == DialogPatternXmlEdit::ChangeTypeModify) { + } + else + { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeModify) + { Changes += QString("Modified type %1 : ").arg(currentChange->element->getelementType()); 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) { + } + else + { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeDelete) + { Changes += QString("Deleted type %1 : ").arg(currentChange->element->getelementType()); Changes += currentChange->element->gettreeNodeName(); Changes += "/"; @@ -179,97 +162,148 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() { // TODO : clear stack and apply } -void DialogPatternXmlEdit::ButtonCancelClicked(){ - this->clear_edit_data(); - if (this->current_node_edited_status=DialogPatternXmlEdit::ChangeTypeDelete) { - if (this->current_node_edited->getelementType() == vXMLTreeElement::TypeAttr) { +void DialogPatternXmlEdit::ButtonCancelClicked() +{ + this->ClearEditData(); + if (this->currentNodeEditedStatus==DialogPatternXmlEdit::ChangeTypeDelete) + { + if (this->currentNodeEdited->getelementType() == VXMLTreeElement::TypeAttr) + { // Attribute previously deleted -> resore - QFont textfont=current_node_edited->font(); + QFont textfont=currentNodeEdited->font(); textfont.setStrikeOut(false); - this->current_node_edited->setFont(textfont); - this->removeChangeStackElement(this->current_node_edited_stack); - } else { + this->currentNodeEdited->setFont(textfont); + this->RemoveChangeStackElement(this->currentNodeEditedStack); + } + else + { QMessageBox::information(this, "Not Implemented", "Not Implemented"); } } } -void DialogPatternXmlEdit::removeChangeStackElement(ChangesStackElement* elmt) { +void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) +{ ChangesStackElement* index = this->changeStackRoot; - if (changeStackRoot == elmt) { - if (elmt->newText != 0) free (elmt->newText); - if (elmt->newValue != 0) free (elmt->newValue); + if (changeStackRoot == elmt) + { + if (elmt->newText != 0) + { + delete elmt->newText; + } + if (elmt->newValue != 0) + { + delete elmt->newValue; + } this->changeStackRoot = elmt->next; - if (this->changeStackLast == elmt) { this->changeStackLast= elmt->next; } - free(elmt); + if (this->changeStackLast == elmt) + { + this->changeStackLast= elmt->next; + } + delete elmt; return; } while (index->next!=0) { - if (index->next == elmt) { + if (index->next == elmt) + { break; } index=index->next; } - if (index->next == 0) { + if (index->next == 0) + { // TODO : debug error here return; } - if (index->next->newText != 0) free (index->next->newText); - if (index->next->newValue != 0) free (index->next->newValue); + if (index->next->newText != 0) + { + delete index->next->newText; + } + if (index->next->newValue != 0) + { + delete index->next->newValue; + } index->next=index->next->next; - if (this->changeStackLast == elmt) { this->changeStackLast= index;} - free(elmt); + if (this->changeStackLast == elmt) + { + this->changeStackLast= index; + } + delete elmt; } -void DialogPatternXmlEdit::ButtonDeleteAttributeClicked(){ +void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() +{ ChangesStackElement* newstack; // TODO : maybe assert functions here - if (this->current_node_edited == 0) return; - if (this->current_node_edited->getelementType() != vXMLTreeElement::TypeAttr) return; + if (this->currentNodeEdited == 0) + { + return; + } + if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeAttr) + { + return; + } newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeDelete); - newstack->element= this->current_node_edited; + newstack->element= this->currentNodeEdited; - QFont textfont=current_node_edited->font(); + QFont textfont=currentNodeEdited->font(); textfont.setStrikeOut(true); - this->current_node_edited->setFont(textfont); + this->currentNodeEdited->setFont(textfont); // Activate changes this->treeChange=true; ui->pushButton_Apply_Changes->setEnabled(true); // clear dialog - this->clear_edit_data(); + this->ClearEditData(); } -void DialogPatternXmlEdit::ButtonAddSonClicked(){ +void DialogPatternXmlEdit::ButtonAddSonClicked() +{ ChangesStackElement* newstack; + bool ok; //clear_edit_data(); // TODO : maybe assert functions here - if (this->current_node_edited == 0) return; - if (this->current_node_edited->getelementType() != vXMLTreeElement::TypeNode) return; + if (this->currentNodeEdited == 0) + { + return; + } + if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeNode) + { + return; + } + - bool ok; QString name = QInputDialog::getText(this, tr("Node Name"), tr("Name:"), QLineEdit::Normal, "", &ok); - if (!ok) return; + if (ok==false) + { + return; + } QString value = QInputDialog::getText(this, tr("Node Value (may be empty)"), tr("Value:"), QLineEdit::Normal, "", &ok); - if (!ok) return; + if (ok==false) + { + return; + } // create element tree but do not add attribute in DOM (will be done in apply). QDomNode empty; - vXMLTreeElement* tElement = new vXMLTreeElement( + VXMLTreeElement* tElement = new VXMLTreeElement( name, - vXMLTreeElement::TypeNode, + VXMLTreeElement::TypeNode, empty,true); - if (value !="") tElement->setTreeNodeValue(value); - current_node_edited->appendRow(tElement); + if (!value.isEmpty()) + { + tElement->setTreeNodeValue(value); + } + currentNodeEdited->appendRow(tElement); xmlmodel->appendchain(tElement); - QFont textfont=current_node_edited->font(); + QFont textfont=currentNodeEdited->font(); textfont.setBold(true); tElement->setFont(textfont); @@ -277,46 +311,59 @@ void DialogPatternXmlEdit::ButtonAddSonClicked(){ newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeAdd); newstack->element=tElement; newstack->newText=new QString(name); newstack->changedText=true; - if (value !="") { newstack->changedValue=true;newstack->newValue=new QString(value);} + if (value.isEmpty()) + { + newstack->changedValue=true;newstack->newValue=new QString(value); + } // Activate changes treeChange=true; ui->pushButton_Apply_Changes->setEnabled(true); } -void DialogPatternXmlEdit::ButtonAddAttributeClicked(){ +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->current_node_edited == 0) return; - if (this->current_node_edited->getelementType() != vXMLTreeElement::TypeNode) return; + if (this->currentNodeEdited == 0) + { + return; + } + if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeNode) return; QString name = QInputDialog::getText(this, tr("Attribute Name"), tr("Name:"), QLineEdit::Normal, "", &ok); - if (!ok) return; + if (ok==false) + { + return; + } QString value = QInputDialog::getText(this, tr("Attribute Value"), tr("Value:"), QLineEdit::Normal, "", &ok); - if (!ok) return; + if (ok==false) + { + return; + } // create element tree but do not add attribute in DOM (will be done in apply). - vXMLTreeElement* tElement = new vXMLTreeElement( + VXMLTreeElement* tElement = new VXMLTreeElement( name, - vXMLTreeElement::TypeAttr, + VXMLTreeElement::TypeAttr, empty,true); tElement->setTreeNodeValue(value); - current_node_edited->appendRow(tElement); + currentNodeEdited->appendRow(tElement); xmlmodel->appendchain(tElement); - QFont textfont=current_node_edited->font(); + 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->type=VXMLTreeElement::TypeAttr; newstack->newText=new QString(name); newstack->newValue=new QString(value); // Activate changes @@ -324,56 +371,63 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked(){ ui->pushButton_Apply_Changes->setEnabled(true); } -void DialogPatternXmlEdit::ButtonSetClicked(){ +void DialogPatternXmlEdit::ButtonSetClicked() +{ QString name,value; ChangesStackElement* newstack; // TODO : check if a change has already been done - if (this->current_node_edited == 0) return; + if (this->currentNodeEdited == 0) return; name=ui->lineEdit_Name->text(); value=ui->lineEdit_Value->text(); bool nameedit,valueedit; - nameedit = (name != current_node_edited->gettreeNodeName()) ? true : false; - valueedit= (value != current_node_edited->gettreeNodeValue()) ? true : false; + nameedit = (name != currentNodeEdited->gettreeNodeName()) ? true : false; + valueedit= (value != currentNodeEdited->gettreeNodeValue()) ? true : false; - if ( nameedit == true || valueedit == true ) { + if ( nameedit == true || valueedit == true ) + { newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeModify); - newstack->element= this->current_node_edited; + newstack->element= this->currentNodeEdited; - if (nameedit == true) { + if (nameedit == true) + { newstack->changedText=true; newstack->newText=new QString(name); - current_node_edited->setTreeNodeName(name); + currentNodeEdited->setTreeNodeName(name); } - if (valueedit == true) { + if (valueedit == true) + { newstack->changedValue=true; newstack->newValue= new QString(value); - current_node_edited->setTreeNodeValue(value); + currentNodeEdited->setTreeNodeValue(value); } - QFont textfont=current_node_edited->font(); + QFont textfont=currentNodeEdited->font(); textfont.setBold(true); - current_node_edited->setFont(textfont); + currentNodeEdited->setFont(textfont); treeChange=true; ui->pushButton_Apply_Changes->setEnabled(true); - clear_edit_data(); + ClearEditData(); } } -void DialogPatternXmlEdit::nameTextEdited(QString newtext) { +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) { +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::clear_edit_data() { +void DialogPatternXmlEdit::ClearEditData() +{ ui->lineEdit_Name->setText(""); ui->lineEdit_Value->setText(""); ui->lineEdit_Name->setEnabled(false); @@ -387,27 +441,36 @@ void DialogPatternXmlEdit::clear_edit_data() { ui->pushButton_Cancel_Values->setEnabled(false); } -void DialogPatternXmlEdit::clearStack() { +void DialogPatternXmlEdit::ClearStack() +{ ChangesStackElement * tmp; - while (changeStackRoot != 0) { - if (changeStackRoot->newText != 0) free (changeStackRoot->newText); - if (changeStackRoot->newValue != 0) free (changeStackRoot->newValue); + while (changeStackRoot != 0) + { + if (changeStackRoot->newText != 0) + { + delete changeStackRoot->newText; + } + if (changeStackRoot->newValue != 0) + { + delete changeStackRoot->newValue; + } tmp=changeStackRoot; changeStackRoot=changeStackRoot->next; - free(tmp); + delete tmp; } changeStackLast=0; } -void DialogPatternXmlEdit::baseSelectionChanged(int value) +void DialogPatternXmlEdit::BaseSelectionChanged(int value) { QDomNode newbase; int index; - if (this->treeChange == true) {//Changes have been made : warn ? + if (this->treeChange == true) + {//Changes have been made : warn ? } - clearStack(); + ClearStack(); ui->pushButton_Apply_Changes->setEnabled(false); index = ui->comboBox_Base_Selection->itemData(value).toInt(); //.convert(QVariant::Int); @@ -416,45 +479,50 @@ void DialogPatternXmlEdit::baseSelectionChanged(int value) // Clear all tree info and nodes // TODO : Check - while (rootNode->rowCount() > 0) { + while (rootNode->rowCount() > 0) + { rootNode->removeRow(0); } - xmlmodel->clearTree(); + xmlmodel->ClearTree(); - vXMLTreeElement* standard_base = new vXMLTreeElement( + VXMLTreeElement* standard_base = new VXMLTreeElement( rootBases[index]->gettreeNodeName(), - vXMLTreeElement::TypeRoot, + VXMLTreeElement::TypeRoot, rootBases[index]->getDocNode(), false); rootNode->appendRow(standard_base); - readNodes(rootBases[index]->getDocNode(),standard_base,xmlmodel,true); + ReadNodes(rootBases[index]->getDocNode(),standard_base,xmlmodel,true); ui->treeView_main->setModel(xmlmodel); - this->clear_edit_data(); + this->ClearEditData(); // TODO : warn if changes ? - this->clearStack(); + this->ClearStack(); return; } -void DialogPatternXmlEdit::Element_clicked ( const QModelIndex & index ) { +void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) +{ // Get item (function returns parent of clicked item) - vXMLTreeElement *item = (vXMLTreeElement *)index.internalPointer(); + VXMLTreeElement *item = (VXMLTreeElement *)index.internalPointer(); // Get child specified by index row/column - vXMLTreeElement * item2 = (vXMLTreeElement *) item->child(index.row(),index.column()); + VXMLTreeElement * item2 = (VXMLTreeElement *) item->child(index.row(),index.column()); // Clear all data and disable buttons - this->clear_edit_data(); + this->ClearEditData(); // Check status of element in change stack - this->current_node_edited=item2; - this->current_node_edited_status=0; + this->currentNodeEdited=item2; + this->currentNodeEditedStatus=0; DialogPatternXmlEdit::ChangesStackElement * local = this->changeStackRoot; - while (local != 0) { - if (local->element == item2) { - this->current_node_edited_status=local->type; - this->current_node_edited_stack=local; - if (local->type == DialogPatternXmlEdit::ChangeTypeDelete) { + while (local != 0) + { + 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; @@ -463,21 +531,27 @@ void DialogPatternXmlEdit::Element_clicked ( const QModelIndex & index ) { local=local->next; } // Fill the dialog and Activate the line edit - if (item2->getelementType() != vXMLTreeElement::TypeRoot) { - ui->lineEdit_Name->setText(current_node_edited->gettreeNodeName()); + if (item2->getelementType() != VXMLTreeElement::TypeRoot) + { + ui->lineEdit_Name->setText(currentNodeEdited->gettreeNodeName()); ui->lineEdit_Name->setEnabled(true); // Fill value - ui->lineEdit_Value->setText(current_node_edited->gettreeNodeValue()); + ui->lineEdit_Value->setText(currentNodeEdited->gettreeNodeValue()); ui->lineEdit_Value->setEnabled(true); } - if (item2->getelementType() == vXMLTreeElement::TypeRoot) { + 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) { + } + 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); - } else if (item2->getelementType() == vXMLTreeElement::TypeAttr) { + } + else if (item2->getelementType() == VXMLTreeElement::TypeAttr) + { ui->label_type_value->setText(tr("Attribute")); ui->pushButton_Remove_attribute->setEnabled(true); } @@ -487,39 +561,45 @@ DialogPatternXmlEdit::~DialogPatternXmlEdit() { //xmlmodel->clearTree(); delete ui; - ChangesStackElement * tmp; while (changeStackRoot != 0) { + ChangesStackElement * tmp; + while (changeStackRoot != 0) + { tmp=changeStackRoot->next; - free(changeStackRoot); + delete changeStackRoot; changeStackRoot=tmp; } - //delete rootBases[0]; - //free(rootBases); - //delete xmlmodel; } -void DialogPatternXmlEdit::readNodes(QDomNode dNode, vXMLTreeElement* root,vXMLTreeView* xmlmodel, bool refresh) +void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLTreeView* xmlmodel, bool refresh) { QDomNode tNode,tNode2; - vXMLTreeElement* tElement,*tElement2; + 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") { + if (tNode.nodeName() == "draw") + { for (int i = 0; i < tNode.attributes().size(); i++) { if ((tNode.attributes().item(i).nodeName() == "name") - && (refresh == false)){ + && (refresh == false)) + { ui->comboBox_Base_Selection->addItem(tNode.attributes().item(i).nodeValue(), QVariant(rootBasesNum)); - rootBases[rootBasesNum]=new vXMLTreeElement( + rootBases[rootBasesNum]=new VXMLTreeElement( QString("Drawing %1").arg(tNode.attributes().item(i).nodeValue()), - vXMLTreeElement::TypeRoot,tNode,false);; + VXMLTreeElement::TypeRoot,tNode,false);; rootBasesNum++; //QStandardItem* rootNode = (QStandardItem*) rootBases[rootBasesNum]->invisibleRootItem(); //rootNode->appendRow(tElement); @@ -533,70 +613,77 @@ void DialogPatternXmlEdit::readNodes(QDomNode dNode, vXMLTreeElement* root,vXMLT { tElement=xmlmodel->getCurrent()->elmt; tNode=tElement->getDocNode(); - if (tElement->getelementType() == vXMLTreeElement::TypeNode) { + if (tElement->getelementType() == VXMLTreeElement::TypeNode) + { totalOfChilds = tNode.childNodes().size(); - for (int i=0;iappendchain(tElement2); tElement->appendRow(tElement2); } } - if (tNode.nodeType() == QDomNode::TextNode) { + if (tNode.nodeType() == QDomNode::TextNode) + { tElement->setTreeNodeValue(tNode.nodeValue()); } for (int i = 0; i < tNode.attributes().size(); i++) { - tElement2 = new vXMLTreeElement( + tElement2 = new VXMLTreeElement( tNode.attributes().item(i).nodeName(), - vXMLTreeElement::TypeAttr, + VXMLTreeElement::TypeAttr, tNode,false); tElement2->setTreeNodeValue(tNode.attributes().item(i).nodeValue()); tElement->appendRow(tElement2); xmlmodel->appendchain(tElement2); } } - xmlmodel->setCurrent(xmlmodel->getCurrent()->next); + xmlmodel->SetCurrent(xmlmodel->getCurrent()->next); } while (xmlmodel->getCurrent() != 0); return; } // vXMLTreeView Code ----------------------------------------------------------------- -vXMLTreeView::vXMLTreeView(QObject *parent) : QStandardItemModel(parent) +VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent) { current=last=items=0; } -void vXMLTreeView::clearTree() { +void VXMLTreeView::ClearTree() { // TODO check if treeitems are deleted with the delete row command of QDom //clear the chain link TreeElementchain * tmp; - while (items != 0) { + while (items != 0) + { tmp=items; items=items->next; - free (tmp); + delete tmp; } // reset chain counters current=last=items=0; } -vXMLTreeView::~vXMLTreeView() +VXMLTreeView::~VXMLTreeView() { } -void vXMLTreeView::appendchain(vXMLTreeElement* elmt) +void VXMLTreeView::appendchain(VXMLTreeElement* elmt) { - if (last == 0) { // first element - current=(TreeElementchain*)malloc(sizeof(TreeElementchain)); - if (current == 0) { + if (last == 0) + { // first element + current = new TreeElementchain; + if (current == 0) + { Q_ASSERT(current != 0); // TODO : throw exception } @@ -605,8 +692,9 @@ void vXMLTreeView::appendchain(vXMLTreeElement* elmt) last=items=current; return; } - TreeElementchain* temp=(TreeElementchain*)malloc(sizeof(TreeElementchain)); - if (temp == 0) { + TreeElementchain* temp= new TreeElementchain; + if (temp == 0) + { Q_ASSERT(temp != 0); // TODO : throw exception } @@ -616,32 +704,30 @@ void vXMLTreeView::appendchain(vXMLTreeElement* elmt) last=temp; } -vXMLTreeView::TreeElementchain * vXMLTreeView::getCurrent() { return this->current;} -void vXMLTreeView::setCurrent(vXMLTreeView::TreeElementchain * value) { this->current=value;} -vXMLTreeView::TreeElementchain * vXMLTreeView::getLast() { return this->last;} -vXMLTreeView::TreeElementchain * vXMLTreeView::getItems() { return this->items;} - // vXMLTreeElement code ----------------------------------------------------------------- -const short int vXMLTreeElement::TypeNode=1; -const short int vXMLTreeElement::TypeAttr=2; -const short int vXMLTreeElement::TypeRoot=3; +const short int VXMLTreeElement::TypeNode=1; +const short int VXMLTreeElement::TypeAttr=2; +const short int VXMLTreeElement::TypeRoot=3; -vXMLTreeElement::vXMLTreeElement(QString name, int nodetype, QDomNode source,bool editor) - : QStandardItem(name) +VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source,bool editor): QStandardItem(name) { this->elementType=nodetype; this->DocNode=source; this->addedNode=editor; - if (!editor) this->DocNode=source; + if (!editor) + { + this->DocNode=source; + } this->treeNodeName=name; this->treeNodeValue=""; // TODO : translation ? this->treeNodeValueSet=false, this->setText(this->displayText()); - switch (this->elementType) { - case vXMLTreeElement::TypeAttr: + switch (this->elementType) + { + case VXMLTreeElement::TypeAttr: this->setBackground(BACKGROUND_COLOR_ATTRIBUTE); break; default: @@ -650,43 +736,36 @@ vXMLTreeElement::vXMLTreeElement(QString name, int nodetype, QDomNode source,boo } -vXMLTreeElement::~vXMLTreeElement() +VXMLTreeElement::~VXMLTreeElement() { } -void vXMLTreeElement::setTreeNodeValue(QString value) + +void VXMLTreeElement::setTreeNodeValue(QString value) { this->treeNodeValue=value; this->treeNodeValueSet=true; this->setText(this->displayText()); } -void vXMLTreeElement::setTreeNodeName(QString value) +void VXMLTreeElement::setTreeNodeName(QString value) { this->treeNodeName=value; this->setText(this->displayText()); } -QString vXMLTreeElement::displayText() +QString VXMLTreeElement::displayText() { - if (this->elementType == vXMLTreeElement::TypeRoot) + if (this->elementType == VXMLTreeElement::TypeRoot) return this->treeNodeName; return QString("%1 : %2").arg((this->treeNodeName)).arg(this->treeNodeValue); } -short int vXMLTreeElement::getelementType() { return this->elementType;} - -QDomNode vXMLTreeElement::getDocNode() -{ - return this->DocNode; -} - -QString vXMLTreeElement::gettreeNodeName() { return this->treeNodeName;} -QString vXMLTreeElement::gettreeNodeValue() { +QString VXMLTreeElement::gettreeNodeValue() { // Only return value if it's really set. if (this->treeNodeValueSet) return this->treeNodeValue; else return ""; } -bool vXMLTreeElement::gettreeNodeValueSet() {return this->treeNodeValueSet;} + diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h index 6332c05d3..96eb01d8d 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.h +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -41,7 +41,7 @@ */ #define BACKGROUND_COLOR_ATTRIBUTE QBrush(Qt::GlobalColor::cyan) -class vXMLTreeElement : public QStandardItem +class VXMLTreeElement : public QStandardItem { public: @@ -51,11 +51,11 @@ public: * @param nodetype : node type (node, attribute, root) * @param source : the source dom node */ - explicit vXMLTreeElement (QString name, int nodetype, QDomNode source,bool editor); + explicit VXMLTreeElement (QString name, int nodetype, QDomNode source,bool editor); - explicit vXMLTreeElement (QString name, int nodetype); + explicit VXMLTreeElement (QString name, int nodetype); - ~vXMLTreeElement (); + ~VXMLTreeElement (); static const short int TypeNode; static const short int TypeAttr; static const short int TypeRoot; @@ -110,38 +110,58 @@ private: * @brief nodeValue : Attribute or node value */ QString treeNodeName; - Q_DISABLE_COPY(vXMLTreeElement) + Q_DISABLE_COPY(VXMLTreeElement) }; +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 +class VXMLTreeView : public QStandardItemModel { public: - explicit vXMLTreeView (QObject *parent = 0); - void appendchain(vXMLTreeElement* elmt); + explicit VXMLTreeView (QObject *parent = 0); + void appendchain(VXMLTreeElement* elmt); /** * @brief The TreeElement struct : chained list of vXMLTreeElement */ typedef struct TreeElementchain { - vXMLTreeElement* elmt; + VXMLTreeElement* elmt; TreeElementchain* next; } TreeElementchain; TreeElementchain * getCurrent(); - void setCurrent(TreeElementchain * value); - TreeElementchain * getLast(); - TreeElementchain * getItems(); + void SetCurrent(TreeElementchain * value); + TreeElementchain * GetLast(); + TreeElementchain * GetItems(); /** * @brief clearTree : clear tree elements and listed items. */ - void clearTree(); - ~vXMLTreeView (); + void ClearTree(); + ~VXMLTreeView (); private: - Q_DISABLE_COPY(vXMLTreeView) + Q_DISABLE_COPY(VXMLTreeView) /** * @brief items : root of chained list of vXMLTreeElement @@ -158,6 +178,23 @@ private: }; +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 { @@ -177,10 +214,10 @@ public: /** * @brief clear_edit_data : clear input boxes and disables buttons. */ - void clear_edit_data(); + void ClearEditData(); - void nameTextEdited(QString newtext); - void valueTextEdited(QString newtext); + void NameTextEdited(QString newtext); + void ValueTextEdited(QString newtext); void ButtonSetClicked(); void ButtonCancelClicked(); void ButtonDeleteAttributeClicked(); @@ -192,7 +229,7 @@ public: // Stack of changes definition typedef struct ChangesStackElement { short int type; - vXMLTreeElement *element; + VXMLTreeElement *element; QString *newText; bool changedText; QString *newValue; @@ -202,16 +239,16 @@ public: // Change stack functions ChangesStackElement* CreateStackElement(short int typechange); - void removeChangeStackElement(ChangesStackElement* elmt); - void clearStack(); + void RemoveChangeStackElement(ChangesStackElement* elmt); + void ClearStack(); bool treeChange; - vXMLTreeElement* current_node_edited; - short int current_node_edited_status; - ChangesStackElement* current_node_edited_stack; + VXMLTreeElement* currentNodeEdited; + short int currentNodeEditedStatus; + ChangesStackElement* currentNodeEditedStack; private slots: - void baseSelectionChanged(int value); - void Element_clicked ( const QModelIndex & index ); + void BaseSelectionChanged(int value); + void ElementClicked ( const QModelIndex & index ); private: Q_DISABLE_COPY(DialogPatternXmlEdit) @@ -222,11 +259,11 @@ private: QDomElement root; QStandardItem *rootNode; //typedef struct rootbases { vXMLTreeElement * root; QString name; } rootbases; - vXMLTreeElement ** rootBases; + VXMLTreeElement ** rootBases; qint16 rootBasesNum; - void readNodes(QDomNode dNode, vXMLTreeElement* root, vXMLTreeView *xmlmodel, bool refresh); - vXMLTreeView* xmlmodel; + void ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXMLTreeView *xmlmodel, bool refresh); + VXMLTreeView* xmlmodel; // Stack of changes diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 288cfcd39..ef7d7b51d 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -546,8 +546,8 @@ void MainWindow::PatternProperties() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::EditPatternCode() { - //TODO : free dialog pointer at end of dialog DialogPatternXmlEdit *Pattern = new DialogPatternXmlEdit (this,doc); + Pattern->setAttribute(Qt::WA_DeleteOnClose,true); Pattern->show(); } From cc572df448d7f8fd57647bb7e2c57590c1be1f73 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Fri, 16 May 2014 17:13:45 +0200 Subject: [PATCH 04/42] Code style --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 80 +++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index 815df0454..df2244b63 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -35,14 +35,15 @@ 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),ui(new Ui::DialogPatternXmlEdit) +DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent,VPattern *xmldoc):QDialog(parent), + ui(new Ui::DialogPatternXmlEdit) { ui->setupUi(this); xmlmodel = new VXMLTreeView(); - currentNodeEdited=0; + currentNodeEdited=nullptr; treeChange=false; - this->changeStackRoot = this->changeStackLast =0; + this->changeStackRoot = this->changeStackLast =nullptr ; doc=xmldoc; root = doc->documentElement(); @@ -75,13 +76,15 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent,VPattern *xmldoc):QDi //ui->treeView_main->expandAll(); // connectors - connect(ui->comboBox_Base_Selection,static_cast(&QComboBox::currentIndexChanged),this,&DialogPatternXmlEdit::BaseSelectionChanged); + 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_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); @@ -96,7 +99,7 @@ DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElem tmp->type=typechange; tmp->changedText=tmp->changedValue=false; - if (changeStackLast==0) + if (changeStackLast==nullptr ) { changeStackLast=changeStackRoot=tmp; } @@ -105,8 +108,8 @@ DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElem changeStackLast->next=tmp; changeStackLast=changeStackLast->next; } - changeStackLast->newValue=changeStackLast->newText=0; - changeStackLast->next=0; + changeStackLast->newValue=changeStackLast->newText=nullptr; + changeStackLast->next=nullptr; return changeStackLast; } @@ -114,7 +117,7 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() { QString Changes=""; ChangesStackElement* currentChange; - if (this->changeStackRoot==0) + if (this->changeStackRoot==nullptr) { Changes="No Changes"; } @@ -156,7 +159,7 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() } } currentChange=currentChange->next; - } while (currentChange != 0); + } while (currentChange != nullptr); } QMessageBox::information(this, "Changes (not REALLY applied for now)", Changes); // TODO : clear stack and apply @@ -188,11 +191,11 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) if (changeStackRoot == elmt) { - if (elmt->newText != 0) + if (elmt->newText != nullptr) { delete elmt->newText; } - if (elmt->newValue != 0) + if (elmt->newValue != nullptr) { delete elmt->newValue; } @@ -204,23 +207,23 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) delete elmt; return; } - while (index->next!=0) { + while (index->next!=nullptr) { if (index->next == elmt) { break; } index=index->next; } - if (index->next == 0) + if (index->next == nullptr) { // TODO : debug error here return; } - if (index->next->newText != 0) + if (index->next->newText != nullptr) { delete index->next->newText; } - if (index->next->newValue != 0) + if (index->next->newValue != nullptr) { delete index->next->newValue; } @@ -237,7 +240,7 @@ void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() ChangesStackElement* newstack; // TODO : maybe assert functions here - if (this->currentNodeEdited == 0) + if (this->currentNodeEdited == nullptr) { return; } @@ -265,7 +268,7 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() bool ok; //clear_edit_data(); // TODO : maybe assert functions here - if (this->currentNodeEdited == 0) + if (this->currentNodeEdited == nullptr) { return; } @@ -327,11 +330,14 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked() QDomNode empty; // empty QNode to pas to create function : maybe a better way to do this ? // TODO : maybe assert functions here - if (this->currentNodeEdited == 0) + if (this->currentNodeEdited == nullptr) + { + return; + } + if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeNode) { return; } - if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeNode) return; QString name = QInputDialog::getText(this, tr("Attribute Name"), tr("Name:"), QLineEdit::Normal, @@ -377,7 +383,7 @@ void DialogPatternXmlEdit::ButtonSetClicked() ChangesStackElement* newstack; // TODO : check if a change has already been done - if (this->currentNodeEdited == 0) return; + if (this->currentNodeEdited == nullptr) return; name=ui->lineEdit_Name->text(); value=ui->lineEdit_Value->text(); bool nameedit,valueedit; @@ -444,13 +450,13 @@ void DialogPatternXmlEdit::ClearEditData() void DialogPatternXmlEdit::ClearStack() { ChangesStackElement * tmp; - while (changeStackRoot != 0) + while (changeStackRoot != nullptr) { - if (changeStackRoot->newText != 0) + if (changeStackRoot->newText != nullptr) { delete changeStackRoot->newText; } - if (changeStackRoot->newValue != 0) + if (changeStackRoot->newValue != nullptr) { delete changeStackRoot->newValue; } @@ -458,7 +464,7 @@ void DialogPatternXmlEdit::ClearStack() changeStackRoot=changeStackRoot->next; delete tmp; } - changeStackLast=0; + changeStackLast=nullptr; } void DialogPatternXmlEdit::BaseSelectionChanged(int value) @@ -515,7 +521,7 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) this->currentNodeEdited=item2; this->currentNodeEditedStatus=0; DialogPatternXmlEdit::ChangesStackElement * local = this->changeStackRoot; - while (local != 0) + while (local != nullptr) { if (local->element == item2) { @@ -562,7 +568,7 @@ DialogPatternXmlEdit::~DialogPatternXmlEdit() //xmlmodel->clearTree(); delete ui; ChangesStackElement * tmp; - while (changeStackRoot != 0) + while (changeStackRoot != nullptr) { tmp=changeStackRoot->next; delete changeStackRoot; @@ -652,7 +658,7 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT // vXMLTreeView Code ----------------------------------------------------------------- VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent) { - current=last=items=0; + current=last=items=nullptr; } void VXMLTreeView::ClearTree() { @@ -661,14 +667,14 @@ void VXMLTreeView::ClearTree() { //clear the chain link TreeElementchain * tmp; - while (items != 0) + while (items != nullptr) { tmp=items; items=items->next; delete tmp; } // reset chain counters - current=last=items=0; + current=last=items=nullptr; } @@ -679,27 +685,27 @@ VXMLTreeView::~VXMLTreeView() void VXMLTreeView::appendchain(VXMLTreeElement* elmt) { - if (last == 0) + if (last == nullptr) { // first element current = new TreeElementchain; - if (current == 0) + if (current == nullptr) { - Q_ASSERT(current != 0); + Q_ASSERT(current != nullptr); // TODO : throw exception } current->elmt=elmt; - current->next=0; + current->next=nullptr; last=items=current; return; } TreeElementchain* temp= new TreeElementchain; - if (temp == 0) + if (temp == nullptr) { - Q_ASSERT(temp != 0); + Q_ASSERT(temp != nullptr); // TODO : throw exception } temp->elmt=elmt; - temp->next=0; + temp->next=nullptr; last->next=temp; last=temp; } From 1489dc6a1cb3fc90d40fc30a43967b4ed1577f3f Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 16 May 2014 19:39:46 +0300 Subject: [PATCH 05/42] Unix Line Endings. Need for Vera++. --HG-- branch : XML Editor --- src/app/dialogs/app/dialogaboutapp.cpp | 130 +- src/app/dialogs/app/dialogaboutapp.h | 114 +- src/app/dialogs/app/dialogpatternxmledit.cpp | 1554 +++++++++--------- src/app/dialogs/app/dialogpatternxmledit.h | 564 +++---- 4 files changed, 1181 insertions(+), 1181 deletions(-) diff --git a/src/app/dialogs/app/dialogaboutapp.cpp b/src/app/dialogs/app/dialogaboutapp.cpp index ffad2670e..310d6f65b 100644 --- a/src/app/dialogs/app/dialogaboutapp.cpp +++ b/src/app/dialogs/app/dialogaboutapp.cpp @@ -1,65 +1,65 @@ -/************************************************************************ - ** - ** @file dialogaboutapp.cpp - ** @author Patrick Proy - ** @date 6 5, 2014 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013 Valentina project - ** 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 "dialogaboutapp.h" -#include "ui_dialogaboutapp.h" -#include "../../version.h" - -DialogAboutApp::DialogAboutApp(QWidget *parent) : - QDialog(parent), - ui(new Ui::DialogAboutApp) -{ - ui->setupUi(this); - - ui->label_Valentina_Version->setText(QString("Valentina %1").arg(APP_VERSION)); - ui->label_QT_Version->setText(tr("Based on Qt %2 (32 bit)").arg(QT_VERSION_STR)); - - QDate date = QLocale(QLocale::C).toDate(QString(__DATE__).simplified(), QLatin1String("MMM d yyyy")); - ui->label_Valentina_Built->setText(tr("Built on %3 at %4").arg(date.toString()).arg(__TIME__)); - - ui->label_Legal_Stuff->setText(WARRANTY); - - ui->pushButton_Web_Site->setText(tr("Web site : %1").arg(VER_COMPANYDOMAIN_STR)); - connect(ui->pushButton_Web_Site, &QPushButton::clicked, - this, &DialogAboutApp::webButtonClicked ); - -} - -DialogAboutApp::~DialogAboutApp() -{ - delete ui; -} - -void DialogAboutApp::webButtonClicked() { - if ( ! QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR))) { - QMessageBox::warning(this, - tr("Warning"), - tr("Cannot open your default browser")); - } - -} +/************************************************************************ + ** + ** @file dialogaboutapp.cpp + ** @author Patrick Proy + ** @date 6 5, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** 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 "dialogaboutapp.h" +#include "ui_dialogaboutapp.h" +#include "../../version.h" + +DialogAboutApp::DialogAboutApp(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogAboutApp) +{ + ui->setupUi(this); + + ui->label_Valentina_Version->setText(QString("Valentina %1").arg(APP_VERSION)); + ui->label_QT_Version->setText(tr("Based on Qt %2 (32 bit)").arg(QT_VERSION_STR)); + + QDate date = QLocale(QLocale::C).toDate(QString(__DATE__).simplified(), QLatin1String("MMM d yyyy")); + ui->label_Valentina_Built->setText(tr("Built on %3 at %4").arg(date.toString()).arg(__TIME__)); + + ui->label_Legal_Stuff->setText(WARRANTY); + + ui->pushButton_Web_Site->setText(tr("Web site : %1").arg(VER_COMPANYDOMAIN_STR)); + connect(ui->pushButton_Web_Site, &QPushButton::clicked, + this, &DialogAboutApp::webButtonClicked ); + +} + +DialogAboutApp::~DialogAboutApp() +{ + delete ui; +} + +void DialogAboutApp::webButtonClicked() { + if ( ! QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR))) { + 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 0b771b9fe..e4df620e3 100644 --- a/src/app/dialogs/app/dialogaboutapp.h +++ b/src/app/dialogs/app/dialogaboutapp.h @@ -1,57 +1,57 @@ -/************************************************************************ - ** - ** @file dialogaboutapp.h - ** @author Patrick Proy - ** @date 6 5, 2014 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013 Valentina project - ** 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 DIALOGABOUTAPP_H -#define DIALOGABOUTAPP_H - -#include - -namespace Ui { -class DialogAboutApp; -} - -class DialogAboutApp : public QDialog -{ - Q_OBJECT - -public: - explicit DialogAboutApp(QWidget *parent = 0); - ~DialogAboutApp(); - -private: - Ui::DialogAboutApp *ui; - Q_DISABLE_COPY(DialogAboutApp) - -private slots: - /** - * @brief Fake button clicked - */ - void webButtonClicked(); -}; - -#endif // DIALOGABOUTAPP_H +/************************************************************************ + ** + ** @file dialogaboutapp.h + ** @author Patrick Proy + ** @date 6 5, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** 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 DIALOGABOUTAPP_H +#define DIALOGABOUTAPP_H + +#include + +namespace Ui { +class DialogAboutApp; +} + +class DialogAboutApp : public QDialog +{ + Q_OBJECT + +public: + explicit DialogAboutApp(QWidget *parent = 0); + ~DialogAboutApp(); + +private: + Ui::DialogAboutApp *ui; + Q_DISABLE_COPY(DialogAboutApp) + +private slots: + /** + * @brief Fake button clicked + */ + void webButtonClicked(); +}; + +#endif // DIALOGABOUTAPP_H diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index df2244b63..3e558680e 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -1,777 +1,777 @@ -/************************************************************************ - ** - ** @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" - - -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), - ui(new Ui::DialogPatternXmlEdit) -{ - ui->setupUi(this); - - xmlmodel = new VXMLTreeView(); - currentNodeEdited=nullptr; - treeChange=false; - this->changeStackRoot = this->changeStackLast =nullptr ; - - doc=xmldoc; - root = doc->documentElement(); - // disable edit trigers : - //ui->treeView_main->editTriggers(QTreeView::NoEditTriggers); - ui->treeView_main->setEditTriggers(QTreeView::NoEditTriggers); - - ui->treeView_main->setWindowTitle("XML"); - - - rootNode = (QStandardItem*) xmlmodel->invisibleRootItem(); - - qint16 drawnum=xmldoc->elementsByTagName("draw").size(); - rootBases = new VXMLTreeElement*[drawnum+1]; - rootBasesNum=1; - 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 drawings"),QVariant(0)); - - //rootBases[0]=(QDomNode) doc->DocumentNode; - rootNode->appendRow(standard_base); - - ReadNodes(root,standard_base,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); -} - -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->next=nullptr; - return changeStackLast; -} - -void DialogPatternXmlEdit::ButtonApplyChangesClicked() -{ - QString Changes=""; - ChangesStackElement* currentChange; - if (this->changeStackRoot==nullptr) - { - Changes="No Changes"; - } - else - { - currentChange=this->changeStackRoot; - do - { - if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) - { - Changes += QString("Added type %1 : ").arg(currentChange->element->getelementType()); - 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(currentChange->element->getelementType()); - 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(currentChange->element->getelementType()); - 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 -} - -void DialogPatternXmlEdit::ButtonCancelClicked() -{ - this->ClearEditData(); - if (this->currentNodeEditedStatus==DialogPatternXmlEdit::ChangeTypeDelete) - { - if (this->currentNodeEdited->getelementType() == VXMLTreeElement::TypeAttr) - { - // Attribute previously deleted -> resore - QFont textfont=currentNodeEdited->font(); - textfont.setStrikeOut(false); - this->currentNodeEdited->setFont(textfont); - this->RemoveChangeStackElement(this->currentNodeEditedStack); - } - else - { - QMessageBox::information(this, "Not Implemented", "Not Implemented"); - } - } -} - -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; - } - 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) - { - // TODO : debug error here - return; - } - if (index->next->newText != nullptr) - { - delete index->next->newText; - } - if (index->next->newValue != nullptr) - { - delete index->next->newValue; - } - 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; - } - - 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); - // 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 but do not add attribute in DOM (will be done in apply). - QDomNode empty; - VXMLTreeElement* tElement = new VXMLTreeElement( - name, - VXMLTreeElement::TypeNode, - empty,true); - - if (!value.isEmpty()) - { - 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); -} - -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); - - 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); -} - -void DialogPatternXmlEdit::ButtonSetClicked() -{ - QString name,value; - ChangesStackElement* newstack; - - // TODO : check if a change has already been done - 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 ) - { - newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeModify); - newstack->element= this->currentNodeEdited; - - if (nameedit == true) - { - newstack->changedText=true; - newstack->newText=new QString(name); - currentNodeEdited->setTreeNodeName(name); - } - if (valueedit == true) - { - newstack->changedValue=true; - newstack->newValue= new QString(value); - currentNodeEdited->setTreeNodeValue(value); - } - - QFont textfont=currentNodeEdited->font(); - textfont.setBold(true); - currentNodeEdited->setFont(textfont); - treeChange=true; - ui->pushButton_Apply_Changes->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); -} - -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 ? - } - 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); - } - 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 = (VXMLTreeElement *)index.internalPointer(); - - // Get child specified by index row/column - VXMLTreeElement * item2 = (VXMLTreeElement *) item->child(index.row(),index.column()); - - // Clear all data and disable buttons - this->ClearEditData(); - // Check status of element in change stack - this->currentNodeEdited=item2; - this->currentNodeEditedStatus=0; - DialogPatternXmlEdit::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); - } - else if (item2->getelementType() == VXMLTreeElement::TypeAttr) - { - ui->label_type_value->setText(tr("Attribute")); - ui->pushButton_Remove_attribute->setEnabled(true); - } -} - -DialogPatternXmlEdit::~DialogPatternXmlEdit() -{ - //xmlmodel->clearTree(); - delete ui; - ChangesStackElement * tmp; - while (changeStackRoot != nullptr) - { - tmp=changeStackRoot->next; - delete changeStackRoot; - changeStackRoot=tmp; - } -} - -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 Code ----------------------------------------------------------------- -VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent) -{ - current=last=items=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; -} - - -// vXMLTreeElement code ----------------------------------------------------------------- - -const short int VXMLTreeElement::TypeNode=1; -const short int VXMLTreeElement::TypeAttr=2; -const short int VXMLTreeElement::TypeRoot=3; - - -VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source,bool editor): QStandardItem(name) -{ - this->elementType=nodetype; - this->DocNode=source; - this->addedNode=editor; - if (!editor) - { - this->DocNode=source; - } - this->treeNodeName=name; - this->treeNodeValue=""; // TODO : translation ? - this->treeNodeValueSet=false, - 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 ""; -} - +/************************************************************************ + ** + ** @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" + + +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), + ui(new Ui::DialogPatternXmlEdit) +{ + ui->setupUi(this); + + xmlmodel = new VXMLTreeView(); + currentNodeEdited=nullptr; + treeChange=false; + this->changeStackRoot = this->changeStackLast =nullptr ; + + doc=xmldoc; + root = doc->documentElement(); + // disable edit trigers : + //ui->treeView_main->editTriggers(QTreeView::NoEditTriggers); + ui->treeView_main->setEditTriggers(QTreeView::NoEditTriggers); + + ui->treeView_main->setWindowTitle("XML"); + + + rootNode = (QStandardItem*) xmlmodel->invisibleRootItem(); + + qint16 drawnum=xmldoc->elementsByTagName("draw").size(); + rootBases = new VXMLTreeElement*[drawnum+1]; + rootBasesNum=1; + 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 drawings"),QVariant(0)); + + //rootBases[0]=(QDomNode) doc->DocumentNode; + rootNode->appendRow(standard_base); + + ReadNodes(root,standard_base,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); +} + +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->next=nullptr; + return changeStackLast; +} + +void DialogPatternXmlEdit::ButtonApplyChangesClicked() +{ + QString Changes=""; + ChangesStackElement* currentChange; + if (this->changeStackRoot==nullptr) + { + Changes="No Changes"; + } + else + { + currentChange=this->changeStackRoot; + do + { + if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) + { + Changes += QString("Added type %1 : ").arg(currentChange->element->getelementType()); + 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(currentChange->element->getelementType()); + 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(currentChange->element->getelementType()); + 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 +} + +void DialogPatternXmlEdit::ButtonCancelClicked() +{ + this->ClearEditData(); + if (this->currentNodeEditedStatus==DialogPatternXmlEdit::ChangeTypeDelete) + { + if (this->currentNodeEdited->getelementType() == VXMLTreeElement::TypeAttr) + { + // Attribute previously deleted -> resore + QFont textfont=currentNodeEdited->font(); + textfont.setStrikeOut(false); + this->currentNodeEdited->setFont(textfont); + this->RemoveChangeStackElement(this->currentNodeEditedStack); + } + else + { + QMessageBox::information(this, "Not Implemented", "Not Implemented"); + } + } +} + +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; + } + 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) + { + // TODO : debug error here + return; + } + if (index->next->newText != nullptr) + { + delete index->next->newText; + } + if (index->next->newValue != nullptr) + { + delete index->next->newValue; + } + 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; + } + + 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); + // 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 but do not add attribute in DOM (will be done in apply). + QDomNode empty; + VXMLTreeElement* tElement = new VXMLTreeElement( + name, + VXMLTreeElement::TypeNode, + empty,true); + + if (!value.isEmpty()) + { + 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); +} + +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); + + 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); +} + +void DialogPatternXmlEdit::ButtonSetClicked() +{ + QString name,value; + ChangesStackElement* newstack; + + // TODO : check if a change has already been done + 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 ) + { + newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeModify); + newstack->element= this->currentNodeEdited; + + if (nameedit == true) + { + newstack->changedText=true; + newstack->newText=new QString(name); + currentNodeEdited->setTreeNodeName(name); + } + if (valueedit == true) + { + newstack->changedValue=true; + newstack->newValue= new QString(value); + currentNodeEdited->setTreeNodeValue(value); + } + + QFont textfont=currentNodeEdited->font(); + textfont.setBold(true); + currentNodeEdited->setFont(textfont); + treeChange=true; + ui->pushButton_Apply_Changes->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); +} + +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 ? + } + 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); + } + 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 = (VXMLTreeElement *)index.internalPointer(); + + // Get child specified by index row/column + VXMLTreeElement * item2 = (VXMLTreeElement *) item->child(index.row(),index.column()); + + // Clear all data and disable buttons + this->ClearEditData(); + // Check status of element in change stack + this->currentNodeEdited=item2; + this->currentNodeEditedStatus=0; + DialogPatternXmlEdit::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); + } + else if (item2->getelementType() == VXMLTreeElement::TypeAttr) + { + ui->label_type_value->setText(tr("Attribute")); + ui->pushButton_Remove_attribute->setEnabled(true); + } +} + +DialogPatternXmlEdit::~DialogPatternXmlEdit() +{ + //xmlmodel->clearTree(); + delete ui; + ChangesStackElement * tmp; + while (changeStackRoot != nullptr) + { + tmp=changeStackRoot->next; + delete changeStackRoot; + changeStackRoot=tmp; + } +} + +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 Code ----------------------------------------------------------------- +VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent) +{ + current=last=items=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; +} + + +// vXMLTreeElement code ----------------------------------------------------------------- + +const short int VXMLTreeElement::TypeNode=1; +const short int VXMLTreeElement::TypeAttr=2; +const short int VXMLTreeElement::TypeRoot=3; + + +VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source,bool editor): QStandardItem(name) +{ + this->elementType=nodetype; + this->DocNode=source; + this->addedNode=editor; + if (!editor) + { + this->DocNode=source; + } + this->treeNodeName=name; + this->treeNodeValue=""; // TODO : translation ? + this->treeNodeValueSet=false, + 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 ""; +} + diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h index 96eb01d8d..6f16892cf 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.h +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -1,282 +1,282 @@ -/************************************************************************ - ** - ** @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) -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, 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(); - QString gettreeNodeName(); - QString gettreeNodeValue(); - bool gettreeNodeValueSet(); - void setTreeNodeName(QString value); - /** - * @brief getelementType - * @return elementType value - */ - short int getelementType(); - -private: - /** - * @brief DocNode : link to current document node - */ - QDomNode DocNode; - - /** - * @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; - Q_DISABLE_COPY(VXMLTreeElement) -}; - -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() ; - - - // Stack of changes definition - typedef struct ChangesStackElement { - short int type; - VXMLTreeElement *element; - QString *newText; - bool changedText; - QString *newValue; - 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; - -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 +/************************************************************************ + ** + ** @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) +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, 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(); + QString gettreeNodeName(); + QString gettreeNodeValue(); + bool gettreeNodeValueSet(); + void setTreeNodeName(QString value); + /** + * @brief getelementType + * @return elementType value + */ + short int getelementType(); + +private: + /** + * @brief DocNode : link to current document node + */ + QDomNode DocNode; + + /** + * @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; + Q_DISABLE_COPY(VXMLTreeElement) +}; + +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() ; + + + // Stack of changes definition + typedef struct ChangesStackElement { + short int type; + VXMLTreeElement *element; + QString *newText; + bool changedText; + QString *newValue; + 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; + +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 From b28bd29092d4c5a2cbc0f368d98007cb80f4df7c Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 16 May 2014 20:00:13 +0300 Subject: [PATCH 06/42] Vera++. --HG-- branch : XML Editor --- src/app/container/vincrement.cpp | 3 +- src/app/dialogs/app/dialogaboutapp.cpp | 16 +- src/app/dialogs/app/dialogaboutapp.h | 5 +- src/app/dialogs/app/dialogpatternxmledit.cpp | 167 +++++++++++-------- src/app/dialogs/app/dialogpatternxmledit.h | 20 +-- src/app/mainwindow.cpp | 8 +- src/app/widgets/vapplication.cpp | 6 +- src/libs/qmuparser/qmuparser.h | 2 +- 8 files changed, 128 insertions(+), 99 deletions(-) diff --git a/src/app/container/vincrement.cpp b/src/app/container/vincrement.cpp index 13f1f6da3..eff25c697 100644 --- a/src/app/container/vincrement.cpp +++ b/src/app/container/vincrement.cpp @@ -30,7 +30,8 @@ //--------------------------------------------------------------------------------------------------------------------- VIncrement::VIncrement() - :id(0), base(0), ksize(50.0), kheight(176.0), description(QString()){} + :id(0), base(0), ksize(50.0), kheight(176.0), description(QString()) +{} VIncrement::VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description) :id(id), base(base), ksize(ksize), kheight(kheight), description(description) diff --git a/src/app/dialogs/app/dialogaboutapp.cpp b/src/app/dialogs/app/dialogaboutapp.cpp index 310d6f65b..04e78721e 100644 --- a/src/app/dialogs/app/dialogaboutapp.cpp +++ b/src/app/dialogs/app/dialogaboutapp.cpp @@ -30,6 +30,10 @@ #include "ui_dialogaboutapp.h" #include "../../version.h" +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- DialogAboutApp::DialogAboutApp(QWidget *parent) : QDialog(parent), ui(new Ui::DialogAboutApp) @@ -50,16 +54,18 @@ DialogAboutApp::DialogAboutApp(QWidget *parent) : } +//--------------------------------------------------------------------------------------------------------------------- DialogAboutApp::~DialogAboutApp() { delete ui; } -void DialogAboutApp::webButtonClicked() { - if ( ! QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR))) { - QMessageBox::warning(this, - tr("Warning"), - tr("Cannot open your default browser")); +//--------------------------------------------------------------------------------------------------------------------- +void DialogAboutApp::webButtonClicked() +{ + 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 e4df620e3..830c869f8 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/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index 3e558680e..f107f4c9a 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -26,24 +26,24 @@ ** *************************************************************************/ - #include "dialogpatternxmledit.h" #include "ui_dialogpatternxmledit.h" - 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), - ui(new Ui::DialogPatternXmlEdit) + +//--------------------------------------------------------------------------------------------------------------------- +DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) + :QDialog(parent), ui(new Ui::DialogPatternXmlEdit) { ui->setupUi(this); xmlmodel = new VXMLTreeView(); currentNodeEdited=nullptr; treeChange=false; - this->changeStackRoot = this->changeStackLast =nullptr ; + this->changeStackRoot = this->changeStackLast = nullptr; doc=xmldoc; root = doc->documentElement(); @@ -59,37 +59,40 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent,VPattern *xmldoc):QDi qint16 drawnum=xmldoc->elementsByTagName("draw").size(); rootBases = new VXMLTreeElement*[drawnum+1]; rootBasesNum=1; - rootBases[0]=new VXMLTreeElement("Valentina",VXMLTreeElement::TypeRoot,root,false); + 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 drawings"),QVariant(0)); + VXMLTreeElement* standard_base = new VXMLTreeElement("Valentina", VXMLTreeElement::TypeRoot, root, false); + ui->comboBox_Base_Selection->addItem(tr("All drawings"), QVariant(0)); //rootBases[0]=(QDomNode) doc->DocumentNode; rootNode->appendRow(standard_base); - ReadNodes(root,standard_base,xmlmodel,false); + ReadNodes(root, standard_base, 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->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); } +//--------------------------------------------------------------------------------------------------------------------- DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElement(short int typechange) { ChangesStackElement* tmp; @@ -113,6 +116,7 @@ DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElem return changeStackLast; } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ButtonApplyChangesClicked() { QString Changes=""; @@ -155,7 +159,7 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() Changes += (currentChange->element->gettreeNodeValueSet()) ? currentChange->element->gettreeNodeValue(): QString(tr("")); Changes += "\n"; - } + } } } currentChange=currentChange->next; @@ -165,6 +169,7 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() // TODO : clear stack and apply } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ButtonCancelClicked() { this->ClearEditData(); @@ -185,6 +190,7 @@ void DialogPatternXmlEdit::ButtonCancelClicked() } } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) { ChangesStackElement* index = this->changeStackRoot; @@ -207,7 +213,8 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) delete elmt; return; } - while (index->next!=nullptr) { + while (index->next!=nullptr) + { if (index->next == elmt) { break; @@ -235,6 +242,7 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) delete elmt; } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() { ChangesStackElement* newstack; @@ -262,6 +270,7 @@ void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() this->ClearEditData(); } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ButtonAddSonClicked() { ChangesStackElement* newstack; @@ -295,12 +304,9 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() // create element tree but do not add attribute in DOM (will be done in apply). QDomNode empty; - VXMLTreeElement* tElement = new VXMLTreeElement( - name, - VXMLTreeElement::TypeNode, - empty,true); + VXMLTreeElement* tElement = new VXMLTreeElement(name, VXMLTreeElement::TypeNode, empty, true); - if (!value.isEmpty()) + if (value.isEmpty() == false) { tElement->setTreeNodeValue(value); } @@ -323,6 +329,7 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() ui->pushButton_Apply_Changes->setEnabled(true); } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ButtonAddAttributeClicked() { ChangesStackElement* newstack; @@ -355,10 +362,7 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked() } // create element tree but do not add attribute in DOM (will be done in apply). - VXMLTreeElement* tElement = new VXMLTreeElement( - name, - VXMLTreeElement::TypeAttr, - empty,true); + VXMLTreeElement* tElement = new VXMLTreeElement(name, VXMLTreeElement::TypeAttr, empty, true); tElement->setTreeNodeValue(value); currentNodeEdited->appendRow(tElement); @@ -377,16 +381,20 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked() ui->pushButton_Apply_Changes->setEnabled(true); } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ButtonSetClicked() { - QString name,value; + QString name, value; ChangesStackElement* newstack; // TODO : check if a change has already been done - if (this->currentNodeEdited == nullptr) return; + if (this->currentNodeEdited == nullptr) + { + return; + } name=ui->lineEdit_Name->text(); value=ui->lineEdit_Value->text(); - bool nameedit,valueedit; + bool nameedit, valueedit; nameedit = (name != currentNodeEdited->gettreeNodeName()) ? true : false; valueedit= (value != currentNodeEdited->gettreeNodeValue()) ? true : false; @@ -418,6 +426,7 @@ void DialogPatternXmlEdit::ButtonSetClicked() } } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::NameTextEdited(QString newtext) { //QMessageBox::information(this, "nameTextEdited", QString("%1").arg(newtext)); @@ -425,6 +434,7 @@ void DialogPatternXmlEdit::NameTextEdited(QString newtext) ui->pushButton_Cancel_Values->setEnabled(true); } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ValueTextEdited(QString newtext) { //QMessageBox::information(this, "valueTextEdited", QString("%1").arg(newtext)); @@ -432,6 +442,7 @@ void DialogPatternXmlEdit::ValueTextEdited(QString newtext) ui->pushButton_Cancel_Values->setEnabled(true); } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ClearEditData() { ui->lineEdit_Name->setText(""); @@ -447,6 +458,7 @@ void DialogPatternXmlEdit::ClearEditData() ui->pushButton_Cancel_Values->setEnabled(false); } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ClearStack() { ChangesStackElement * tmp; @@ -467,6 +479,7 @@ void DialogPatternXmlEdit::ClearStack() changeStackLast=nullptr; } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::BaseSelectionChanged(int value) { QDomNode newbase; @@ -497,7 +510,7 @@ void DialogPatternXmlEdit::BaseSelectionChanged(int value) rootBases[index]->getDocNode(), false); rootNode->appendRow(standard_base); - ReadNodes(rootBases[index]->getDocNode(),standard_base,xmlmodel,true); + ReadNodes(rootBases[index]->getDocNode(), standard_base, xmlmodel, true); ui->treeView_main->setModel(xmlmodel); this->ClearEditData(); @@ -506,6 +519,7 @@ void DialogPatternXmlEdit::BaseSelectionChanged(int value) return; } +//--------------------------------------------------------------------------------------------------------------------- void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) { @@ -513,7 +527,7 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) VXMLTreeElement *item = (VXMLTreeElement *)index.internalPointer(); // Get child specified by index row/column - VXMLTreeElement * item2 = (VXMLTreeElement *) item->child(index.row(),index.column()); + VXMLTreeElement * item2 = (VXMLTreeElement *) item->child(index.row(), index.column()); // Clear all data and disable buttons this->ClearEditData(); @@ -550,7 +564,7 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) ui->label_type_value->setText(tr("Root node"));; ui->pushButton_Add_son->setEnabled(true); } - else if (item2->getelementType() == VXMLTreeElement::TypeNode) + else if (item2->getelementType() == VXMLTreeElement::TypeNode) { ui->label_type_value->setText(tr("Node")); ui->pushButton_Add_attribute->setEnabled(true); @@ -563,6 +577,7 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) } } +//--------------------------------------------------------------------------------------------------------------------- DialogPatternXmlEdit::~DialogPatternXmlEdit() { //xmlmodel->clearTree(); @@ -576,11 +591,12 @@ DialogPatternXmlEdit::~DialogPatternXmlEdit() } } -void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLTreeView* xmlmodel, bool refresh) +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXMLTreeView* xmlmodel, bool refresh) { - QDomNode tNode,tNode2; - VXMLTreeElement* tElement,*tElement2; + QDomNode tNode, tNode2; + VXMLTreeElement* tElement, *tElement2; int totalOfChilds = dNode.childNodes().size(); if (totalOfChilds == 0) { @@ -591,7 +607,7 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT tNode = dNode.childNodes().at(i); if (tNode.nodeType() != QDomNode::CommentNode) { - tElement = new VXMLTreeElement(tNode.nodeName(),VXMLTreeElement::TypeNode,tNode,false); + tElement = new VXMLTreeElement(tNode.nodeName(), VXMLTreeElement::TypeNode, tNode, false); xmlmodel->appendchain(tElement); root->appendRow(tElement); if (tNode.nodeName() == "draw") @@ -605,7 +621,7 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT QVariant(rootBasesNum)); rootBases[rootBasesNum]=new VXMLTreeElement( QString("Drawing %1").arg(tNode.attributes().item(i).nodeValue()), - VXMLTreeElement::TypeRoot,tNode,false);; + VXMLTreeElement::TypeRoot, tNode, false); rootBasesNum++; //QStandardItem* rootNode = (QStandardItem*) rootBases[rootBasesNum]->invisibleRootItem(); //rootNode->appendRow(tElement); @@ -627,7 +643,7 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT tNode2 = tNode.childNodes().at(i); if (tNode2.nodeType() != QDomNode::CommentNode) { - tElement2 = new VXMLTreeElement(tNode2.nodeName(),VXMLTreeElement::TypeNode,tNode2,false); + tElement2 = new VXMLTreeElement(tNode2.nodeName(), VXMLTreeElement::TypeNode, tNode2, false); xmlmodel->appendchain(tElement2); tElement->appendRow(tElement2); } @@ -640,10 +656,8 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT for (int i = 0; i < tNode.attributes().size(); i++) { - tElement2 = new VXMLTreeElement( - tNode.attributes().item(i).nodeName(), - VXMLTreeElement::TypeAttr, - tNode,false); + 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); @@ -655,13 +669,15 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT return; } -// vXMLTreeView Code ----------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent) { current=last=items=nullptr; } -void VXMLTreeView::ClearTree() { +//--------------------------------------------------------------------------------------------------------------------- +void VXMLTreeView::ClearTree() +{ // TODO check if treeitems are deleted with the delete row command of QDom @@ -675,14 +691,13 @@ void VXMLTreeView::ClearTree() { } // reset chain counters current=last=items=nullptr; - } +//--------------------------------------------------------------------------------------------------------------------- VXMLTreeView::~VXMLTreeView() -{ - -} +{} +//--------------------------------------------------------------------------------------------------------------------- void VXMLTreeView::appendchain(VXMLTreeElement* elmt) { if (last == nullptr) @@ -710,43 +725,40 @@ void VXMLTreeView::appendchain(VXMLTreeElement* elmt) last=temp; } - -// vXMLTreeElement code ----------------------------------------------------------------- - const short int VXMLTreeElement::TypeNode=1; const short int VXMLTreeElement::TypeAttr=2; const short int VXMLTreeElement::TypeRoot=3; - -VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source,bool editor): QStandardItem(name) +//--------------------------------------------------------------------------------------------------------------------- +VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source, bool editor) + : QStandardItem(name) { this->elementType=nodetype; this->DocNode=source; this->addedNode=editor; - if (!editor) + if (editor == false) { this->DocNode=source; } this->treeNodeName=name; this->treeNodeValue=""; // TODO : translation ? this->treeNodeValueSet=false, - this->setText(this->displayText()); + this->setText(this->displayText()); switch (this->elementType) { - case VXMLTreeElement::TypeAttr: - this->setBackground(BACKGROUND_COLOR_ATTRIBUTE); - break; - default: - break; + case VXMLTreeElement::TypeAttr: + this->setBackground(BACKGROUND_COLOR_ATTRIBUTE); + break; + default: + break; } } - +//--------------------------------------------------------------------------------------------------------------------- VXMLTreeElement::~VXMLTreeElement() -{ - -} +{} +//--------------------------------------------------------------------------------------------------------------------- void VXMLTreeElement::setTreeNodeValue(QString value) { this->treeNodeValue=value; @@ -754,24 +766,33 @@ void VXMLTreeElement::setTreeNodeValue(QString value) 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() { +//--------------------------------------------------------------------------------------------------------------------- +QString VXMLTreeElement::gettreeNodeValue() +{ // Only return value if it's really set. if (this->treeNodeValueSet) + { return this->treeNodeValue; + } else - return ""; + { + return QString(); + } } - diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h index 6f16892cf..8c5cac0a9 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.h +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -37,21 +37,20 @@ /** * @brief The vXMLTreeElement class : node/attribute of xml pattern. Used by vXMLTreeView * - ********************************************************************************************** */ #define BACKGROUND_COLOR_ATTRIBUTE QBrush(Qt::GlobalColor::cyan) class VXMLTreeElement : public QStandardItem { -public: +public: /** * @brief vXMLTreeElement * @param name : display name * @param nodetype : node type (node, attribute, root) * @param source : the source dom node */ - explicit VXMLTreeElement (QString name, int nodetype, QDomNode source,bool editor); + explicit VXMLTreeElement (QString name, int nodetype, QDomNode source, bool editor); explicit VXMLTreeElement (QString name, int nodetype); @@ -146,7 +145,8 @@ public: /** * @brief The TreeElement struct : chained list of vXMLTreeElement */ - typedef struct TreeElementchain { + typedef struct TreeElementchain + { VXMLTreeElement* elmt; TreeElementchain* next; } TreeElementchain; @@ -197,8 +197,9 @@ inline VXMLTreeView::TreeElementchain * VXMLTreeView::GetItems() //******************************************************************************************** -namespace Ui { -class DialogPatternXmlEdit; +namespace Ui +{ + class DialogPatternXmlEdit; } /** * @brief The DialogPatternXmlEdit class : ui dialog for XML editing of pattern @@ -223,11 +224,12 @@ public: void ButtonDeleteAttributeClicked(); void ButtonAddSonClicked(); void ButtonAddAttributeClicked(); - void ButtonApplyChangesClicked() ; + void ButtonApplyChangesClicked(); // Stack of changes definition - typedef struct ChangesStackElement { + typedef struct ChangesStackElement + { short int type; VXMLTreeElement *element; QString *newText; @@ -277,6 +279,4 @@ private: ChangesStackElement* changeStackLast; }; - - #endif // DIALOGPATTERNXMLEDIT_H diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index ef7d7b51d..93d18d6bc 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -503,7 +503,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(); } @@ -546,8 +546,8 @@ void MainWindow::PatternProperties() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::EditPatternCode() { - DialogPatternXmlEdit *Pattern = new DialogPatternXmlEdit (this,doc); - Pattern->setAttribute(Qt::WA_DeleteOnClose,true); + DialogPatternXmlEdit *Pattern = new DialogPatternXmlEdit (this, doc); + Pattern->setAttribute(Qt::WA_DeleteOnClose, true); Pattern->show(); } @@ -1367,7 +1367,7 @@ void MainWindow::CreateActions() connect(ui->actionOptions, &QAction::triggered, this, &MainWindow::Options); connect(ui->actionPattern_properties, &QAction::triggered, this, &MainWindow::PatternProperties); ui->actionPattern_properties->setEnabled(false); - connect(ui->actionEdit_pattern_code,&QAction::triggered,this,&MainWindow::EditPatternCode); + 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. diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index 43de0a2d7..51160358a 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -148,7 +148,7 @@ QString VApplication::pathToTables() const return QApplication::applicationDirPath() + QStringLiteral("/tables/individual"); #else QDir dir(QApplication::applicationDirPath() + QStringLiteral("/tables/individual")); - if(dir.exist()) + if (dir.exist()) { return dir.absolutePath(); } @@ -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/libs/qmuparser/qmuparser.h b/src/libs/qmuparser/qmuparser.h index 50892dd99..db2a4c8a7 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 -}; + }; //--------------------------------------------------------------------------------------------------------------------- /** From e1c3f418e5d4af7a9e89192b7476df2f2d7d2d8e Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 16 May 2014 20:24:51 +0300 Subject: [PATCH 07/42] GCC warnings. --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 32 ++++++++++---------- src/app/dialogs/app/dialogpatternxmledit.h | 1 - 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index f107f4c9a..0ed508211 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -36,14 +36,14 @@ const short int DialogPatternXmlEdit::ChangeTypeModify=3; //--------------------------------------------------------------------------------------------------------------------- DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) - :QDialog(parent), ui(new Ui::DialogPatternXmlEdit) + :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); xmlmodel = new VXMLTreeView(); - currentNodeEdited=nullptr; - treeChange=false; - this->changeStackRoot = this->changeStackLast = nullptr; doc=xmldoc; root = doc->documentElement(); @@ -53,9 +53,10 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) ui->treeView_main->setWindowTitle("XML"); - + //TODO warning: use of old-style cast [-Wold-style-cast] rootNode = (QStandardItem*) xmlmodel->invisibleRootItem(); + //TODO warning: conversion to 'qint16 {aka short int}' from 'int' may alter its value [-Wconversion] qint16 drawnum=xmldoc->elementsByTagName("draw").size(); rootBases = new VXMLTreeElement*[drawnum+1]; rootBasesNum=1; @@ -524,9 +525,11 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) { // Get item (function returns parent of clicked item) + //TODO warning: use of old-style cast [-Wold-style-cast] VXMLTreeElement *item = (VXMLTreeElement *)index.internalPointer(); // Get child specified by index row/column + //TODO warning: use of old-style cast [-Wold-style-cast] VXMLTreeElement * item2 = (VXMLTreeElement *) item->child(index.row(), index.column()); // Clear all data and disable buttons @@ -670,10 +673,9 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXML } //--------------------------------------------------------------------------------------------------------------------- -VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent) -{ - current=last=items=nullptr; -} +VXMLTreeView::VXMLTreeView(QObject *parent) + : QStandardItemModel(parent), items(nullptr), current(nullptr), last(nullptr) +{} //--------------------------------------------------------------------------------------------------------------------- void VXMLTreeView::ClearTree() @@ -730,19 +732,17 @@ 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, int nodetype, QDomNode source, bool editor) - : QStandardItem(name) + : QStandardItem(name), DocNode(source), addedNode(editor), elementType(nodetype), treeNodeValue(""), + treeNodeValueSet(false), treeNodeName(name) { - this->elementType=nodetype; - this->DocNode=source; - this->addedNode=editor; if (editor == false) { this->DocNode=source; } - this->treeNodeName=name; - this->treeNodeValue=""; // TODO : translation ? - this->treeNodeValueSet=false, this->setText(this->displayText()); switch (this->elementType) { diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h index 8c5cac0a9..b5ad38d42 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.h +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -175,7 +175,6 @@ private: * @brief last : used to parse in iteration. */ TreeElementchain * last; - }; inline VXMLTreeView::TreeElementchain * VXMLTreeView::getCurrent() From 99818c3d285fbd309e99ec7368be642f75cc01c2 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sun, 18 May 2014 21:42:36 +0200 Subject: [PATCH 08/42] Added node delete Added undo change button --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 473 +++++++++++++++---- src/app/dialogs/app/dialogpatternxmledit.h | 59 ++- src/app/dialogs/app/dialogpatternxmledit.ui | 6 +- 3 files changed, 441 insertions(+), 97 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index 0ed508211..764441b9e 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -53,11 +53,9 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) ui->treeView_main->setWindowTitle("XML"); - //TODO warning: use of old-style cast [-Wold-style-cast] - rootNode = (QStandardItem*) xmlmodel->invisibleRootItem(); + rootNode = xmlmodel->invisibleRootItem(); - //TODO warning: conversion to 'qint16 {aka short int}' from 'int' may alter its value [-Wconversion] - qint16 drawnum=xmldoc->elementsByTagName("draw").size(); + int drawnum=xmldoc->elementsByTagName("draw").size(); rootBases = new VXMLTreeElement*[drawnum+1]; rootBasesNum=1; rootBases[0]=new VXMLTreeElement("Valentina", VXMLTreeElement::TypeRoot, root, false); @@ -87,10 +85,133 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) 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_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); +} + +//--------------------------------------------------------------------------------------------------------------------- +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; + stack << currentNode; + while (stack.isEmpty() == false) + { + //pop first element + currentNodeStack=stack.takeFirst(); + if (onlydeactivate==true) + { + currentNodeStack->SetSetlectable(false); + QFont textfont=currentNodeStack->font(); + textfont.setStrikeOut(true); + currentNodeStack->setFont(textfont); + } + // 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(); + } + 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; } //--------------------------------------------------------------------------------------------------------------------- @@ -113,14 +234,136 @@ DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElem 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) { @@ -131,20 +374,21 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() currentChange=this->changeStackRoot; do { + nodetype=stringtype.at(currentChange->element->GetelementType()-1); if (currentChange->type == DialogPatternXmlEdit::ChangeTypeAdd) { - Changes += QString("Added type %1 : ").arg(currentChange->element->getelementType()); - Changes += currentChange->element->gettreeNodeName(); + Changes += QString("Added type %1 : ").arg(nodetype); + Changes += currentChange->element->GettreeNodeName(); Changes += "/"; - Changes += (currentChange->element->gettreeNodeValueSet()) ? - currentChange->element->gettreeNodeValue(): QString(tr("")); + Changes += (currentChange->element->GettreeNodeValueSet()) ? + currentChange->element->GettreeNodeValue(): QString(tr("")); Changes += "\n"; } else { if (currentChange->type == DialogPatternXmlEdit::ChangeTypeModify) { - Changes += QString("Modified type %1 : ").arg(currentChange->element->getelementType()); + Changes += QString("Modified type %1 : ").arg(nodetype); Changes += (currentChange->changedText) ? *currentChange->newText : QString(tr("Unchanged")); Changes += "/"; Changes += (currentChange->changedValue) ? *currentChange->newValue: QString(tr("Unchanged")); @@ -154,11 +398,11 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() { if (currentChange->type == DialogPatternXmlEdit::ChangeTypeDelete) { - Changes += QString("Deleted type %1 : ").arg(currentChange->element->getelementType()); - Changes += currentChange->element->gettreeNodeName(); + Changes += QString("Deleted type %1 : ").arg(nodetype); + Changes += currentChange->element->GettreeNodeName(); Changes += "/"; - Changes += (currentChange->element->gettreeNodeValueSet()) ? - currentChange->element->gettreeNodeValue(): QString(tr("")); + Changes += (currentChange->element->GettreeNodeValueSet()) ? + currentChange->element->GettreeNodeValue(): QString(tr("")); Changes += "\n"; } } @@ -176,17 +420,9 @@ void DialogPatternXmlEdit::ButtonCancelClicked() this->ClearEditData(); if (this->currentNodeEditedStatus==DialogPatternXmlEdit::ChangeTypeDelete) { - if (this->currentNodeEdited->getelementType() == VXMLTreeElement::TypeAttr) + if (this->UndoChange(this->currentNodeEditedStack) == false) { - // Attribute previously deleted -> resore - QFont textfont=currentNodeEdited->font(); - textfont.setStrikeOut(false); - this->currentNodeEdited->setFont(textfont); - this->RemoveChangeStackElement(this->currentNodeEditedStack); - } - else - { - QMessageBox::information(this, "Not Implemented", "Not Implemented"); + QMessageBox::warning(this, "Error", "Cannot undo"); } } } @@ -206,6 +442,14 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) { 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) { @@ -224,7 +468,7 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) } if (index->next == nullptr) { - // TODO : debug error here + Q_ASSERT(index->next != nullptr); return; } if (index->next->newText != nullptr) @@ -235,6 +479,14 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) { 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) { @@ -253,11 +505,32 @@ void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() { return; } - if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeAttr) + 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; @@ -267,6 +540,7 @@ void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() // Activate changes this->treeChange=true; ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); // clear dialog this->ClearEditData(); } @@ -282,7 +556,7 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() { return; } - if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeNode) + if (this->currentNodeEdited->GetelementType() != VXMLTreeElement::TypeNode) { return; } @@ -309,7 +583,7 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() if (value.isEmpty() == false) { - tElement->setTreeNodeValue(value); + tElement->SetTreeNodeValue(value); } currentNodeEdited->appendRow(tElement); xmlmodel->appendchain(tElement); @@ -328,6 +602,7 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() // Activate changes treeChange=true; ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); } //--------------------------------------------------------------------------------------------------------------------- @@ -342,7 +617,7 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked() { return; } - if (this->currentNodeEdited->getelementType() != VXMLTreeElement::TypeNode) + if (this->currentNodeEdited->GetelementType() != VXMLTreeElement::TypeNode) { return; } @@ -365,7 +640,7 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked() // create element tree but do not add attribute in DOM (will be done in apply). VXMLTreeElement* tElement = new VXMLTreeElement(name, VXMLTreeElement::TypeAttr, empty, true); - tElement->setTreeNodeValue(value); + tElement->SetTreeNodeValue(value); currentNodeEdited->appendRow(tElement); xmlmodel->appendchain(tElement); QFont textfont=currentNodeEdited->font(); @@ -380,6 +655,7 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked() // Activate changes treeChange=true; ui->pushButton_Apply_Changes->setEnabled(true); + ui->pushButton_Undo_Last_Change->setEnabled(true); } //--------------------------------------------------------------------------------------------------------------------- @@ -388,7 +664,6 @@ void DialogPatternXmlEdit::ButtonSetClicked() QString name, value; ChangesStackElement* newstack; - // TODO : check if a change has already been done if (this->currentNodeEdited == nullptr) { return; @@ -397,32 +672,67 @@ void DialogPatternXmlEdit::ButtonSetClicked() value=ui->lineEdit_Value->text(); bool nameedit, valueedit; - nameedit = (name != currentNodeEdited->gettreeNodeName()) ? true : false; - valueedit= (value != currentNodeEdited->gettreeNodeValue()) ? true : false; + nameedit = (name != currentNodeEdited->GettreeNodeName()) ? true : false; + valueedit= (value != currentNodeEdited->GettreeNodeValue()) ? true : false; if ( nameedit == true || valueedit == true ) { - newstack = this->CreateStackElement(DialogPatternXmlEdit::ChangeTypeModify); - newstack->element= this->currentNodeEdited; - - if (nameedit == true) - { - newstack->changedText=true; - newstack->newText=new QString(name); - currentNodeEdited->setTreeNodeName(name); + 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); + } } - if (valueedit == true) + else { - newstack->changedValue=true; - newstack->newValue= new QString(value); - currentNodeEdited->setTreeNodeValue(value); - } + 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(); } } @@ -457,6 +767,7 @@ void DialogPatternXmlEdit::ClearEditData() ui->pushButton_Add_son->setEnabled(false); ui->pushButton_Remove_attribute->setEnabled(false); ui->pushButton_Cancel_Values->setEnabled(false); + ui->pushButton_Remove_Node->setEnabled(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -490,7 +801,7 @@ void DialogPatternXmlEdit::BaseSelectionChanged(int value) if (this->treeChange == true) {//Changes have been made : warn ? } - ClearStack(); + this->ClearStack(); ui->pushButton_Apply_Changes->setEnabled(false); index = ui->comboBox_Base_Selection->itemData(value).toInt(); //.convert(QVariant::Int); @@ -503,15 +814,15 @@ void DialogPatternXmlEdit::BaseSelectionChanged(int value) { rootNode->removeRow(0); } - xmlmodel->ClearTree(); + this->xmlmodel->ClearTree(); VXMLTreeElement* standard_base = new VXMLTreeElement( - rootBases[index]->gettreeNodeName(), + rootBases[index]->GettreeNodeName(), VXMLTreeElement::TypeRoot, - rootBases[index]->getDocNode(), + rootBases[index]->GetDocNode(), false); rootNode->appendRow(standard_base); - ReadNodes(rootBases[index]->getDocNode(), standard_base, xmlmodel, true); + ReadNodes(rootBases[index]->GetDocNode(), standard_base, xmlmodel, true); ui->treeView_main->setModel(xmlmodel); this->ClearEditData(); @@ -534,10 +845,15 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) // 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; - DialogPatternXmlEdit::ChangesStackElement * local = this->changeStackRoot; + ChangesStackElement * local = this->changeStackRoot; while (local != nullptr) { if (local->element == item2) @@ -554,26 +870,27 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) local=local->next; } // Fill the dialog and Activate the line edit - if (item2->getelementType() != VXMLTreeElement::TypeRoot) + if (item2->GetelementType() != VXMLTreeElement::TypeRoot) { - ui->lineEdit_Name->setText(currentNodeEdited->gettreeNodeName()); + ui->lineEdit_Name->setText(currentNodeEdited->GettreeNodeName()); ui->lineEdit_Name->setEnabled(true); // Fill value - ui->lineEdit_Value->setText(currentNodeEdited->gettreeNodeValue()); + ui->lineEdit_Value->setText(currentNodeEdited->GettreeNodeValue()); ui->lineEdit_Value->setEnabled(true); } - if (item2->getelementType() == VXMLTreeElement::TypeRoot) + 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) + 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) + else if (item2->GetelementType() == VXMLTreeElement::TypeAttr) { ui->label_type_value->setText(tr("Attribute")); ui->pushButton_Remove_attribute->setEnabled(true); @@ -583,15 +900,9 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) //--------------------------------------------------------------------------------------------------------------------- DialogPatternXmlEdit::~DialogPatternXmlEdit() { - //xmlmodel->clearTree(); + this->ClearStack(); + this->xmlmodel->ClearTree(); delete ui; - ChangesStackElement * tmp; - while (changeStackRoot != nullptr) - { - tmp=changeStackRoot->next; - delete changeStackRoot; - changeStackRoot=tmp; - } } //--------------------------------------------------------------------------------------------------------------------- @@ -637,8 +948,8 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXML do { tElement=xmlmodel->getCurrent()->elmt; - tNode=tElement->getDocNode(); - if (tElement->getelementType() == VXMLTreeElement::TypeNode) + tNode=tElement->GetDocNode(); + if (tElement->GetelementType() == VXMLTreeElement::TypeNode) { totalOfChilds = tNode.childNodes().size(); for (int i=0;isetTreeNodeValue(tNode.nodeValue()); + 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()); + tElement2->SetTreeNodeValue(tNode.attributes().item(i).nodeValue()); tElement->appendRow(tElement2); xmlmodel->appendchain(tElement2); } @@ -737,13 +1048,13 @@ const short int VXMLTreeElement::TypeRoot=3; // ^ VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source, bool editor) : QStandardItem(name), DocNode(source), addedNode(editor), elementType(nodetype), treeNodeValue(""), - treeNodeValueSet(false), treeNodeName(name) + treeNodeValueSet(false), treeNodeName(name), selectable(true) { if (editor == false) { this->DocNode=source; } - this->setText(this->displayText()); + this->setText(this->DisplayText()); switch (this->elementType) { case VXMLTreeElement::TypeAttr: @@ -759,22 +1070,22 @@ VXMLTreeElement::~VXMLTreeElement() {} //--------------------------------------------------------------------------------------------------------------------- -void VXMLTreeElement::setTreeNodeValue(QString value) +void VXMLTreeElement::SetTreeNodeValue(QString value) { this->treeNodeValue=value; this->treeNodeValueSet=true; - this->setText(this->displayText()); + this->setText(this->DisplayText()); } //--------------------------------------------------------------------------------------------------------------------- -void VXMLTreeElement::setTreeNodeName(QString value) +void VXMLTreeElement::SetTreeNodeName(QString value) { this->treeNodeName=value; - this->setText(this->displayText()); + this->setText(this->DisplayText()); } //--------------------------------------------------------------------------------------------------------------------- -QString VXMLTreeElement::displayText() +QString VXMLTreeElement::DisplayText() { if (this->elementType == VXMLTreeElement::TypeRoot) { @@ -784,7 +1095,7 @@ QString VXMLTreeElement::displayText() } //--------------------------------------------------------------------------------------------------------------------- -QString VXMLTreeElement::gettreeNodeValue() +QString VXMLTreeElement::GettreeNodeValue() { // Only return value if it's really set. if (this->treeNodeValueSet) diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h index b5ad38d42..4a8fccdc7 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.h +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -40,6 +40,7 @@ */ #define BACKGROUND_COLOR_ATTRIBUTE QBrush(Qt::GlobalColor::cyan) +#define BACKGROUND_COLOR_INACTIVE_NODE QBrush(Qt::GlobalColor::gray) class VXMLTreeElement : public QStandardItem { @@ -62,26 +63,28 @@ public: * @brief setNodeValue : set value of node (content or attribute) * @param value : the value */ - void setTreeNodeValue(QString value); + void SetTreeNodeValue(QString value); /** * @brief displayText : text to display * @return text to display */ - QString displayText(); + QString DisplayText(); /** * @brief getDocNode * @return current document node */ - QDomNode getDocNode(); - QString gettreeNodeName(); - QString gettreeNodeValue(); - bool gettreeNodeValueSet(); - void setTreeNodeName(QString value); + QDomNode GetDocNode(); + QString GettreeNodeName(); + QString GettreeNodeValue(); + bool GettreeNodeValueSet(); + void SetTreeNodeName(QString value); /** * @brief getelementType * @return elementType value */ - short int getelementType(); + short int GetelementType(); + bool IsSelectable(); + void SetSetlectable(bool value); private: /** @@ -109,25 +112,39 @@ private: * @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 short int VXMLTreeElement::getelementType() +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() +inline QDomNode VXMLTreeElement::GetDocNode() { return this->DocNode; } -inline QString VXMLTreeElement::gettreeNodeName() +inline QString VXMLTreeElement::GettreeNodeName() { return this->treeNodeName; } -inline bool VXMLTreeElement::gettreeNodeValueSet() +inline bool VXMLTreeElement::GettreeNodeValueSet() { return this->treeNodeValueSet; } @@ -224,7 +241,8 @@ public: void ButtonAddSonClicked(); void ButtonAddAttributeClicked(); void ButtonApplyChangesClicked(); - + void ButtonUndoLastChange(); + void ButtonDeleteNode(); // Stack of changes definition typedef struct ChangesStackElement @@ -232,8 +250,10 @@ public: short int type; VXMLTreeElement *element; QString *newText; + QString *oldText; bool changedText; QString *newValue; + QString *oldValue; bool changedValue; ChangesStackElement* next; } ChangesStackElement; @@ -246,6 +266,19 @@ public: 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); private slots: void BaseSelectionChanged(int value); diff --git a/src/app/dialogs/app/dialogpatternxmledit.ui b/src/app/dialogs/app/dialogpatternxmledit.ui index 8b4a7238e..5336d3c21 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.ui +++ b/src/app/dialogs/app/dialogpatternxmledit.ui @@ -200,7 +200,7 @@ - + false @@ -272,12 +272,12 @@ - + false - Cancel changes + Undo last From bb3e8e58bbce7ba6d627ced0a1ea7320f174be3c Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 19 May 2014 08:04:33 +0200 Subject: [PATCH 09/42] Corrected display problems when restoring nodes Changes casting styles --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 37 ++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index 764441b9e..f9379e910 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -154,18 +154,12 @@ bool DialogPatternXmlEdit::DeleteNodeAndSons(VXMLTreeElement * currentNode, bool QList stack; VXMLTreeElement * currentNodeStack; + // First undo all changes on sons stack << currentNode; while (stack.isEmpty() == false) { //pop first element currentNodeStack=stack.takeFirst(); - if (onlydeactivate==true) - { - currentNodeStack->SetSetlectable(false); - QFont textfont=currentNodeStack->font(); - textfont.setStrikeOut(true); - currentNodeStack->setFont(textfont); - } // clear all changes made in son node and not on current or it will loop if (currentNodeStack != currentNode) { @@ -189,6 +183,29 @@ bool DialogPatternXmlEdit::DeleteNodeAndSons(VXMLTreeElement * currentNode, bool } //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) @@ -836,12 +853,10 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) { // Get item (function returns parent of clicked item) - //TODO warning: use of old-style cast [-Wold-style-cast] - VXMLTreeElement *item = (VXMLTreeElement *)index.internalPointer(); + VXMLTreeElement *item = static_cast (index.internalPointer()); // Get child specified by index row/column - //TODO warning: use of old-style cast [-Wold-style-cast] - VXMLTreeElement * item2 = (VXMLTreeElement *) item->child(index.row(), index.column()); + VXMLTreeElement * item2 = static_cast (item->child(index.row(), index.column())); // Clear all data and disable buttons this->ClearEditData(); From dc1d7c5fe2880240b0fc6fc0a079156540f72638 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 19 May 2014 21:03:12 +0300 Subject: [PATCH 10/42] Make xml editor disable on the start. --HG-- branch : XML Editor --- src/app/mainwindow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 93d18d6bc..356ab269e 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1089,6 +1089,8 @@ void MainWindow::SetEnableWidgets(bool enable) } ui->actionTable->setEnabled(enable); ui->actionHistory->setEnabled(enable); + ui->actionPattern_properties->setEnabled(enable); + ui->actionEdit_pattern_code->setEnabled(enable); } //--------------------------------------------------------------------------------------------------------------------- @@ -1368,7 +1370,7 @@ void MainWindow::CreateActions() 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); + ui->actionEdit_pattern_code->setEnabled(false); //Actions for recent files loaded by a main window application. for (int i = 0; i < MaxRecentFiles; ++i) From b83633541bce0c8356ca828a7661620413812557 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 19 May 2014 21:07:51 +0300 Subject: [PATCH 11/42] Hide header. --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.ui | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/dialogs/app/dialogpatternxmledit.ui b/src/app/dialogs/app/dialogpatternxmledit.ui index 5336d3c21..f6ce6432d 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.ui +++ b/src/app/dialogs/app/dialogpatternxmledit.ui @@ -62,6 +62,12 @@ QAbstractItemView::SingleSelection + + true + + + false + From ffda1e5f8db95a7146ea3b256ef185ba94419f47 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 19 May 2014 21:16:26 +0300 Subject: [PATCH 12/42] All pattern pieces instead All drawings. --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index f9379e910..dc1211f7a 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -29,6 +29,8 @@ #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; @@ -63,7 +65,7 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) VXMLTreeElement* standard_base = new VXMLTreeElement("Valentina", VXMLTreeElement::TypeRoot, root, false); - ui->comboBox_Base_Selection->addItem(tr("All drawings"), QVariant(0)); + ui->comboBox_Base_Selection->addItem(tr("All pattern pieces"), QVariant(0)); //rootBases[0]=(QDomNode) doc->DocumentNode; rootNode->appendRow(standard_base); @@ -579,9 +581,7 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() } - QString name = QInputDialog::getText(this, tr("Node Name"), - tr("Name:"), QLineEdit::Normal, - "", &ok); + QString name = QInputDialog::getText(this, tr("Node Name"), tr("Name:"), QLineEdit::Normal, "", &ok); if (ok==false) { return; From 81e8638a6d294bc04ef35b726186d3d68e6a71b9 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sat, 24 May 2014 16:23:47 +0200 Subject: [PATCH 13/42] Change formula input to multiline (in dialogendline only ) Other dialogs don't work for now on this version. --HG-- branch : XML Editor --- src/app/dialogs/tools/dialogendline.cpp | 36 +++++- src/app/dialogs/tools/dialogendline.h | 12 ++ src/app/dialogs/tools/dialogendline.ui | 73 +++++++++-- src/app/dialogs/tools/dialogtool.cpp | 117 ++++++++++++++++-- src/app/dialogs/tools/dialogtool.h | 6 + src/app/share/resources/icon.qrc | 2 + .../share/resources/icon/16x16/go-down.png | Bin 0 -> 756 bytes .../share/resources/icon/16x16/go-next.png | Bin 0 -> 829 bytes 8 files changed, 218 insertions(+), 28 deletions(-) create mode 100644 src/app/share/resources/icon/16x16/go-down.png create mode 100644 src/app/share/resources/icon/16x16/go-next.png diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index b9b1b4279..cdc6aad14 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -39,10 +39,13 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + // TODO : auto extend height on first value length. + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + InitOkCansel(ui); flagFormula = false; flagName = false; @@ -57,7 +60,29 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::FormulaTextChanged() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < 64) + { + ui->plainTextEditFormula->setFixedHeight(64); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -90,7 +115,10 @@ void DialogEndLine::setTypeLine(const QString &value) void DialogEndLine::setFormula(const QString &value) { formula = value; - ui->lineEditFormula->setText(formula); + ui->plainTextEditFormula->setPlainText(value); + //QTextCursor cursor = ui->plainTextEditFormula->textCursor(); + //cursor.insertText(value); + //ui->plainTextEditFormula->setCursor(cursor); } //--------------------------------------------------------------------------------------------------------------------- @@ -111,7 +139,7 @@ void DialogEndLine::DialogAccepted() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->lineEditFormula->text(); + formula = ui->plainTextEditFormula->toPlainText(); 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 7dfc82b03..9765d6cbb 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -112,6 +112,14 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** + * @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) /** @@ -138,6 +146,10 @@ private: * @brief basePointId id base point of line */ quint32 basePointId; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogEndLine::getPointName() const diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 1d6c59866..797078a5a 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -6,8 +6,8 @@ 0 0 - 539 - 559 + 486 + 522 @@ -74,17 +74,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for calculation of length of line + + + 40 + 20 + - + @@ -147,6 +147,56 @@ + + + + + + + 16777215 + 24 + + + + + 4 + 0 + + + + + + + + + 16 + 16 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + :/icon/16x16/go-down.png + :/icon/16x16/go-next.png:/icon/16x16/go-down.png + + + + 16 + 16 + + + + true + + + + + @@ -550,7 +600,6 @@ - lineEditFormula comboBoxBasePoint lineEditNamePoint doubleSpinBoxAngle diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index c10df30c0..ada3d1e16 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -33,10 +33,15 @@ #include +// TODO : for issue #79 +// replace lineEditFormula -> plainTextEditFormula +// delete lineEditFormala everywhrer +// delete PutValHere and eval overloaded functions + //--------------------------------------------------------------------------------------------------------------------- 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), + bOk(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), @@ -283,22 +288,42 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const quint32 &value) const } } -//--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) -{ +{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit Q_CHECK_PTR(lineEdit); Q_CHECK_PTR(listWidget); QListWidgetItem *item = listWidget->currentItem(); Q_CHECK_PTR(item); + 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) +{ + Q_CHECK_PTR(plainTextEdit); + Q_CHECK_PTR(listWidget); + QListWidgetItem *item = listWidget->currentItem(); + Q_CHECK_PTR(item); + + 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()); + */ } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) -{ +{// TODO issue #79 : erase this function after all tools updated to plainTextEdit Q_CHECK_PTR(edit); Q_CHECK_PTR(timer); Q_CHECK_PTR(labelEditFormula); @@ -313,10 +338,26 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) } timer->start(1000); } - //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) +void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *timer) { + Q_CHECK_PTR(edit); + Q_CHECK_PTR(timer); + Q_CHECK_PTR(labelEditFormula); + if (edit->toPlainText().isEmpty()) + { + flag = false; + CheckState(); + QPalette palette = labelEditFormula->palette(); + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + labelEditFormula->setPalette(palette); + return; + } + timer->start(1000); +} + +void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) +{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit Q_CHECK_PTR(edit); Q_CHECK_PTR(timer); Q_CHECK_PTR(label); @@ -350,6 +391,45 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) labelEditFormula->setPalette(palette); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label) +{ + Q_CHECK_PTR(edit); + Q_CHECK_PTR(timer); + Q_CHECK_PTR(label); + Q_CHECK_PTR(labelEditFormula); + QPalette palette = labelEditFormula->palette(); + if (edit->toPlainText().isEmpty()) + { + flag = false; + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + } + else + { + Calculator cal(data); + QString errorMsg; + // Replace line return with spaces for calc + QString formula = edit->toPlainText(); + formula.replace("\n"," "); + qreal result = cal.eval(formula, &errorMsg); + if (errorMsg.isEmpty() == false) + { + label->setText(tr("Error")); + flag = false; + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + } + else + { + label->setText(QString().setNum(result)); + flag = true; + palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); + } + } + CheckState(); + timer->stop(); + labelEditFormula->setPalette(palette); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogTool::setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const { @@ -489,13 +569,22 @@ void DialogTool::DialogRejected() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::FormulaChanged() -{ +{ // TODO issue #79 : erase after full update of tools. QLineEdit* edit = qobject_cast(sender()); if (edit) { ValFormulaChanged(flagFormula, edit, timerFormula); } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::FormulaChanged2() +{ + QPlainTextEdit* edit = qobject_cast(sender()); + if (edit) + { + ValFormulaChanged(flagFormula, edit, timerFormula); + } +} //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowUp() @@ -556,9 +645,9 @@ void DialogTool::ArrowRightDown() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::EvalFormula() { - Q_CHECK_PTR(lineEditFormula); + Q_CHECK_PTR(plainTextEditFormula); Q_CHECK_PTR(labelResultCalculation); - Eval(lineEditFormula, flagFormula, timerFormula, labelResultCalculation); + Eval(plainTextEditFormula, flagFormula, timerFormula, labelResultCalculation); } //--------------------------------------------------------------------------------------------------------------------- @@ -615,19 +704,23 @@ void DialogTool::Increments() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutHere() { - PutValHere(lineEditFormula, listWidget); + PutValHere(plainTextEditFormula, listWidget); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutVal(QListWidgetItem *item) { - Q_CHECK_PTR(lineEditFormula); + Q_CHECK_PTR(plainTextEditFormula); Q_CHECK_PTR(item); - int pos = lineEditFormula->cursorPosition(); + 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()); + */ } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 6def423d3..dc8eed65b 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "../../container/vcontainer.h" #include "../../widgets/vapplication.h" @@ -102,6 +103,7 @@ public slots: * @brief formula check formula */ void FormulaChanged(); + void FormulaChanged2(); /** * @brief ArrowUp set angle value 90 degree */ @@ -214,6 +216,7 @@ protected: * @brief lineEditFormula linEdit for formula */ QLineEdit *lineEditFormula; + QPlainTextEdit *plainTextEditFormula; /** * @brief listWidget listWidget with variables */ @@ -341,6 +344,7 @@ protected: * @param listWidget listWidget */ void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget); + void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget); /** * @brief ValFormulaChanged handle change formula * @param flag flag state of formula @@ -348,6 +352,7 @@ protected: * @param timer timer of formula */ void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); + void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); /** * @brief Eval evaluate formula and show result * @param edit lineEdit of formula @@ -355,6 +360,7 @@ protected: * @param timer timer of formula * @param label label for signal error */ + void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); /** * @brief setCurrentPointId set current point id in combobox diff --git a/src/app/share/resources/icon.qrc b/src/app/share/resources/icon.qrc index 64d48ee8e..75a714bc7 100644 --- a/src/app/share/resources/icon.qrc +++ b/src/app/share/resources/icon.qrc @@ -52,5 +52,7 @@ icon/flags/uk.png icon/Graduation.png icon/individual.png + icon/16x16/go-down.png + icon/16x16/go-next.png diff --git a/src/app/share/resources/icon/16x16/go-down.png b/src/app/share/resources/icon/16x16/go-down.png new file mode 100644 index 0000000000000000000000000000000000000000..a74287892e3a8b6135f8c7239530e962021fdb49 GIT binary patch literal 756 zcmVL}00NXrL_t(I%gvH&NYham#-Foklnb4= za@o|3Y!y0`O(L?SME#IxQR^aQMHY#sU?r(hlTnGLWr>%p6cbXzP$@5r{Lsz3q?1Y` z`(Wgibl#_%{@*@~t(N$`=hMqM&w0-8ea`{@kxx*HxlS)A3yMz2iXpONrZuOKe3UnR z!4jRleAiq{c3i2o_q#(_qav?EwRA4`BPA5HYGqMRB21p*7cBq)_IF4}UA{n>f{jcCNl{kPcsbde3wz4*)8PR0s_`5W7>AxOr@Rn&9TiU@b6{5eP$C z9s4mdgJ1m(lG`vvY61fx^m^K%F=cWd4bN~)GYIk$ zt!4p!uB^Fx0GaWDZUFGQq0&f@aV-|XCo=F=lV7}0k`pDGoMP5G5irkZ?ITVI-0sd~ zGIyvu2ioc?s~rI#DZ6^`gEJFZ~8kU=k=Mtl+)?0000Px#AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy33hNnX8-^I5C8xG5CB}pt-}BS00v@9M??Ss00000`9r&Z00009 za7bBm000tn000tn0p4aGcmMzbQAtEWR5%f}!D&d-aU2KWZ&0s-mJ*Us1VO1U%rsXd zSSG_PgtW{uk143hQd?wRo9X6}_wr(DR?0S-W-}dgF{6cftY*h%g)bx`qx4Nez0jh5 zpY{)h>C|^U57DCP+r6|FiK3g<)nRx+&f+fDBm_h&r6*IGitZ@=HqxS8MIX87GQX!K z=d!hp(pxWCTG*6p#_7e(%Qkfp`Adu#LO!6A803~$iBZWEsQe=? zlsyE8GM|8QZ6IMk^NiBKVKX_~Cy)?lPm~h=kAYo1KiK}k1$gOZuv Date: Sun, 25 May 2014 11:46:54 +0200 Subject: [PATCH 14/42] Change DialogEndLine formula to multiline --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogendline.cpp | 37 +++++- src/app/dialogs/tools/dialogendline.h | 12 ++ src/app/dialogs/tools/dialogendline.ui | 73 +++++++++-- src/app/dialogs/tools/dialogtool.cpp | 117 ++++++++++++++++-- src/app/dialogs/tools/dialogtool.h | 6 + src/app/share/resources/icon.qrc | 2 + .../share/resources/icon/16x16/go-down.png | Bin 0 -> 756 bytes .../share/resources/icon/16x16/go-next.png | Bin 0 -> 829 bytes 8 files changed, 219 insertions(+), 28 deletions(-) create mode 100644 src/app/share/resources/icon/16x16/go-down.png create mode 100644 src/app/share/resources/icon/16x16/go-next.png diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index b9b1b4279..5d938aae6 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -39,10 +39,13 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + // TODO : auto extend height on first value length. + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + InitOkCansel(ui); flagFormula = false; flagName = false; @@ -57,7 +60,29 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::FormulaTextChanged() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::DeployFormulaTextEdit() +{ + if (ui->plainTextEditFormula->height() < 64) + { + ui->plainTextEditFormula->setFixedHeight(64); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -90,7 +115,10 @@ void DialogEndLine::setTypeLine(const QString &value) void DialogEndLine::setFormula(const QString &value) { formula = value; - ui->lineEditFormula->setText(formula); + ui->plainTextEditFormula->setPlainText(value); + //QTextCursor cursor = ui->plainTextEditFormula->textCursor(); + //cursor.insertText(value); + //ui->plainTextEditFormula->setCursor(cursor); } //--------------------------------------------------------------------------------------------------------------------- @@ -111,7 +139,8 @@ void DialogEndLine::DialogAccepted() { 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 7dfc82b03..9765d6cbb 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -112,6 +112,14 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** + * @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) /** @@ -138,6 +146,10 @@ private: * @brief basePointId id base point of line */ quint32 basePointId; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogEndLine::getPointName() const diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 1d6c59866..797078a5a 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -6,8 +6,8 @@ 0 0 - 539 - 559 + 486 + 522 @@ -74,17 +74,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - - Formula for calculation of length of line + + + 40 + 20 + - + @@ -147,6 +147,56 @@ + + + + + + + 16777215 + 24 + + + + + 4 + 0 + + + + + + + + + 16 + 16 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + :/icon/16x16/go-down.png + :/icon/16x16/go-next.png:/icon/16x16/go-down.png + + + + 16 + 16 + + + + true + + + + + @@ -550,7 +600,6 @@ - lineEditFormula comboBoxBasePoint lineEditNamePoint doubleSpinBoxAngle diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index c10df30c0..ada3d1e16 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -33,10 +33,15 @@ #include +// TODO : for issue #79 +// replace lineEditFormula -> plainTextEditFormula +// delete lineEditFormala everywhrer +// delete PutValHere and eval overloaded functions + //--------------------------------------------------------------------------------------------------------------------- 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), + bOk(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), @@ -283,22 +288,42 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const quint32 &value) const } } -//--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) -{ +{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit Q_CHECK_PTR(lineEdit); Q_CHECK_PTR(listWidget); QListWidgetItem *item = listWidget->currentItem(); Q_CHECK_PTR(item); + 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) +{ + Q_CHECK_PTR(plainTextEdit); + Q_CHECK_PTR(listWidget); + QListWidgetItem *item = listWidget->currentItem(); + Q_CHECK_PTR(item); + + 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()); + */ } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) -{ +{// TODO issue #79 : erase this function after all tools updated to plainTextEdit Q_CHECK_PTR(edit); Q_CHECK_PTR(timer); Q_CHECK_PTR(labelEditFormula); @@ -313,10 +338,26 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) } timer->start(1000); } - //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) +void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *timer) { + Q_CHECK_PTR(edit); + Q_CHECK_PTR(timer); + Q_CHECK_PTR(labelEditFormula); + if (edit->toPlainText().isEmpty()) + { + flag = false; + CheckState(); + QPalette palette = labelEditFormula->palette(); + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + labelEditFormula->setPalette(palette); + return; + } + timer->start(1000); +} + +void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) +{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit Q_CHECK_PTR(edit); Q_CHECK_PTR(timer); Q_CHECK_PTR(label); @@ -350,6 +391,45 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) labelEditFormula->setPalette(palette); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label) +{ + Q_CHECK_PTR(edit); + Q_CHECK_PTR(timer); + Q_CHECK_PTR(label); + Q_CHECK_PTR(labelEditFormula); + QPalette palette = labelEditFormula->palette(); + if (edit->toPlainText().isEmpty()) + { + flag = false; + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + } + else + { + Calculator cal(data); + QString errorMsg; + // Replace line return with spaces for calc + QString formula = edit->toPlainText(); + formula.replace("\n"," "); + qreal result = cal.eval(formula, &errorMsg); + if (errorMsg.isEmpty() == false) + { + label->setText(tr("Error")); + flag = false; + palette.setColor(labelEditFormula->foregroundRole(), Qt::red); + } + else + { + label->setText(QString().setNum(result)); + flag = true; + palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); + } + } + CheckState(); + timer->stop(); + labelEditFormula->setPalette(palette); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogTool::setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const { @@ -489,13 +569,22 @@ void DialogTool::DialogRejected() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::FormulaChanged() -{ +{ // TODO issue #79 : erase after full update of tools. QLineEdit* edit = qobject_cast(sender()); if (edit) { ValFormulaChanged(flagFormula, edit, timerFormula); } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::FormulaChanged2() +{ + QPlainTextEdit* edit = qobject_cast(sender()); + if (edit) + { + ValFormulaChanged(flagFormula, edit, timerFormula); + } +} //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowUp() @@ -556,9 +645,9 @@ void DialogTool::ArrowRightDown() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::EvalFormula() { - Q_CHECK_PTR(lineEditFormula); + Q_CHECK_PTR(plainTextEditFormula); Q_CHECK_PTR(labelResultCalculation); - Eval(lineEditFormula, flagFormula, timerFormula, labelResultCalculation); + Eval(plainTextEditFormula, flagFormula, timerFormula, labelResultCalculation); } //--------------------------------------------------------------------------------------------------------------------- @@ -615,19 +704,23 @@ void DialogTool::Increments() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutHere() { - PutValHere(lineEditFormula, listWidget); + PutValHere(plainTextEditFormula, listWidget); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutVal(QListWidgetItem *item) { - Q_CHECK_PTR(lineEditFormula); + Q_CHECK_PTR(plainTextEditFormula); Q_CHECK_PTR(item); - int pos = lineEditFormula->cursorPosition(); + 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()); + */ } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 6def423d3..dc8eed65b 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "../../container/vcontainer.h" #include "../../widgets/vapplication.h" @@ -102,6 +103,7 @@ public slots: * @brief formula check formula */ void FormulaChanged(); + void FormulaChanged2(); /** * @brief ArrowUp set angle value 90 degree */ @@ -214,6 +216,7 @@ protected: * @brief lineEditFormula linEdit for formula */ QLineEdit *lineEditFormula; + QPlainTextEdit *plainTextEditFormula; /** * @brief listWidget listWidget with variables */ @@ -341,6 +344,7 @@ protected: * @param listWidget listWidget */ void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget); + void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget); /** * @brief ValFormulaChanged handle change formula * @param flag flag state of formula @@ -348,6 +352,7 @@ protected: * @param timer timer of formula */ void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); + void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); /** * @brief Eval evaluate formula and show result * @param edit lineEdit of formula @@ -355,6 +360,7 @@ protected: * @param timer timer of formula * @param label label for signal error */ + void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); /** * @brief setCurrentPointId set current point id in combobox diff --git a/src/app/share/resources/icon.qrc b/src/app/share/resources/icon.qrc index 64d48ee8e..7fae467c5 100644 --- a/src/app/share/resources/icon.qrc +++ b/src/app/share/resources/icon.qrc @@ -52,5 +52,7 @@ icon/flags/uk.png icon/Graduation.png icon/individual.png + icon/16x16/go-down.png + icon/16x16/go-next.png diff --git a/src/app/share/resources/icon/16x16/go-down.png b/src/app/share/resources/icon/16x16/go-down.png new file mode 100644 index 0000000000000000000000000000000000000000..a74287892e3a8b6135f8c7239530e962021fdb49 GIT binary patch literal 756 zcmVL}00NXrL_t(I%gvH&NYham#-Foklnb4= za@o|3Y!y0`O(L?SME#IxQR^aQMHY#sU?r(hlTnGLWr>%p6cbXzP$@5r{Lsz3q?1Y` z`(Wgibl#_%{@*@~t(N$`=hMqM&w0-8ea`{@kxx*HxlS)A3yMz2iXpONrZuOKe3UnR z!4jRleAiq{c3i2o_q#(_qav?EwRA4`BPA5HYGqMRB21p*7cBq)_IF4}UA{n>f{jcCNl{kPcsbde3wz4*)8PR0s_`5W7>AxOr@Rn&9TiU@b6{5eP$C z9s4mdgJ1m(lG`vvY61fx^m^K%F=cWd4bN~)GYIk$ zt!4p!uB^Fx0GaWDZUFGQq0&f@aV-|XCo=F=lV7}0k`pDGoMP5G5irkZ?ITVI-0sd~ zGIyvu2ioc?s~rI#DZ6^`gEJFZ~8kU=k=Mtl+)?0000Px#AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy33hNnX8-^I5C8xG5CB}pt-}BS00v@9M??Ss00000`9r&Z00009 za7bBm000tn000tn0p4aGcmMzbQAtEWR5%f}!D&d-aU2KWZ&0s-mJ*Us1VO1U%rsXd zSSG_PgtW{uk143hQd?wRo9X6}_wr(DR?0S-W-}dgF{6cftY*h%g)bx`qx4Nez0jh5 zpY{)h>C|^U57DCP+r6|FiK3g<)nRx+&f+fDBm_h&r6*IGitZ@=HqxS8MIX87GQX!K z=d!hp(pxWCTG*6p#_7e(%Qkfp`Adu#LO!6A803~$iBZWEsQe=? zlsyE8GM|8QZ6IMk^NiBKVKX_~Cy)?lPm~h=kAYo1KiK}k1$gOZuv Date: Sun, 25 May 2014 21:54:17 +0200 Subject: [PATCH 15/42] First change for "apply button" (works only when modifying an existing point). --HG-- branch : DialogTools --- src/app/dialogs/app/dialoghistory.h | 4 +++ src/app/dialogs/app/dialogincrements.h | 4 +++ src/app/dialogs/tools/dialogalongline.cpp | 2 +- src/app/dialogs/tools/dialogalongline.h | 4 +++ src/app/dialogs/tools/dialogarc.cpp | 2 +- src/app/dialogs/tools/dialogarc.h | 4 +++ src/app/dialogs/tools/dialogbisector.cpp | 2 +- src/app/dialogs/tools/dialogbisector.h | 4 +++ src/app/dialogs/tools/dialogcutarc.cpp | 2 +- src/app/dialogs/tools/dialogcutarc.h | 4 +++ src/app/dialogs/tools/dialogcutspline.cpp | 2 +- src/app/dialogs/tools/dialogcutspline.h | 4 +++ src/app/dialogs/tools/dialogcutsplinepath.cpp | 2 +- src/app/dialogs/tools/dialogcutsplinepath.h | 4 +++ src/app/dialogs/tools/dialogdetail.h | 4 +++ src/app/dialogs/tools/dialogendline.cpp | 28 ++++++++++++++++--- src/app/dialogs/tools/dialogendline.h | 10 +++++++ src/app/dialogs/tools/dialogendline.ui | 2 +- src/app/dialogs/tools/dialogheight.cpp | 2 +- src/app/dialogs/tools/dialogheight.h | 4 +++ src/app/dialogs/tools/dialogline.cpp | 2 +- src/app/dialogs/tools/dialogline.h | 4 +++ src/app/dialogs/tools/dialoglineintersect.cpp | 2 +- src/app/dialogs/tools/dialoglineintersect.h | 4 +++ src/app/dialogs/tools/dialognormal.cpp | 2 +- src/app/dialogs/tools/dialognormal.h | 4 +++ src/app/dialogs/tools/dialogpointofcontact.h | 4 +++ .../tools/dialogpointofintersection.cpp | 2 +- .../dialogs/tools/dialogpointofintersection.h | 4 +++ src/app/dialogs/tools/dialogshoulderpoint.cpp | 2 +- src/app/dialogs/tools/dialogshoulderpoint.h | 4 +++ src/app/dialogs/tools/dialogsinglepoint.cpp | 2 +- src/app/dialogs/tools/dialogsinglepoint.h | 4 +++ src/app/dialogs/tools/dialogspline.cpp | 2 +- src/app/dialogs/tools/dialogspline.h | 4 +++ src/app/dialogs/tools/dialogsplinepath.cpp | 2 +- src/app/dialogs/tools/dialogsplinepath.h | 4 +++ src/app/dialogs/tools/dialogtool.cpp | 6 ++++ src/app/dialogs/tools/dialogtool.h | 20 ++++++++++--- src/app/dialogs/tools/dialogtriangle.cpp | 2 +- src/app/dialogs/tools/dialogtriangle.h | 4 +++ src/app/dialogs/tools/dialoguniondetails.cpp | 2 +- src/app/dialogs/tools/dialoguniondetails.h | 4 +++ src/app/tools/drawTools/vdrawtool.cpp | 13 +++++++++ src/app/tools/drawTools/vdrawtool.h | 5 ++++ 45 files changed, 176 insertions(+), 26 deletions(-) diff --git a/src/app/dialogs/app/dialoghistory.h b/src/app/dialogs/app/dialoghistory.h index d3c5aea69..eaad3b37d 100644 --- a/src/app/dialogs/app/dialoghistory.h +++ b/src/app/dialogs/app/dialoghistory.h @@ -57,6 +57,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} /** * @brief cellClicked changed history record * @param row number row in table diff --git a/src/app/dialogs/app/dialogincrements.h b/src/app/dialogs/app/dialogincrements.h index f7e8e6fa3..685aae20c 100644 --- a/src/app/dialogs/app/dialogincrements.h +++ b/src/app/dialogs/app/dialogincrements.h @@ -54,6 +54,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(){} /** * @brief clickedToolButtonAdd create new row in table */ diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index c6f643d9d..d83ce620e 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -43,7 +43,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) flagFormula = false; flagName = false; - InitOkCansel(ui); + InitOkCancel(ui); CheckState(); FillComboBoxTypeLine(ui->comboBoxLineType); diff --git a/src/app/dialogs/tools/dialogalongline.h b/src/app/dialogs/tools/dialogalongline.h index 947c31793..0d22f2e65 100644 --- a/src/app/dialogs/tools/dialogalongline.h +++ b/src/app/dialogs/tools/dialogalongline.h @@ -113,6 +113,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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(DialogAlongLine) /** diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index bbb17d47b..7a79c6448 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -48,7 +48,7 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) timerF2 = new QTimer(this); connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); - InitOkCansel(ui); + InitOkCancel(ui); FillComboBoxPoints(ui->comboBoxBasePoint); diff --git a/src/app/dialogs/tools/dialogarc.h b/src/app/dialogs/tools/dialogarc.h index 24840e2f2..dda31681b 100644 --- a/src/app/dialogs/tools/dialogarc.h +++ b/src/app/dialogs/tools/dialogarc.h @@ -101,6 +101,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} /** * @brief ValChenged show description angles of lines * @param row number of row diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 35050a844..cc2d49581 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -42,7 +42,7 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCansel(ui); + InitOkCancel(ui); flagFormula = false; flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogbisector.h b/src/app/dialogs/tools/dialogbisector.h index 89fab7a10..e428a3f0a 100644 --- a/src/app/dialogs/tools/dialogbisector.h +++ b/src/app/dialogs/tools/dialogbisector.h @@ -124,6 +124,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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(DialogBisector) /** diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 55844e496..1dabfc556 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -40,7 +40,7 @@ DialogCutArc::DialogCutArc(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/dialogcutarc.h b/src/app/dialogs/tools/dialogcutarc.h index 8f9d93ed7..2005f245e 100644 --- a/src/app/dialogs/tools/dialogcutarc.h +++ b/src/app/dialogs/tools/dialogcutarc.h @@ -92,6 +92,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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(DialogCutArc) /** diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 1730ba10e..ff3026fac 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -39,7 +39,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 35041872f..9bcff379e 100644 --- a/src/app/dialogs/tools/dialogcutspline.h +++ b/src/app/dialogs/tools/dialogcutspline.h @@ -92,6 +92,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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 fee2d8f04..35d707aa7 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -41,7 +41,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 417e85d94..6614d5b42 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.h +++ b/src/app/dialogs/tools/dialogcutsplinepath.h @@ -92,6 +92,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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.h b/src/app/dialogs/tools/dialogdetail.h index b2edce30b..f76b0ddb0 100644 --- a/src/app/dialogs/tools/dialogdetail.h +++ b/src/app/dialogs/tools/dialogdetail.h @@ -66,6 +66,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} /** * @brief BiasXChanged changed value of offset for object respect to x * @param d value in mm diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 5d938aae6..f143d9fb9 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -46,7 +46,7 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) // TODO : auto extend height on first value length. this->formulaBaseHeight=ui->plainTextEditFormula->height(); - InitOkCansel(ui); + InitOkCancel(ui); flagFormula = false; flagName = false; CheckState(); @@ -56,12 +56,14 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) InitArrow(ui); + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEndLine::PutHere); 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->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit); + //ui-> } //--------------------------------------------------------------------------------------------------------------------- @@ -75,9 +77,9 @@ void DialogEndLine::FormulaTextChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogEndLine::DeployFormulaTextEdit() { - if (ui->plainTextEditFormula->height() < 64) + if (ui->plainTextEditFormula->height() < DIALOGENDLINE_MAX_FORMULA_HEIGHT) { - ui->plainTextEditFormula->setFixedHeight(64); + ui->plainTextEditFormula->setFixedHeight(DIALOGENDLINE_MAX_FORMULA_HEIGHT); } else { @@ -115,6 +117,12 @@ void DialogEndLine::setTypeLine(const QString &value) void DialogEndLine::setFormula(const QString &value) { formula = value; + // 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(value); //QTextCursor cursor = ui->plainTextEditFormula->textCursor(); //cursor.insertText(value); @@ -136,6 +144,19 @@ void DialogEndLine::setBasePointId(const quint32 &value, const quint32 &id) //--------------------------------------------------------------------------------------------------------------------- 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); @@ -143,7 +164,6 @@ void DialogEndLine::DialogAccepted() 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 9765d6cbb..38a4a6ba1 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; @@ -112,6 +114,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(); /** * @brief DeployFormulaTextEdit grow or shrink formula input */ @@ -122,6 +128,10 @@ public slots: void FormulaTextChanged(); private: Q_DISABLE_COPY(DialogEndLine) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 797078a5a..fe66d84b3 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -593,7 +593,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index 455479962..a07e09a11 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -38,7 +38,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 63ebbf5bb..241e609e5 100644 --- a/src/app/dialogs/tools/dialogheight.h +++ b/src/app/dialogs/tools/dialogheight.h @@ -114,6 +114,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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 a87a5410c..0e7512024 100644 --- a/src/app/dialogs/tools/dialogline.cpp +++ b/src/app/dialogs/tools/dialogline.cpp @@ -36,7 +36,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 2978b6d1a..f04a5a3bc 100644 --- a/src/app/dialogs/tools/dialogline.h +++ b/src/app/dialogs/tools/dialogline.h @@ -91,6 +91,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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 9951ee884..a28468175 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -38,7 +38,7 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent { ui->setupUi(this); number = 0; - InitOkCansel(ui); + InitOkCancel(ui); labelEditNamePoint = ui->labelEditNamePoint; flagName = false; diff --git a/src/app/dialogs/tools/dialoglineintersect.h b/src/app/dialogs/tools/dialoglineintersect.h index 3196210f7..7fd400520 100644 --- a/src/app/dialogs/tools/dialoglineintersect.h +++ b/src/app/dialogs/tools/dialoglineintersect.h @@ -111,6 +111,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} /** * @brief P1Line1Changed changed first point of first line * @param index index in list diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index 81ebf9dd3..9cfc40b89 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -42,7 +42,7 @@ DialogNormal::DialogNormal(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/dialognormal.h b/src/app/dialogs/tools/dialognormal.h index a47aae457..ad0658afe 100644 --- a/src/app/dialogs/tools/dialognormal.h +++ b/src/app/dialogs/tools/dialognormal.h @@ -123,6 +123,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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(DialogNormal) /** diff --git a/src/app/dialogs/tools/dialogpointofcontact.h b/src/app/dialogs/tools/dialogpointofcontact.h index d99ae957d..acde2b352 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.h +++ b/src/app/dialogs/tools/dialogpointofcontact.h @@ -109,6 +109,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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(DialogPointOfContact) /** diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index 82538e73c..a5e09ef40 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -38,7 +38,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 8c8b98c2a..fac2f9ec4 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.h +++ b/src/app/dialogs/tools/dialogpointofintersection.h @@ -93,6 +93,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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 65fb7f069..5d5d00d92 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -43,7 +43,7 @@ DialogShoulderPoint::DialogShoulderPoint(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/dialogshoulderpoint.h b/src/app/dialogs/tools/dialogshoulderpoint.h index 9d9130eb6..ba9f57454 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.h +++ b/src/app/dialogs/tools/dialogshoulderpoint.h @@ -124,6 +124,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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(DialogShoulderPoint) /** diff --git a/src/app/dialogs/tools/dialogsinglepoint.cpp b/src/app/dialogs/tools/dialogsinglepoint.cpp index 80d5c8fb0..6e929ee23 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.cpp +++ b/src/app/dialogs/tools/dialogsinglepoint.cpp @@ -40,7 +40,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 f0da08178..b7b3754a9 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.h +++ b/src/app/dialogs/tools/dialogsinglepoint.h @@ -76,6 +76,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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 1030aea47..b76e06f3b 100644 --- a/src/app/dialogs/tools/dialogspline.cpp +++ b/src/app/dialogs/tools/dialogspline.cpp @@ -37,7 +37,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 47aa5a5c5..5fa0dd978 100644 --- a/src/app/dialogs/tools/dialogspline.h +++ b/src/app/dialogs/tools/dialogspline.h @@ -131,6 +131,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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 67b732663..9ac242a42 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -37,7 +37,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); diff --git a/src/app/dialogs/tools/dialogsplinepath.h b/src/app/dialogs/tools/dialogsplinepath.h index 8e1ddca4a..040bcb5b5 100644 --- a/src/app/dialogs/tools/dialogsplinepath.h +++ b/src/app/dialogs/tools/dialogsplinepath.h @@ -76,6 +76,10 @@ public slots: * @brief PointChanged selected another point in list * @param row number of row */ + /** TODO ISSUE 79 : create real function + * @brief DialogApply apply data and emit signal about applied dialog. + */ + virtual void DialogApply(){} void PointChanged(int row); /** * @brief currentPointChanged changed point in combo box diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index ada3d1e16..543f63a05 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -855,3 +855,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 dc8eed65b..1231dd919 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -75,6 +75,10 @@ signals: * @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 @@ -95,6 +99,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); + /** + * @brief DialogApply save data and emit signal DialogApplied. + */ + virtual void DialogApply(); /** * @brief DialogRejected emit signal dialog rejected */ @@ -453,15 +461,19 @@ protected: connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves); } template - void InitOkCansel(T *ui) + void InitOkCancel(T *ui) { bOk = ui->buttonBox->button(QDialogButtonBox::Ok); Q_CHECK_PTR(bOk); 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); + Q_CHECK_PTR(bCancel); + connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); + // TODO issue #79 + QPushButton *bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + Q_CHECK_PTR(bApply); + connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); } private: /** diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index 9a1ebb5ce..63da15c19 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -38,7 +38,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 609e94cea..1756f55bf 100644 --- a/src/app/dialogs/tools/dialogtriangle.h +++ b/src/app/dialogs/tools/dialogtriangle.h @@ -115,6 +115,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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 d9a7135ce..7c430437f 100644 --- a/src/app/dialogs/tools/dialoguniondetails.cpp +++ b/src/app/dialogs/tools/dialoguniondetails.cpp @@ -35,7 +35,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 b38dcbdfa..93a4a18f9 100644 --- a/src/app/dialogs/tools/dialoguniondetails.h +++ b/src/app/dialogs/tools/dialoguniondetails.h @@ -81,6 +81,10 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ 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/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 25f329719..9b654a862 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -94,6 +94,19 @@ 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::SetFactor(qreal factor) { diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index af389a880..b00a23c13 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -84,6 +84,10 @@ public slots: * @param result keep result working dialog. */ virtual void FullUpdateFromGui(int result); + /** + * @brief FullUpdateFromGuiApply refresh tool data after change in options but do not delete dialog + */ + virtual void FullUpdateFromGuiApply(); /** * @brief SetFactor set current scale factor of scene. * @param factor scene scale factor. @@ -157,6 +161,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); From 2913e55024589b1d7278064d60d94cad53eedcda Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sun, 25 May 2014 23:50:21 +0200 Subject: [PATCH 16/42] Apply button works like ok button in first dialog. Still needs more code to be able to update on first dialog --HG-- branch : DialogTools --- src/app/mainwindow.cpp | 56 ++++++++++++++++++++++++++++++++++++++++-- src/app/mainwindow.h | 23 ++++++++++++++++- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 47155b812..22a4961de 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -202,6 +202,7 @@ void MainWindow::OptionDraw() } //--------------------------------------------------------------------------------------------------------------------- +// TODO Issue 79 : remove function template void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot) @@ -230,6 +231,36 @@ void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString & } } +//--------------------------------------------------------------------------------------------------------------------- +// TODO Issue 79 : rename to SetToolButton +template +void MainWindow::SetToolButton2(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())) + { + Q_CHECK_PTR(tButton); + tButton->setChecked(true); + } + } +} //--------------------------------------------------------------------------------------------------------------------- template void MainWindow::ClosedDialog(int result) @@ -242,11 +273,32 @@ void MainWindow::ClosedDialog(int result) ArrowTool(); } +//--------------------------------------------------------------------------------------------------------------------- +template +void MainWindow::ApplyDialog() +{// TODO ISSUE 79 : copy + Q_CHECK_PTR(dialogTool); + + // TODO ISSUE 79 : Only create on first apply for now, + // for updating : VDataTool * stored in DialogTool ? + DrawTool::Create(dialogTool, currentScene, doc, pattern); + + ArrowTool(); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolEndLine(bool checked) { - SetToolButton(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), - &MainWindow::ClosedDialogEndLine); +// SetToolButton(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), +// &MainWindow::ClosedDialogEndLine); + SetToolButton2(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), + &MainWindow::ClosedDialogEndLine,&MainWindow::ApplyDialogEndLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ApplyDialogEndLine() +{ // TODO ISSUE 79 : copy + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 9a8f8407f..c0c70d47a 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -254,6 +254,10 @@ public slots: * @param result result of dialog working. */ void ClosedDialogEndLine(int result); + /** // TODO ISSUE 79 : copy + * @brief ApplyDialogEndLine actions after apply in DialogEndLine. + */ + void ApplyDialogEndLine(); /** * @brief ClosedDialogLine actions after closing DialogLine. * @param result result of dialog working. @@ -503,7 +507,7 @@ private: */ void RestoreCurrentScene(); template - /** + /** // TODO ISSUE 79 : delete * @brief SetToolButton set tool and show dialog. * @param checked true if tool button checked. * @param t tool type. @@ -513,6 +517,18 @@ private: */ void SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot); + /** // TODO ISSUE 79 : copy + * @brief SetToolButton 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. + */ + template + void SetToolButton2(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, + Func closeDialogSlot, Func2 applyDialogSlot); /** * @brief MinimumScrollBar set scroll bar to minimum. */ @@ -523,6 +539,11 @@ private: * @param result result working dialog. */ void ClosedDialog(int result); + /** // TODO ISSUE 79 : copy + * @brief ApplyDialog handle apply in dialog + */ + template + void ApplyDialog(); /** * @brief SavePattern save pattern file. * @param fileName pattern file name. From e645e671de5d611594ebc3fc37f82b89a4a4f56f Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 26 May 2014 09:03:51 +0200 Subject: [PATCH 17/42] First test for apply on creation --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogtool.cpp | 2 +- src/app/dialogs/tools/dialogtool.h | 4 ++++ src/app/mainwindow.cpp | 15 +++++++++++---- src/app/tools/drawTools/vtoolendline.cpp | 8 +++++--- src/app/tools/drawTools/vtoolendline.h | 6 ++++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 543f63a05..40cf59383 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -45,7 +45,7 @@ DialogTool::DialogTool(const VContainer *data, QWidget *parent) 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); timerFormula = new QTimer(this); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 1231dd919..88ba9f998 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -40,6 +40,7 @@ #include #include "../../container/vcontainer.h" #include "../../widgets/vapplication.h" +#include "../../tools/vabstracttool.h" namespace ComboMode { @@ -69,6 +70,8 @@ public: */ DialogTool(const VContainer *data, QWidget *parent = nullptr); virtual ~DialogTool() {} + inline VAbstractTool* GetAssociatedTool() { return this->associatedTool;} + inline void SetAssociatedTool(VAbstractTool* tool) { this->associatedTool=tool;} signals: /** * @brief DialogClosed signal dialog closed @@ -475,6 +478,7 @@ protected: Q_CHECK_PTR(bApply); connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); } + VAbstractTool* associatedTool; private: /** * @brief FillList fill combobox list diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 22a4961de..75fc96107 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -268,7 +268,10 @@ void MainWindow::ClosedDialog(int result) Q_CHECK_PTR(dialogTool); if (result == QDialog::Accepted) { - DrawTool::Create(dialogTool, currentScene, doc, pattern); + if (dialogTool->GetAssociatedTool() == nullptr) + { + DrawTool::Create(dialogTool, currentScene, doc, pattern); + } } ArrowTool(); } @@ -280,10 +283,14 @@ void MainWindow::ApplyDialog() Q_CHECK_PTR(dialogTool); // TODO ISSUE 79 : Only create on first apply for now, - // for updating : VDataTool * stored in DialogTool ? - DrawTool::Create(dialogTool, currentScene, doc, pattern); + // need function for updating in dialogtools or drawtool - ArrowTool(); + if (dialogTool->GetAssociatedTool() == nullptr) + { + dialogTool->SetAssociatedTool( + dynamic_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + } + //ArrowTool(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 14f1b2a0e..34bf39956 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -65,7 +65,7 @@ void VToolEndLine::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, +VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { Q_CHECK_PTR(dialog); @@ -76,12 +76,12 @@ void VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatter QString formula = dialogTool->getFormula(); qreal angle = dialogTool->getAngle(); quint32 basePointId = dialogTool->getBasePointId(); - Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, + return Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); } //--------------------------------------------------------------------------------------------------------------------- -void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, +VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, const 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) @@ -120,8 +120,10 @@ 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; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index acf0bcf20..ecda77ed0 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, const 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); From 5cb0a5cf96836aab913e65d8ad21107970b7e683 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 26 May 2014 13:48:42 +0200 Subject: [PATCH 18/42] Multi lines for formula and apply button are now working for DialogEndLine --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogtool.cpp | 7 ++-- src/app/dialogs/tools/dialogtool.h | 19 ++++++++-- src/app/mainwindow.cpp | 44 +++++++++++++++++++----- src/app/mainwindow.h | 8 ++++- src/app/tools/drawTools/vdrawtool.cpp | 6 ++++ src/app/tools/drawTools/vdrawtool.h | 4 +++ src/app/tools/drawTools/vtoolendline.cpp | 10 ++++-- 7 files changed, 81 insertions(+), 17 deletions(-) diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 40cf59383..718475811 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -41,8 +41,8 @@ //--------------------------------------------------------------------------------------------------------------------- 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), plainTextEditFormula(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()), associatedTool(nullptr) @@ -520,6 +520,9 @@ void DialogTool::CheckState() { Q_CHECK_PTR(bOk); bOk->setEnabled(flagFormula && flagName); + Q_CHECK_PTR(bApply); + bApply->setEnabled(flagFormula && flagName); + } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 88ba9f998..8a3c1f23e 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -70,8 +70,14 @@ public: */ DialogTool(const VContainer *data, QWidget *parent = nullptr); virtual ~DialogTool() {} - inline VAbstractTool* GetAssociatedTool() { return this->associatedTool;} - inline void SetAssociatedTool(VAbstractTool* tool) { this->associatedTool=tool;} + inline VAbstractTool* GetAssociatedTool() + { + return this->associatedTool; + } + inline void SetAssociatedTool(VAbstractTool* tool) + { + this->associatedTool=tool; + } signals: /** * @brief DialogClosed signal dialog closed @@ -219,6 +225,10 @@ protected: * @brief bOk button ok */ QPushButton *bOk; + /** + * @brief bApply button apply + */ + QPushButton *bApply; /** * @brief spinBoxAngle spinbox for angle */ @@ -474,10 +484,13 @@ protected: Q_CHECK_PTR(bCancel); connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); // TODO issue #79 - QPushButton *bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + bApply = ui->buttonBox->button(QDialogButtonBox::Apply); Q_CHECK_PTR(bApply); connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); } + /** + * @brief associatedTool vdrawtool associated with opened dialog. + */ VAbstractTool* associatedTool; private: /** diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 75fc96107..7f6511ee9 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -264,14 +264,38 @@ void MainWindow::SetToolButton2(bool checked, Valentina::Tools t, const QString //--------------------------------------------------------------------------------------------------------------------- template void MainWindow::ClosedDialog(int result) -{ +{// TODO ISSUE 79 : delete Q_CHECK_PTR(dialogTool); if (result == QDialog::Accepted) { + DrawTool::Create(dialogTool, currentScene, doc, pattern); + } + ArrowTool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void MainWindow::ClosedDialog2(int result) +{ // TODO ISSUE 79 : rename + Q_CHECK_PTR(dialogTool); + if (result == QDialog::Accepted) + { + // Only create tool if not already created with apply if (dialogTool->GetAssociatedTool() == nullptr) { - DrawTool::Create(dialogTool, currentScene, doc, pattern); + 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(); } @@ -282,20 +306,22 @@ void MainWindow::ApplyDialog() {// TODO ISSUE 79 : copy Q_CHECK_PTR(dialogTool); - // TODO ISSUE 79 : Only create on first apply for now, - // need function for updating in dialogtools or drawtool - + // Only create tool if not already created with apply if (dialogTool->GetAssociatedTool() == nullptr) { dialogTool->SetAssociatedTool( - dynamic_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + static_cast (DrawTool::Create(dialogTool, currentScene, doc, pattern))); + } + else + { // Or update associated tool with data + VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + vtool->FullUpdateFromGuiApply(); } - //ArrowTool(); } //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolEndLine(bool checked) -{ +{// TODO ISSUE 79 : copy // SetToolButton(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), // &MainWindow::ClosedDialogEndLine); SetToolButton2(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), @@ -311,7 +337,7 @@ void MainWindow::ApplyDialogEndLine() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogEndLine(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index c0c70d47a..e31923daf 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -534,11 +534,17 @@ private: */ void MinimumScrollBar(); template - /** + /** // TODO ISSUE 79 : delete * @brief ClosedDialog handle close dialog * @param result result working dialog. */ void ClosedDialog(int result); + template + /** // TODO ISSUE 79 : rename + * @brief ClosedDialog handle close dialog + * @param result result working dialog. + */ + void ClosedDialog2(int result); /** // TODO ISSUE 79 : copy * @brief ApplyDialog handle apply in dialog */ diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 9b654a862..4a331c016 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -107,6 +107,12 @@ void VDrawTool::FullUpdateFromGuiApply() } } +//--------------------------------------------------------------------------------------------------------------------- +void VDrawTool::DialogLinkDestroy() +{ + this->dialog=nullptr; +} + //--------------------------------------------------------------------------------------------------------------------- void VDrawTool::SetFactor(qreal factor) { diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index b00a23c13..e77e6a099 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -55,6 +55,10 @@ public: * @brief setDialog set dialog when user want change tool option. */ virtual void setDialog() {} + /** + * @brief DialogLinkDestroy removes dialog pointer + */ + virtual void DialogLinkDestroy(); /** * @brief ignoreContextMenu set ignore contect menu tool. * @param enable true - ignore. diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 34bf39956..69e0e636b 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -76,8 +76,14 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene QString formula = dialogTool->getFormula(); qreal angle = dialogTool->getAngle(); quint32 basePointId = dialogTool->getBasePointId(); - return Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, - Valentina::FromGui); + + VToolEndLine *point; + 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; } //--------------------------------------------------------------------------------------------------------------------- From 2afc195a87a897fb0a9bf0e2d83c17392d077c83 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 26 May 2014 14:20:14 +0200 Subject: [PATCH 19/42] Backout changeset 38e907833133b065c72ba362fed040f608d4b66d --HG-- branch : XML Editor --- src/app/dialogs/tools/dialogendline.cpp | 36 +----- src/app/dialogs/tools/dialogendline.h | 12 -- src/app/dialogs/tools/dialogendline.ui | 73 ++--------- src/app/dialogs/tools/dialogtool.cpp | 117 ++---------------- src/app/dialogs/tools/dialogtool.h | 6 - src/app/share/resources/icon.qrc | 2 - .../share/resources/icon/16x16/go-down.png | Bin 756 -> 0 bytes .../share/resources/icon/16x16/go-next.png | Bin 829 -> 0 bytes 8 files changed, 28 insertions(+), 218 deletions(-) delete mode 100644 src/app/share/resources/icon/16x16/go-down.png delete mode 100644 src/app/share/resources/icon/16x16/go-next.png diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index cdc6aad14..b9b1b4279 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -39,13 +39,10 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - plainTextEditFormula = ui->plainTextEditFormula; + lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - // TODO : auto extend height on first value length. - this->formulaBaseHeight=ui->plainTextEditFormula->height(); - InitOkCansel(ui); flagFormula = false; flagName = false; @@ -60,29 +57,7 @@ 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->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged); - connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogEndLine::FormulaTextChanged() -{ - // TODO issue #79 : back to FormulaChanged when full update - // Also remove this function if only one function called here - this->FormulaChanged2(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogEndLine::DeployFormulaTextEdit() -{ - if (ui->plainTextEditFormula->height() < 64) - { - ui->plainTextEditFormula->setFixedHeight(64); - } - else - { - ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); - } + connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogEndLine::FormulaChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -115,10 +90,7 @@ void DialogEndLine::setTypeLine(const QString &value) void DialogEndLine::setFormula(const QString &value) { formula = value; - ui->plainTextEditFormula->setPlainText(value); - //QTextCursor cursor = ui->plainTextEditFormula->textCursor(); - //cursor.insertText(value); - //ui->plainTextEditFormula->setCursor(cursor); + ui->lineEditFormula->setText(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -139,7 +111,7 @@ void DialogEndLine::DialogAccepted() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->plainTextEditFormula->toPlainText(); + formula = ui->lineEditFormula->text(); 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 9765d6cbb..7dfc82b03 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -112,14 +112,6 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); - /** - * @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) /** @@ -146,10 +138,6 @@ private: * @brief basePointId id base point of line */ quint32 basePointId; - /** - * @brief formulaBaseHeight base height defined by dialogui - */ - int formulaBaseHeight; }; inline QString DialogEndLine::getPointName() const diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 797078a5a..1d6c59866 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -6,8 +6,8 @@ 0 0 - 486 - 522 + 539 + 559 @@ -74,17 +74,17 @@ - - - Qt::Horizontal + + + + 0 + 0 + - - - 40 - 20 - + + Formula for calculation of length of line - + @@ -147,56 +147,6 @@ - - - - - - - 16777215 - 24 - - - - - 4 - 0 - - - - - - - - - 16 - 16 - - - - <html><head/><body><p>Show full calculation in message box</p></body></html> - - - - - - - :/icon/16x16/go-down.png - :/icon/16x16/go-next.png:/icon/16x16/go-down.png - - - - 16 - 16 - - - - true - - - - - @@ -600,6 +550,7 @@ + lineEditFormula comboBoxBasePoint lineEditNamePoint doubleSpinBoxAngle diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index ada3d1e16..c10df30c0 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -33,15 +33,10 @@ #include -// TODO : for issue #79 -// replace lineEditFormula -> plainTextEditFormula -// delete lineEditFormala everywhrer -// delete PutValHere and eval overloaded functions - //--------------------------------------------------------------------------------------------------------------------- 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), plainTextEditFormula(nullptr), listWidget(nullptr), + bOk(nullptr), spinBoxAngle(nullptr), lineEditFormula(nullptr), listWidget(nullptr), labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), @@ -288,42 +283,22 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const quint32 &value) const } } +//--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) -{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit +{ Q_CHECK_PTR(lineEdit); Q_CHECK_PTR(listWidget); QListWidgetItem *item = listWidget->currentItem(); Q_CHECK_PTR(item); - 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) -{ - Q_CHECK_PTR(plainTextEdit); - Q_CHECK_PTR(listWidget); - QListWidgetItem *item = listWidget->currentItem(); - Q_CHECK_PTR(item); - - 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()); - */ } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) -{// TODO issue #79 : erase this function after all tools updated to plainTextEdit +{ Q_CHECK_PTR(edit); Q_CHECK_PTR(timer); Q_CHECK_PTR(labelEditFormula); @@ -338,26 +313,10 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) } timer->start(1000); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *timer) -{ - Q_CHECK_PTR(edit); - Q_CHECK_PTR(timer); - Q_CHECK_PTR(labelEditFormula); - if (edit->toPlainText().isEmpty()) - { - flag = false; - CheckState(); - QPalette palette = labelEditFormula->palette(); - palette.setColor(labelEditFormula->foregroundRole(), Qt::red); - labelEditFormula->setPalette(palette); - return; - } - timer->start(1000); -} +//--------------------------------------------------------------------------------------------------------------------- void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) -{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit +{ Q_CHECK_PTR(edit); Q_CHECK_PTR(timer); Q_CHECK_PTR(label); @@ -391,45 +350,6 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) labelEditFormula->setPalette(palette); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label) -{ - Q_CHECK_PTR(edit); - Q_CHECK_PTR(timer); - Q_CHECK_PTR(label); - Q_CHECK_PTR(labelEditFormula); - QPalette palette = labelEditFormula->palette(); - if (edit->toPlainText().isEmpty()) - { - flag = false; - palette.setColor(labelEditFormula->foregroundRole(), Qt::red); - } - else - { - Calculator cal(data); - QString errorMsg; - // Replace line return with spaces for calc - QString formula = edit->toPlainText(); - formula.replace("\n"," "); - qreal result = cal.eval(formula, &errorMsg); - if (errorMsg.isEmpty() == false) - { - label->setText(tr("Error")); - flag = false; - palette.setColor(labelEditFormula->foregroundRole(), Qt::red); - } - else - { - label->setText(QString().setNum(result)); - flag = true; - palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); - } - } - CheckState(); - timer->stop(); - labelEditFormula->setPalette(palette); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogTool::setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value, const quint32 &id) const { @@ -569,17 +489,8 @@ void DialogTool::DialogRejected() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::FormulaChanged() -{ // TODO issue #79 : erase after full update of tools. - QLineEdit* edit = qobject_cast(sender()); - if (edit) - { - ValFormulaChanged(flagFormula, edit, timerFormula); - } -} -//--------------------------------------------------------------------------------------------------------------------- -void DialogTool::FormulaChanged2() { - QPlainTextEdit* edit = qobject_cast(sender()); + QLineEdit* edit = qobject_cast(sender()); if (edit) { ValFormulaChanged(flagFormula, edit, timerFormula); @@ -645,9 +556,9 @@ void DialogTool::ArrowRightDown() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::EvalFormula() { - Q_CHECK_PTR(plainTextEditFormula); + Q_CHECK_PTR(lineEditFormula); Q_CHECK_PTR(labelResultCalculation); - Eval(plainTextEditFormula, flagFormula, timerFormula, labelResultCalculation); + Eval(lineEditFormula, flagFormula, timerFormula, labelResultCalculation); } //--------------------------------------------------------------------------------------------------------------------- @@ -704,23 +615,19 @@ void DialogTool::Increments() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutHere() { - PutValHere(plainTextEditFormula, listWidget); + PutValHere(lineEditFormula, listWidget); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutVal(QListWidgetItem *item) { - Q_CHECK_PTR(plainTextEditFormula); + Q_CHECK_PTR(lineEditFormula); Q_CHECK_PTR(item); - QTextCursor cursor = plainTextEditFormula->textCursor(); - cursor.insertText(item->text()); - plainTextEditFormula->setTextCursor(cursor); - /*int pos = plainTextEditFormula->cursorPosition(); + int pos = lineEditFormula->cursorPosition(); lineEditFormula->setText(lineEditFormula->text().insert(lineEditFormula->cursorPosition(), item->text())); lineEditFormula->setFocus(); lineEditFormula->setCursorPosition(pos + item->text().size()); - */ } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index dc8eed65b..6def423d3 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -37,7 +37,6 @@ #include #include #include -#include #include "../../container/vcontainer.h" #include "../../widgets/vapplication.h" @@ -103,7 +102,6 @@ public slots: * @brief formula check formula */ void FormulaChanged(); - void FormulaChanged2(); /** * @brief ArrowUp set angle value 90 degree */ @@ -216,7 +214,6 @@ protected: * @brief lineEditFormula linEdit for formula */ QLineEdit *lineEditFormula; - QPlainTextEdit *plainTextEditFormula; /** * @brief listWidget listWidget with variables */ @@ -344,7 +341,6 @@ protected: * @param listWidget listWidget */ void PutValHere(QLineEdit *lineEdit, QListWidget *listWidget); - void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget); /** * @brief ValFormulaChanged handle change formula * @param flag flag state of formula @@ -352,7 +348,6 @@ protected: * @param timer timer of formula */ void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); - void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); /** * @brief Eval evaluate formula and show result * @param edit lineEdit of formula @@ -360,7 +355,6 @@ protected: * @param timer timer of formula * @param label label for signal error */ - void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); /** * @brief setCurrentPointId set current point id in combobox diff --git a/src/app/share/resources/icon.qrc b/src/app/share/resources/icon.qrc index 75a714bc7..64d48ee8e 100644 --- a/src/app/share/resources/icon.qrc +++ b/src/app/share/resources/icon.qrc @@ -52,7 +52,5 @@ icon/flags/uk.png icon/Graduation.png icon/individual.png - icon/16x16/go-down.png - icon/16x16/go-next.png diff --git a/src/app/share/resources/icon/16x16/go-down.png b/src/app/share/resources/icon/16x16/go-down.png deleted file mode 100644 index a74287892e3a8b6135f8c7239530e962021fdb49..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 756 zcmVL}00NXrL_t(I%gvH&NYham#-Foklnb4= za@o|3Y!y0`O(L?SME#IxQR^aQMHY#sU?r(hlTnGLWr>%p6cbXzP$@5r{Lsz3q?1Y` z`(Wgibl#_%{@*@~t(N$`=hMqM&w0-8ea`{@kxx*HxlS)A3yMz2iXpONrZuOKe3UnR z!4jRleAiq{c3i2o_q#(_qav?EwRA4`BPA5HYGqMRB21p*7cBq)_IF4}UA{n>f{jcCNl{kPcsbde3wz4*)8PR0s_`5W7>AxOr@Rn&9TiU@b6{5eP$C z9s4mdgJ1m(lG`vvY61fx^m^K%F=cWd4bN~)GYIk$ zt!4p!uB^Fx0GaWDZUFGQq0&f@aV-|XCo=F=lV7}0k`pDGoMP5G5irkZ?ITVI-0sd~ zGIyvu2ioc?s~rI#DZ6^`gEJFZ~8kU=k=Mtl+)?0000Px#AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy33hNnX8-^I5C8xG5CB}pt-}BS00v@9M??Ss00000`9r&Z00009 za7bBm000tn000tn0p4aGcmMzbQAtEWR5%f}!D&d-aU2KWZ&0s-mJ*Us1VO1U%rsXd zSSG_PgtW{uk143hQd?wRo9X6}_wr(DR?0S-W-}dgF{6cftY*h%g)bx`qx4Nez0jh5 zpY{)h>C|^U57DCP+r6|FiK3g<)nRx+&f+fDBm_h&r6*IGitZ@=HqxS8MIX87GQX!K z=d!hp(pxWCTG*6p#_7e(%Qkfp`Adu#LO!6A803~$iBZWEsQe=? zlsyE8GM|8QZ6IMk^NiBKVKX_~Cy)?lPm~h=kAYo1KiK}k1$gOZuv Date: Mon, 26 May 2014 17:33:44 +0300 Subject: [PATCH 20/42] Errors after merging. --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogendline.cpp | 1 - src/app/dialogs/tools/dialogtool.cpp | 34 +++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index edb12a430..17b95e046 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -163,7 +163,6 @@ void DialogEndLine::SaveData() formula.replace("\n"," "); angle = ui->doubleSpinBoxAngle->value(); basePointId = getCurrentObjectId(ui->comboBoxBasePoint); - emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index f0cbb096c..fa247de2c 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -415,23 +415,31 @@ void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *l } else { - Calculator cal(data); - QString errorMsg; - // Replace line return with spaces for calc - QString formula = edit->toPlainText(); - formula.replace("\n"," "); - qreal result = cal.eval(formula, &errorMsg); - if (errorMsg.isEmpty() == false) + try + { + // Replace line return with spaces for calc + QString formula = edit->toPlainText(); + formula.replace("\n"," "); + formula = qApp->FormulaFromUser(formula); + Calculator cal(data); + const qreal result = cal.EvalFormula(formula); + + label->setText(QString().setNum(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); - } - else - { - label->setText(QString().setNum(result)); - flag = true; - palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); + emit ToolTip("Parser error: "+e.GetMsg()); + qDebug() << "\nMath parser error:\n" + << "--------------------------------------\n" + << "Message: " << e.GetMsg() << "\n" + << "Expression: " << e.GetExpr() << "\n" + << "--------------------------------------"; } } CheckState(); From c4b5c3dccb7779b43db6fbe99e4a4f9b309ffc72 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Wed, 28 May 2014 21:16:41 +0200 Subject: [PATCH 21/42] Apply changes to DOM tree. No validation yet. --HG-- branch : XML Editor --- src/app/dialogs/app/dialogpatternxmledit.cpp | 169 +++++++++++++++++-- src/app/dialogs/app/dialogpatternxmledit.h | 74 ++++++++ src/app/dialogs/app/dialogpatternxmledit.ui | 10 ++ 3 files changed, 236 insertions(+), 17 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index dc1211f7a..21044fd26 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -45,22 +45,20 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) { ui->setupUi(this); - xmlmodel = new VXMLTreeView(); - - doc=xmldoc; - root = doc->documentElement(); - // disable edit trigers : - //ui->treeView_main->editTriggers(QTreeView::NoEditTriggers); + 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"); - rootNode = xmlmodel->invisibleRootItem(); + this->rootNode = this->xmlmodel->invisibleRootItem(); int drawnum=xmldoc->elementsByTagName("draw").size(); - rootBases = new VXMLTreeElement*[drawnum+1]; - rootBasesNum=1; - rootBases[0]=new VXMLTreeElement("Valentina", VXMLTreeElement::TypeRoot, root, false); + this->rootBases = new VXMLTreeElement*[drawnum+1]; + this->rootBasesNum=1; + this->rootBases[0]=new VXMLTreeElement("Valentina", VXMLTreeElement::TypeRoot, root, false); // TODO : OOM exception. @@ -68,9 +66,9 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) ui->comboBox_Base_Selection->addItem(tr("All pattern pieces"), QVariant(0)); //rootBases[0]=(QDomNode) doc->DocumentNode; - rootNode->appendRow(standard_base); + this->rootNode->appendRow(standard_base); - ReadNodes(root, standard_base, xmlmodel, false); + this->ReadNodes(this->root, standard_base, this->xmlmodel, false); ui->treeView_main->setModel(xmlmodel); @@ -95,6 +93,64 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent, VPattern *xmldoc) 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() { @@ -431,6 +487,83 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked() } 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->FullUpdateTree(); } //--------------------------------------------------------------------------------------------------------------------- @@ -586,17 +719,17 @@ void DialogPatternXmlEdit::ButtonAddSonClicked() { return; } - QString value = QInputDialog::getText(this, tr("Node Value (may be empty)"), - tr("Value:"), QLineEdit::Normal, - "", &ok); + QString value = QInputDialog::getText(this, tr("Node Value (may be empty)"),tr("Value:"), + QLineEdit::Normal,"", &ok); if (ok==false) { return; } - // create element tree but do not add attribute in DOM (will be done in apply). + // 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) { @@ -656,6 +789,8 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked() // 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); @@ -1063,7 +1198,7 @@ const short int VXMLTreeElement::TypeRoot=3; // ^ VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source, bool editor) : QStandardItem(name), DocNode(source), addedNode(editor), elementType(nodetype), treeNodeValue(""), - treeNodeValueSet(false), treeNodeName(name), selectable(true) + treeNodeValueSet(false), treeNodeName(name), selectable(true), parentnode(nullptr) { if (editor == false) { diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h index 4a8fccdc7..51e3e316f 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.h +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -74,8 +74,23 @@ public: * @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); /** @@ -86,12 +101,26 @@ public: 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) */ @@ -280,6 +309,51 @@ public: */ 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 ); diff --git a/src/app/dialogs/app/dialogpatternxmledit.ui b/src/app/dialogs/app/dialogpatternxmledit.ui index f6ce6432d..2b4c4a83a 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.ui +++ b/src/app/dialogs/app/dialogpatternxmledit.ui @@ -287,6 +287,16 @@ + + + + Immediate apply + + + false + + + From d82d6b40c028af3e393b2b063d05fb50dc2ff899 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 30 May 2014 17:55:54 +0300 Subject: [PATCH 22/42] Move QStringList outside loop. --HG-- branch : DialogTools --- src/app/xml/vpattern.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 67bd9edc1..f8ac3f864 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -206,6 +206,7 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene { Q_CHECK_PTR(sceneDraw); Q_CHECK_PTR(sceneDetail); + QStringList tags{TagDraw, TagIncrements, TagAuthor, TagDescription, TagNotes, TagMeasurements, TagVersion}; PrepareForParse(parse, sceneDraw, sceneDetail); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -215,8 +216,6 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene 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 @@ -641,6 +640,7 @@ void VPattern::ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable) 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) { @@ -649,7 +649,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 @@ -687,6 +686,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) @@ -694,7 +694,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 @@ -737,6 +736,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) @@ -753,8 +754,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 From 98c90ee5fe582f51e2a7e15f7cd4235b86169e44 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 30 May 2014 22:03:17 +0300 Subject: [PATCH 23/42] Use native QString method for replacing strings. Fix bug with InitOkCancel method. Still continue crash. --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogalongline.cpp | 2 +- src/app/dialogs/tools/dialogarc.cpp | 2 +- src/app/dialogs/tools/dialogbisector.cpp | 2 +- src/app/dialogs/tools/dialogcutarc.cpp | 2 +- src/app/dialogs/tools/dialogcutspline.cpp | 2 +- src/app/dialogs/tools/dialogcutsplinepath.cpp | 2 +- src/app/dialogs/tools/dialogendline.cpp | 2 +- src/app/dialogs/tools/dialogheight.cpp | 2 +- src/app/dialogs/tools/dialogline.cpp | 2 +- src/app/dialogs/tools/dialoglineintersect.cpp | 2 +- src/app/dialogs/tools/dialognormal.cpp | 2 +- .../tools/dialogpointofintersection.cpp | 2 +- src/app/dialogs/tools/dialogshoulderpoint.cpp | 2 +- src/app/dialogs/tools/dialogsinglepoint.cpp | 2 +- src/app/dialogs/tools/dialogspline.cpp | 2 +- src/app/dialogs/tools/dialogsplinepath.cpp | 2 +- src/app/dialogs/tools/dialogtool.cpp | 21 +++++++-- src/app/dialogs/tools/dialogtool.h | 14 ++++-- src/app/dialogs/tools/dialogtriangle.cpp | 2 +- src/app/dialogs/tools/dialoguniondetails.cpp | 2 +- src/app/tools/drawTools/vdrawtool.cpp | 6 +-- src/app/tools/drawTools/vtoolendline.cpp | 8 ++-- src/libs/qmuparser/qmuparsererror.cpp | 44 ++++--------------- src/libs/qmuparser/qmuparsererror.h | 4 -- 24 files changed, 60 insertions(+), 73 deletions(-) diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index f7d8cfad6..2d69e0f79 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -43,7 +43,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) flagFormula = false; flagName = false; - InitOkCancel(ui); + InitOkCancelApply(ui); CheckState(); FillComboBoxTypeLine(ui->comboBoxLineType); diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 7a79c6448..aacb45a5c 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -48,7 +48,7 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) timerF2 = new QTimer(this); connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); - InitOkCancel(ui); + InitOkCancelApply(ui); FillComboBoxPoints(ui->comboBoxBasePoint); diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 9308ee7bb..e24511c88 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -42,7 +42,7 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index d4a306bbc..1bdd471c2 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -45,7 +45,7 @@ DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) : labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index d21bf80d1..aa5b6ce56 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -39,7 +39,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, QWidget *parent) lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index cf1d3d5ed..bea8089c0 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -41,7 +41,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, QWidget *parent labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 37b61b49e..f0d47c3ed 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -46,7 +46,7 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) // TODO : auto extend height on first value length. this->formulaBaseHeight=ui->plainTextEditFormula->height(); - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index a07e09a11..f9b03c0a2 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -38,7 +38,7 @@ DialogHeight::DialogHeight(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogline.cpp b/src/app/dialogs/tools/dialogline.cpp index 0e7512024..7e15ab494 100644 --- a/src/app/dialogs/tools/dialogline.cpp +++ b/src/app/dialogs/tools/dialogline.cpp @@ -36,7 +36,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); - InitOkCancel(ui); + InitOkCancelApply(ui); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index a28468175..971b696ff 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -38,7 +38,7 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent { ui->setupUi(this); number = 0; - InitOkCancel(ui); + InitOkCancelApply(ui); labelEditNamePoint = ui->labelEditNamePoint; flagName = false; diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index 708b97d56..ba20c3755 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -42,7 +42,7 @@ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index a5e09ef40..34a736aa1 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -38,7 +38,7 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, QWi { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index c4a4bef38..663424ff0 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -43,7 +43,7 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; flagName = false; diff --git a/src/app/dialogs/tools/dialogsinglepoint.cpp b/src/app/dialogs/tools/dialogsinglepoint.cpp index 6e929ee23..f65840db2 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.cpp +++ b/src/app/dialogs/tools/dialogsinglepoint.cpp @@ -40,7 +40,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; - InitOkCancel(ui); + InitOkCancelApply(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogspline.cpp b/src/app/dialogs/tools/dialogspline.cpp index b76e06f3b..193a5db87 100644 --- a/src/app/dialogs/tools/dialogspline.cpp +++ b/src/app/dialogs/tools/dialogspline.cpp @@ -37,7 +37,7 @@ DialogSpline::DialogSpline(const VContainer *data, QWidget *parent) kAsm1(1), kAsm2(1), kCurve(1) { ui->setupUi(this); - InitOkCancel(ui); + InitOkCancelApply(ui); FillComboBoxPoints(ui->comboBoxP1); FillComboBoxPoints(ui->comboBoxP4); diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index 9ac242a42..6b9958646 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -37,7 +37,7 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) { ui->setupUi(this); - InitOkCancel(ui); + InitOkCancelApply(ui); bOk->setEnabled(false); FillComboBoxPoints(ui->comboBoxPoint); diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 58d57f4c2..785539bb0 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -435,11 +435,24 @@ void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *l QString formula = edit->toPlainText(); formula.replace("\n"," "); formula = qApp->FormulaFromUser(formula); - Calculator cal(data); - const qreal result = cal.EvalFormula(formula); + Calculator *cal = new Calculator(data); + const qreal result = cal->EvalFormula(formula); + delete cal; - QLocale loc = QLocale::system(); - label->setText(loc.toString(result)); + 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(""); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 050701cc8..581fa8d6e 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -475,6 +475,16 @@ protected: connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves); } template + void InitOkCancelApply(T *ui) + { + InitOkCancel(ui); + // TODO issue #79 + bApply = ui->buttonBox->button(QDialogButtonBox::Apply); + Q_CHECK_PTR(bApply); + connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); + } + //Left this method for dialog what do not need apply button + template void InitOkCancel(T *ui) { bOk = ui->buttonBox->button(QDialogButtonBox::Ok); @@ -484,10 +494,6 @@ protected: QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel); Q_CHECK_PTR(bCancel); connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); - // TODO issue #79 - bApply = ui->buttonBox->button(QDialogButtonBox::Apply); - Q_CHECK_PTR(bApply); - connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); } /** * @brief associatedTool vdrawtool associated with opened dialog. diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index 63da15c19..ea011f33e 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -38,7 +38,7 @@ DialogTriangle::DialogTriangle(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialoguniondetails.cpp b/src/app/dialogs/tools/dialoguniondetails.cpp index 7c430437f..b9e0a2566 100644 --- a/src/app/dialogs/tools/dialoguniondetails.cpp +++ b/src/app/dialogs/tools/dialoguniondetails.cpp @@ -35,7 +35,7 @@ DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) numberP(0), p1(0), p2(0) { ui->setupUi(this); - InitOkCancel(ui); + InitOkCancelApply(ui); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index e0f98abec..57a54d815 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -190,9 +190,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/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index dbc613bd4..57ecda28b 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -80,8 +80,8 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene VToolEndLine *point = nullptr; point=Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui); - if (point != nullptr) - { + if (point != nullptr) + { point->dialog=dialogTool; } return point; @@ -123,9 +123,9 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(basePointId); - return point; + return point; } - return nullptr; + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/qmuparser/qmuparsererror.cpp b/src/libs/qmuparser/qmuparsererror.cpp index e0bed1887..6d81239b3 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 0231a0e79..bcaeb015f 100644 --- a/src/libs/qmuparser/qmuparsererror.h +++ b/src/libs/qmuparser/qmuparsererror.h @@ -156,10 +156,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(); }; From cc7f2570818e50325fa5a23a7c6e100d33d85070 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 30 May 2014 22:56:05 +0300 Subject: [PATCH 24/42] New macros SCASSERT instead Q_CHECK_PTR will break into the debugger on the line of the assert. --HG-- branch : DialogTools --- src/app/container/vcontainer.cpp | 6 +- src/app/container/vcontainer.h | 2 +- src/app/dialogs/app/dialoghistory.cpp | 16 +-- .../app/dialogindividualmeasurements.cpp | 6 +- .../dialogs/app/dialogpatternproperties.cpp | 6 +- .../app/dialogstandardmeasurements.cpp | 8 +- src/app/dialogs/tools/dialogarc.cpp | 4 +- src/app/dialogs/tools/dialogdetail.cpp | 8 +- .../dialogs/tools/dialogeditwrongformula.cpp | 2 +- src/app/dialogs/tools/dialoglineintersect.cpp | 2 +- .../dialogs/tools/dialogpointofcontact.cpp | 4 +- src/app/dialogs/tools/dialogsplinepath.cpp | 4 +- src/app/dialogs/tools/dialogtool.cpp | 130 +++++++++--------- src/app/dialogs/tools/dialogtool.h | 8 +- src/app/exception/vexception.cpp | 3 +- src/app/geometry/vequidistant.cpp | 2 +- src/app/mainwindow.cpp | 12 +- src/app/options.h | 44 ++++++ src/app/tablewindow.cpp | 6 +- src/app/tools/drawTools/vdrawtool.h | 6 +- src/app/tools/drawTools/vtoolalongline.cpp | 12 +- src/app/tools/drawTools/vtoolarc.cpp | 12 +- src/app/tools/drawTools/vtoolbisector.cpp | 12 +- src/app/tools/drawTools/vtoolcutarc.cpp | 12 +- src/app/tools/drawTools/vtoolcutspline.cpp | 12 +- .../tools/drawTools/vtoolcutsplinepath.cpp | 14 +- src/app/tools/drawTools/vtoolendline.cpp | 12 +- src/app/tools/drawTools/vtoolheight.cpp | 12 +- src/app/tools/drawTools/vtoolline.cpp | 18 +-- .../tools/drawTools/vtoollineintersect.cpp | 12 +- src/app/tools/drawTools/vtoolnormal.cpp | 12 +- .../tools/drawTools/vtoolpointofcontact.cpp | 12 +- .../drawTools/vtoolpointofintersection.cpp | 12 +- .../tools/drawTools/vtoolshoulderpoint.cpp | 12 +- src/app/tools/drawTools/vtoolsinglepoint.cpp | 8 +- src/app/tools/drawTools/vtoolspline.cpp | 12 +- src/app/tools/drawTools/vtoolsplinepath.cpp | 12 +- src/app/tools/drawTools/vtooltriangle.cpp | 12 +- src/app/tools/nodeDetails/vnodearc.cpp | 2 +- src/app/tools/nodeDetails/vnodepoint.cpp | 2 +- src/app/tools/nodeDetails/vnodespline.cpp | 2 +- src/app/tools/nodeDetails/vnodesplinepath.cpp | 2 +- src/app/tools/vabstracttool.cpp | 2 +- src/app/tools/vdatatool.cpp | 2 +- src/app/tools/vtooldetail.cpp | 16 +-- src/app/tools/vtooluniondetails.cpp | 12 +- src/app/widgets/doubledelegate.cpp | 8 +- src/app/widgets/textdelegate.cpp | 8 +- src/app/widgets/vtablegraphicsview.cpp | 5 +- src/app/xml/vpattern.cpp | 36 ++--- 50 files changed, 321 insertions(+), 275 deletions(-) diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 7cf541dc1..7684cc398 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)) { @@ -543,7 +543,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 94ce7ded4..b98af16aa 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -73,7 +73,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/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index a6c452fe3..a60bbe272 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -129,7 +129,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()); @@ -164,7 +164,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(); @@ -261,7 +261,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); @@ -269,14 +269,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 ) @@ -347,7 +347,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); @@ -356,7 +356,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(); @@ -366,7 +366,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/dialogindividualmeasurements.cpp b/src/app/dialogs/app/dialogindividualmeasurements.cpp index 234bdb4b2..e90db6da9 100644 --- a/src/app/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/app/dialogs/app/dialogindividualmeasurements.cpp @@ -46,12 +46,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); } @@ -176,7 +176,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 bc0efe0e0..e047c8e0d 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/dialogstandardmeasurements.cpp b/src/app/dialogs/app/dialogstandardmeasurements.cpp index 01d2b10dd..3cce31782 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/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index aacb45a5c..873e9808e 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -193,7 +193,7 @@ void DialogArc::F2Changed() //--------------------------------------------------------------------------------------------------------------------- void DialogArc::CheckState() { - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagRadius && flagF1 && flagF2); } @@ -225,7 +225,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/dialogdetail.cpp b/src/app/dialogs/tools/dialogdetail.cpp index 8b156c4ed..d871656c0 100644 --- a/src/app/dialogs/tools/dialogdetail.cpp +++ b/src/app/dialogs/tools/dialogdetail.cpp @@ -39,10 +39,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. @@ -188,7 +188,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)); @@ -199,7 +199,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/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index d488ad260..71d20c0c3 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -85,7 +85,7 @@ void DialogEditWrongFormula::DialogRejected() //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::CheckState() { - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagFormula); } diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 971b696ff..9c24a6e35 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -176,7 +176,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/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 55237da5b..57d3dedab 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -50,10 +50,10 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *pare labelEditNamePoint = ui.labelEditNamePoint; 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); flagFormula = false; diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index 6b9958646..de42f970b 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -131,7 +131,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()); @@ -143,7 +143,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/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 785539bb0..469ed6473 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -48,7 +48,7 @@ DialogTool::DialogTool(const VContainer *data, QWidget *parent) radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), 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!!! @@ -83,7 +83,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; @@ -106,7 +106,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; @@ -144,7 +144,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; @@ -182,7 +182,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; @@ -220,7 +220,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); } @@ -291,10 +291,10 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const quint32 &value) const void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) { // TODO issue #79 : erase this function after all tools updated to plainTextEdit - 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())); @@ -306,10 +306,10 @@ void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget) { - Q_CHECK_PTR(plainTextEdit); - Q_CHECK_PTR(listWidget); + SCASSERT(plainTextEdit != nullptr); + SCASSERT(listWidget != nullptr); QListWidgetItem *item = listWidget->currentItem(); - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); QTextCursor cursor = plainTextEdit->textCursor(); cursor.insertText(item->text()); @@ -325,9 +325,9 @@ void DialogTool::PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidg //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) {// TODO issue #79 : erase this function after all tools updated to plainTextEdit - 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; @@ -342,9 +342,9 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *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->toPlainText().isEmpty()) { flag = false; @@ -359,10 +359,10 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) { // TODO issue #79 : erase this function after all tools updated to plainTextEdit - 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()) { @@ -417,10 +417,10 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) //--------------------------------------------------------------------------------------------------------------------- void DialogTool::Eval(QPlainTextEdit *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->toPlainText().isEmpty()) { @@ -478,7 +478,7 @@ void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *l //--------------------------------------------------------------------------------------------------------------------- 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); @@ -488,7 +488,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); @@ -498,7 +498,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); @@ -508,7 +508,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); @@ -517,7 +517,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) @@ -533,9 +533,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 @@ -549,7 +549,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); @@ -563,9 +563,9 @@ void DialogTool::FillList(QComboBox *box, const QMap &list) co //--------------------------------------------------------------------------------------------------------------------- void DialogTool::CheckState() { - Q_CHECK_PTR(bOk); + SCASSERT(bOk != nullptr); bOk->setEnabled(flagFormula && flagName); - Q_CHECK_PTR(bApply); + SCASSERT(bApply != nullptr); bApply->setEnabled(flagFormula && flagName); } @@ -580,7 +580,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) { @@ -637,71 +637,71 @@ void DialogTool::FormulaChanged2() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowUp() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(90); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowDown() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(270); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowLeft() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(180); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowRight() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(0); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowLeftUp() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(135); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowLeftDown() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(225); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowRightUp() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(45); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ArrowRightDown() { - Q_CHECK_PTR(spinBoxAngle); + SCASSERT(spinBoxAngle != nullptr); spinBoxAngle->setValue(315); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::EvalFormula() { - Q_CHECK_PTR(plainTextEditFormula); - Q_CHECK_PTR(labelResultCalculation); + SCASSERT(plainTextEditFormula != nullptr); + SCASSERT(labelResultCalculation != nullptr); Eval(plainTextEditFormula, flagFormula, timerFormula, labelResultCalculation); } //--------------------------------------------------------------------------------------------------------------------- void DialogTool::SizeHeight() { - Q_CHECK_PTR(listWidget); + SCASSERT(listWidget != nullptr); disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); listWidget->clear(); @@ -758,8 +758,8 @@ void DialogTool::PutHere() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::PutVal(QListWidgetItem *item) { - Q_CHECK_PTR(plainTextEditFormula); - Q_CHECK_PTR(item); + SCASSERT(plainTextEditFormula != nullptr); + SCASSERT(item != nullptr); QTextCursor cursor = plainTextEditFormula->textCursor(); cursor.insertText(item->text()); plainTextEditFormula->setTextCursor(cursor); @@ -774,14 +774,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; @@ -844,12 +844,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()) { @@ -881,7 +881,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(); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 581fa8d6e..3c1f83f33 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -432,7 +432,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); @@ -480,7 +480,7 @@ protected: InitOkCancel(ui); // TODO issue #79 bApply = ui->buttonBox->button(QDialogButtonBox::Apply); - Q_CHECK_PTR(bApply); + SCASSERT(bApply != nullptr); connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); } //Left this method for dialog what do not need apply button @@ -488,11 +488,11 @@ protected: 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 *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel); - Q_CHECK_PTR(bCancel); + SCASSERT(bCancel != nullptr); connect(bCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); } /** diff --git a/src/app/exception/vexception.cpp b/src/app/exception/vexception.cpp index 1812d7337..9b0cc4974 100644 --- a/src/app/exception/vexception.cpp +++ b/src/app/exception/vexception.cpp @@ -30,6 +30,7 @@ #include #include #include +#include "../options.h" //--------------------------------------------------------------------------------------------------------------------- VException::VException(const QString &what):QException(), what(what), moreInfo(QString()) @@ -64,7 +65,7 @@ void VException::CriticalMessageBox(const QString &situation, QWidget * parent) msgBox.setIcon(QMessageBox::Critical); QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); QGridLayout* layout = static_cast(msgBox.layout()); - Q_CHECK_PTR(layout); + SCASSERT(layout != nullptr); layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); //Disable Qt::WaitCursor for error message. #ifndef QT_NO_CURSOR diff --git a/src/app/geometry/vequidistant.cpp b/src/app/geometry/vequidistant.cpp index c80f34324..e44b05ead 100644 --- a/src/app/geometry/vequidistant.cpp +++ b/src/app/geometry/vequidistant.cpp @@ -33,7 +33,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 9cafbc319..4215af96e 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -176,7 +176,7 @@ void MainWindow::ActionNewDraw() 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); @@ -246,7 +246,7 @@ 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); } } @@ -286,7 +286,7 @@ void MainWindow::SetToolButton2(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); } } @@ -299,7 +299,7 @@ void MainWindow::SetToolButton2(bool checked, Valentina::Tools t, const QString template void MainWindow::ClosedDialog(int result) {// TODO ISSUE 79 : delete - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); if (result == QDialog::Accepted) { DrawTool::Create(dialogTool, currentScene, doc, pattern); @@ -316,7 +316,7 @@ void MainWindow::ClosedDialog(int result) template void MainWindow::ClosedDialog2(int result) { - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); if (result == QDialog::Accepted) { // Only create tool if not already created with apply @@ -346,7 +346,7 @@ void MainWindow::ClosedDialog2(int result) template void MainWindow::ApplyDialog() {// TODO ISSUE 79 : copy - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); // Only create tool if not already created with apply if (dialogTool->GetAssociatedTool() == nullptr) diff --git a/src/app/options.h b/src/app/options.h index 7bcd53bc1..590eec82d 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -33,6 +33,11 @@ #include #include #include +#include + +#ifdef Q_OS_WIN32 +#include WinBase.h +#endif /*Q_OS_WIN32*/ #define SceneSize 50000 @@ -283,4 +288,43 @@ extern const QString cm_Oprt; extern const QString mm_Oprt; extern const QString in_Oprt; +/* + * This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow + * you to continue afterwards should you choose to. + * idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148 + * Usefull links: + * 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? - + * https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func + * + * 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx + * + * 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx + * + * 4. Continue to debug after failed assertion on Linux? [C/C++] - + * https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c + */ +#ifndef QT_NO_DEBUG +#ifdef Q_OS_WIN32 +#define SCASSERT(cond) \ +{ \ + if (!(cond)) \ + { \ + qDebug("ASSERT: %s in %s (%s:%u)", \ + #cond, __FUNCSIG__, __FILE__, __LINE__); \ + void WINAPI DebugBreak(void); \ \ + } \ +} +#else +#define SCASSERT(cond) \ +{ \ + if (!(cond)) \ + { \ + qDebug("ASSERT: %s in %s (%s:%u)", \ + #cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\ + std::raise(SIGTRAP); \ + } \ +} +#endif /* Q_OS_WIN32 */ +#endif /* QT_NO_DEBUG */ + #endif // OPTIONS_H 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.h b/src/app/tools/drawTools/vdrawtool.h index a8f26f32f..d5ade197b 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -95,8 +95,8 @@ protected: */ void ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove = true) { - Q_CHECK_PTR(tool); - Q_CHECK_PTR(event); + SCASSERT(tool != nullptr); + SCASSERT(event != nullptr); if (ignoreContextMenuEvent == false) { QMenu menu; @@ -153,7 +153,7 @@ protected: */ void ShowItem(Item *item, quint32 id, Qt::GlobalColor color, bool enable) { - Q_CHECK_PTR(item); + SCASSERT(item != nullptr); if (id == item->id) { if (enable == false) diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index b6ca59ec2..a0c8da771 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); @@ -160,9 +160,9 @@ void VToolAlongLine::setDialog() //--------------------------------------------------------------------------------------------------------------------- void 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(); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 9664f2528..fadf1a9ed 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -62,9 +62,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()); @@ -75,9 +75,9 @@ void VToolArc::setDialog() //--------------------------------------------------------------------------------------------------------------------- void 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(); @@ -268,9 +268,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/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 07a136106..7aa79e7f0 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -74,9 +74,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); @@ -90,9 +90,9 @@ void VToolBisector::setDialog() void 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(); @@ -232,9 +232,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/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index 50521d867..f9e94a570 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -67,9 +67,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); @@ -80,9 +80,9 @@ void VToolCutArc::setDialog() void 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(); @@ -250,9 +250,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/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 4e74b31d6..fac3d1e96 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -67,9 +67,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); @@ -80,9 +80,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(); @@ -251,9 +251,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 e21db71cd..800ef0334 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -68,9 +68,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); @@ -80,9 +80,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(); @@ -96,7 +96,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); @@ -326,9 +326,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 57ecda28b..8bd8509b1 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -53,9 +53,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); @@ -68,9 +68,9 @@ void VToolEndLine::setDialog() 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(); @@ -194,9 +194,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/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index 88b92801e..d934d4ef3 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -51,9 +51,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); @@ -66,9 +66,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(); @@ -198,9 +198,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 49014357d..b05acb829 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -62,9 +62,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); @@ -73,9 +73,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(); @@ -87,9 +87,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) { @@ -243,9 +243,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 b73cafaf0..9e0df71a5 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -53,9 +53,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); @@ -67,9 +67,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(); @@ -217,9 +217,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 ef5b9ba9b..1a601436d 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -53,9 +53,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); @@ -68,9 +68,9 @@ void VToolNormal::setDialog() //--------------------------------------------------------------------------------------------------------------------- void 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(); @@ -218,9 +218,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/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 25d942d7c..b374baf18 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -53,9 +53,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); @@ -94,9 +94,9 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e //--------------------------------------------------------------------------------------------------------------------- void 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(); @@ -235,9 +235,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/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index 9ff688a39..64db28e83 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -51,9 +51,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); @@ -64,9 +64,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(); @@ -177,9 +177,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 354aec712..1c8d1f932 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -52,9 +52,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); @@ -96,9 +96,9 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li //--------------------------------------------------------------------------------------------------------------------- void 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(); @@ -241,9 +241,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/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 2c542cc5d..8b6b35ad1 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -57,9 +57,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()); } @@ -145,9 +145,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 0e0a5e844..5b39462cd 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -75,9 +75,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()); @@ -92,9 +92,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(); @@ -233,9 +233,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 6d18d81a0..763edef38 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 28ca05b8c..9c3aa03c0 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -52,9 +52,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); @@ -67,9 +67,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(); @@ -238,9 +238,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 b87aeb9fb..ef409f305 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 d6735f89c..6e03a5d7e 100644 --- a/src/app/tools/nodeDetails/vnodepoint.cpp +++ b/src/app/tools/nodeDetails/vnodepoint.cpp @@ -77,7 +77,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 bebdb7042..ef4765273 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 8b2fc44fd..857a9177d 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 ce800920d..5eb477f4a 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -74,7 +74,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::FullUpdateTree); diff --git a/src/app/tools/vdatatool.cpp b/src/app/tools/vdatatool.cpp index ec16d4f67..0454badb5 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/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index c5d2dfa1c..bfd8adbd9 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -99,9 +99,9 @@ VToolDetail::~VToolDetail() //--------------------------------------------------------------------------------------------------------------------- void VToolDetail::setDialog() { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogDetail *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); VDetail detail = VAbstractTool::data.GetDetail(id); dialogTool->setDetails(detail); } @@ -109,9 +109,9 @@ void VToolDetail::setDialog() //--------------------------------------------------------------------------------------------------------------------- void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogDetail *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); VDetail detail = dialogTool->getDetails(); VDetail det; for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) @@ -202,9 +202,9 @@ void VToolDetail::FullUpdateFromGui(int result) QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - Q_CHECK_PTR(dialog); + SCASSERT(dialog != nullptr); DialogDetail *dialogTool = qobject_cast(dialog); - Q_CHECK_PTR(dialogTool); + SCASSERT(dialogTool != nullptr); VDetail det = dialogTool->getDetails(); doc->SetAttribute(domElement, AttrName, det.getName()); doc->SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance())); @@ -433,9 +433,9 @@ template void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node) { QHash* tools = doc->getTools(); - Q_CHECK_PTR(tools); + SCASSERT(tools != nullptr); Tool *tool = qobject_cast(tools->value(node.getId())); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); tool->setParentItem(this); } diff --git a/src/app/tools/vtooluniondetails.cpp b/src/app/tools/vtooluniondetails.cpp index 56fbf01fd..65d0cd63e 100644 --- a/src/app/tools/vtooluniondetails.cpp +++ b/src/app/tools/vtooluniondetails.cpp @@ -312,7 +312,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) { @@ -387,9 +387,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()); ptrdiff_t indexD1 = dialogTool->getIndexD1(); @@ -492,16 +492,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/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/vtablegraphicsview.cpp b/src/app/widgets/vtablegraphicsview.cpp index 3ef25896f..54fe88337 100644 --- a/src/app/widgets/vtablegraphicsview.cpp +++ b/src/app/widgets/vtablegraphicsview.cpp @@ -31,6 +31,7 @@ #include #include #include +#include "../options.h" //--------------------------------------------------------------------------------------------------------------------- VTableGraphicsView::VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent) @@ -65,7 +66,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()); @@ -178,7 +179,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 f8ac3f864..b8c29c005 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -204,8 +204,8 @@ bool VPattern::SetNameDraw(const QString &name) //--------------------------------------------------------------------------------------------------------------------- void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail) { - Q_CHECK_PTR(sceneDraw); - Q_CHECK_PTR(sceneDetail); + SCASSERT(sceneDraw != nullptr); + SCASSERT(sceneDetail != nullptr); QStringList tags{TagDraw, TagIncrements, TagAuthor, TagDescription, TagNotes, TagMeasurements, TagVersion}; PrepareForParse(parse, sceneDraw, sceneDetail); QDomNode domNode = documentElement().firstChild(); @@ -326,7 +326,7 @@ void VPattern::setCurrentData() void VPattern::AddTool(const quint32 &id, VDataTool *tool) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tools.insert(id, tool); } @@ -334,9 +334,9 @@ void VPattern::AddTool(const quint32 &id, VDataTool *tool) void VPattern::UpdateToolData(const quint32 &id, VContainer *data) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(data); + SCASSERT(data != nullptr); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tool->VDataTool::setData(data); } @@ -345,7 +345,7 @@ void VPattern::IncrementReferens(quint32 id) const { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tool->incrementReferens(); } @@ -354,7 +354,7 @@ void VPattern::DecrementReferens(quint32 id) const { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + SCASSERT(tool != nullptr); tool->decrementReferens(); } @@ -675,8 +675,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) { @@ -723,7 +723,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 { @@ -791,7 +791,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) @@ -815,7 +815,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"); @@ -1315,7 +1315,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 { @@ -1339,7 +1339,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"); @@ -1461,7 +1461,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"); @@ -1535,7 +1535,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"); @@ -1648,8 +1648,8 @@ void VPattern::CollectId(const QDomElement &node, QVector &vector) cons void VPattern::PrepareForParse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail) { - Q_CHECK_PTR(sceneDraw); - Q_CHECK_PTR(sceneDetail); + SCASSERT(sceneDraw != nullptr); + SCASSERT(sceneDetail != nullptr); if (parse == Document::FullParse) { TestUniqueId(); From 42091c2611a6d61275240bdcd1f4b5576be1251d Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 31 May 2014 13:00:19 +0400 Subject: [PATCH 25/42] Build doesn't work, if include this headers on Windows. --HG-- branch : DialogTools --- src/app/dialogs/app/dialogaboutapp.cpp | 3 ++ src/app/exception/vexception.cpp | 1 + src/app/geometry/varc.cpp | 1 + src/app/geometry/vspline.cpp | 2 +- src/app/options.h | 26 +++++++++++++---- src/app/stable.h | 32 ++++++++++----------- src/app/tools/drawTools/vdrawtool.h | 2 +- src/app/tools/vtooldetail.cpp | 1 + src/app/widgets/vapplication.cpp | 2 +- src/app/widgets/vsimplespline.cpp | 1 + src/libs/qmuparser/qmuparserbase.cpp | 14 +++++++++ src/libs/qmuparser/qmuparserbase.h | 14 ++------- src/libs/qmuparser/qmuparserbytecode.cpp | 7 ++--- src/libs/qmuparser/qmuparsererror.h | 1 + src/libs/qmuparser/qmuparsertokenreader.cpp | 2 +- src/libs/qmuparser/stable.h | 3 -- 16 files changed, 68 insertions(+), 44 deletions(-) diff --git a/src/app/dialogs/app/dialogaboutapp.cpp b/src/app/dialogs/app/dialogaboutapp.cpp index ffad2670e..339de6ddf 100644 --- a/src/app/dialogs/app/dialogaboutapp.cpp +++ b/src/app/dialogs/app/dialogaboutapp.cpp @@ -29,6 +29,9 @@ #include "dialogaboutapp.h" #include "ui_dialogaboutapp.h" #include "../../version.h" +#include +#include +#include DialogAboutApp::DialogAboutApp(QWidget *parent) : QDialog(parent), diff --git a/src/app/exception/vexception.cpp b/src/app/exception/vexception.cpp index 9b0cc4974..7a4ed4715 100644 --- a/src/app/exception/vexception.cpp +++ b/src/app/exception/vexception.cpp @@ -31,6 +31,7 @@ #include #include #include "../options.h" +#include //--------------------------------------------------------------------------------------------------------------------- VException::VException(const QString &what):QException(), what(what), moreInfo(QString()) diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index 1f5b3710a..d5b7a679f 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -30,6 +30,7 @@ #include "vspline.h" #include "../exception/vexception.h" #include +#include class QRectF; diff --git a/src/app/geometry/vspline.cpp b/src/app/geometry/vspline.cpp index ad568b37c..355eeac60 100644 --- a/src/app/geometry/vspline.cpp +++ b/src/app/geometry/vspline.cpp @@ -27,8 +27,8 @@ *************************************************************************/ #include "vspline.h" - #include +#include //--------------------------------------------------------------------------------------------------------------------- VSpline::VSpline() diff --git a/src/app/options.h b/src/app/options.h index 590eec82d..53cdb7c61 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -36,7 +36,7 @@ #include #ifdef Q_OS_WIN32 -#include WinBase.h +#include #endif /*Q_OS_WIN32*/ #define SceneSize 50000 @@ -305,15 +305,30 @@ extern const QString in_Oprt; */ #ifndef QT_NO_DEBUG #ifdef Q_OS_WIN32 +#ifdef Q_CC_MSVC #define SCASSERT(cond) \ { \ if (!(cond)) \ { \ qDebug("ASSERT: %s in %s (%s:%u)", \ #cond, __FUNCSIG__, __FILE__, __LINE__); \ - void WINAPI DebugBreak(void); \ \ + DebugBreak(); \ } \ -} +} \ + +#else + +#define SCASSERT(cond) \ +{ \ + if (!(cond)) \ + { \ + qDebug("ASSERT: %s in %s (%s:%u)", \ + #cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\ + DebugBreak(); \ + } \ +} \ + +#endif /*Q_CC_MSVC*/ #else #define SCASSERT(cond) \ { \ @@ -321,9 +336,10 @@ extern const QString in_Oprt; { \ qDebug("ASSERT: %s in %s (%s:%u)", \ #cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\ - std::raise(SIGTRAP); \ + std::raise(SIGTRAP); \ } \ -} +} \ + #endif /* Q_OS_WIN32 */ #endif /* QT_NO_DEBUG */ diff --git a/src/app/stable.h b/src/app/stable.h index d7f9fa164..a43113eda 100644 --- a/src/app/stable.h +++ b/src/app/stable.h @@ -36,42 +36,42 @@ #if defined __cplusplus /* Add C++ includes here */ -#ifdef Q_CC_MSVC -#define _USE_MATH_DEFINES -#endif #ifdef QT_CORE_LIB -#include +# include #endif #ifdef QT_GUI_LIB -#include +# include #endif #ifdef QT_WIDGETS_LIB -#include +# include #endif #ifdef QT_XML_LIB -#include +# include #endif #ifdef QT_SVG_LIB -#include +# include #endif #ifdef QT_PRINTSUPPORT_LIB -#include +# include #endif -#ifdef QT_XMLPATTERNS_LIB -#include -#endif +//Build doesn't work, if include this headers on Windows. +#ifndef Q_OS_WIN +# ifdef QT_XMLPATTERNS_LIB +# include +# endif -#ifdef QT_NETWORK_LIB -#include -#endif +# ifdef QT_NETWORK_LIB +# include +# endif +#endif /*Q_OS_WIN*/ -#endif +#endif /*__cplusplus*/ #endif // STABLE_H diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index d5ade197b..4dbaefeaf 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -30,9 +30,9 @@ #define VDRAWTOOL_H #include "../vabstracttool.h" - #include #include +#include #include "../../dialogs/tools/dialogtool.h" /** diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index bfd8adbd9..f165a5165 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -32,6 +32,7 @@ #include #include #include +#include const QString VToolDetail::TagName = QStringLiteral("detail"); const QString VToolDetail::TagNode = QStringLiteral("node"); diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index 36a246d13..22d8561bb 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -37,8 +37,8 @@ #include #include #include - #include +#include const qreal VApplication::PrintDPI = 96.0; diff --git a/src/app/widgets/vsimplespline.cpp b/src/app/widgets/vsimplespline.cpp index 9f30b30f5..bc53d4e22 100644 --- a/src/app/widgets/vsimplespline.cpp +++ b/src/app/widgets/vsimplespline.cpp @@ -28,6 +28,7 @@ #include "vsimplespline.h" #include "../widgets/vapplication.h" +#include #include //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index 6354c8b03..cbfd20c94 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -23,6 +23,7 @@ #include "qmuparserbase.h" #include #include +#include #ifdef QMUP_USE_OPENMP #include #endif @@ -2086,4 +2087,17 @@ void QmuParserBase::Eval(qreal *results, int nBulkSize) const } #endif } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Set a function that can create variable pointer for unknown expression variables. + * @param a_pFactory A pointer to the variable factory. + * @param pUserData A user defined context pointer. + */ +// cppcheck-suppress unusedFunction +void qmu::QmuParserBase::SetVarFactory(facfun_type a_pFactory, void *pUserData) +{ + m_pTokenReader->SetVarCreator(a_pFactory, pUserData); +} + } // namespace qmu diff --git a/src/libs/qmuparser/qmuparserbase.h b/src/libs/qmuparser/qmuparserbase.h index b82954f9a..c7727426b 100644 --- a/src/libs/qmuparser/qmuparserbase.h +++ b/src/libs/qmuparser/qmuparserbase.h @@ -284,18 +284,6 @@ inline void QmuParserBase::AddValIdent(identfun_type a_pCallback) m_pTokenReader->AddValIdent(a_pCallback); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Set a function that can create variable pointer for unknown expression variables. - * @param a_pFactory A pointer to the variable factory. - * @param pUserData A user defined context pointer. - */ -// cppcheck-suppress unusedFunction -inline void QmuParserBase::SetVarFactory(facfun_type a_pFactory, void *pUserData) -{ - m_pTokenReader->SetVarCreator(a_pFactory, pUserData); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Get the default symbols used for the built in operators. @@ -306,11 +294,13 @@ inline const QStringList &QmuParserBase::GetOprtDef() return c_DefaultOprt; } +//--------------------------------------------------------------------------------------------------------------------- inline QMap QmuParserBase::GetTokens() const { return m_Tokens; } +//--------------------------------------------------------------------------------------------------------------------- inline QMap QmuParserBase::GetNumbers() const { return m_Numbers; diff --git a/src/libs/qmuparser/qmuparserbytecode.cpp b/src/libs/qmuparser/qmuparserbytecode.cpp index e4f27746e..3634612eb 100644 --- a/src/libs/qmuparser/qmuparserbytecode.cpp +++ b/src/libs/qmuparser/qmuparserbytecode.cpp @@ -22,11 +22,10 @@ #include "qmuparserbytecode.h" -#include -#include -#include -#include +#include #include +#include +#include #include "qmuparserdef.h" #include "qmuparsererror.h" diff --git a/src/libs/qmuparser/qmuparsererror.h b/src/libs/qmuparser/qmuparsererror.h index bcaeb015f..da4c40d34 100644 --- a/src/libs/qmuparser/qmuparsererror.h +++ b/src/libs/qmuparser/qmuparsererror.h @@ -26,6 +26,7 @@ #include "qmuparser_global.h" #include #include +#include #include "qmuparserdef.h" diff --git a/src/libs/qmuparser/qmuparsertokenreader.cpp b/src/libs/qmuparser/qmuparsertokenreader.cpp index baff8cf16..cd71fbff6 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.cpp +++ b/src/libs/qmuparser/qmuparsertokenreader.cpp @@ -22,8 +22,8 @@ #include "qmuparsertokenreader.h" #include "qmuparserbase.h" - #include +#include /** * @file diff --git a/src/libs/qmuparser/stable.h b/src/libs/qmuparser/stable.h index 824fb3b9d..dff1e2fd9 100644 --- a/src/libs/qmuparser/stable.h +++ b/src/libs/qmuparser/stable.h @@ -36,9 +36,6 @@ #if defined __cplusplus /* Add C++ includes here */ -#ifdef Q_CC_MSVC -#define _USE_MATH_DEFINES -#endif #ifdef QT_CORE_LIB #include From db3dca69587183ce6d7e510c3de463bb3917a485 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sat, 31 May 2014 21:27:59 +0200 Subject: [PATCH 26/42] define SCASSERT in release verion --HG-- branch : DialogTools --- src/app/options.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/options.h b/src/app/options.h index 53cdb7c61..9f734f0e6 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -341,6 +341,8 @@ extern const QString in_Oprt; } \ #endif /* Q_OS_WIN32 */ +#else // define but disable this function if debugging is not set +#define SCASSERT(cond) #endif /* QT_NO_DEBUG */ #endif // OPTIONS_H From cd76068a0fd7c519781dc7e37f06fb25c314ff44 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sat, 31 May 2014 21:43:03 +0200 Subject: [PATCH 27/42] better with qt_noop() --HG-- branch : DialogTools --- src/app/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/options.h b/src/app/options.h index 9f734f0e6..2b99ea490 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -342,7 +342,7 @@ extern const QString in_Oprt; #endif /* Q_OS_WIN32 */ #else // define but disable this function if debugging is not set -#define SCASSERT(cond) +#define SCASSERT(cond) qt_noop(); #endif /* QT_NO_DEBUG */ #endif // OPTIONS_H From 59ebe093c83961b3e56dbf6bc359eeea427309ba Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sun, 1 Jun 2014 12:00:20 +0200 Subject: [PATCH 28/42] no message --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogendline.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index f0d47c3ed..cc9d6c676 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -79,10 +79,14 @@ void DialogEndLine::DeployFormulaTextEdit() if (ui->plainTextEditFormula->height() < DIALOGENDLINE_MAX_FORMULA_HEIGHT) { ui->plainTextEditFormula->setFixedHeight(DIALOGENDLINE_MAX_FORMULA_HEIGHT); + QIcon icon(":/icon/16x16/go-next.png"); + ui->pushButtonGrowLength->setIcon(icon); } else { ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + QIcon icon(":/icon/16x16/go-down.png"); + ui->pushButtonGrowLength->setIcon(icon); } } From db96431484dd18fb429474ae9d1fed7d82d813c2 Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 1 Jun 2014 13:50:48 +0300 Subject: [PATCH 29/42] Use icon from theme. Move icons to internal theme for Windows systems. --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogendline.cpp | 8 ++++---- src/app/dialogs/tools/dialogendline.ui | 6 ++---- src/app/share/resources/icon.qrc | 2 -- .../share/resources/icon/16x16/go-next.png | Bin 829 -> 0 bytes .../win.icon.theme/16x16/actions}/go-down.png | Bin .../win.icon.theme/24x24/actions/go-down.png | Bin 0 -> 1461 bytes .../win.icon.theme/24x24/actions/go-next.png | Bin 1908 -> 1460 bytes .../24x24/actions/process-stop.png | Bin 1904 -> 1447 bytes .../win.icon.theme/32x32/actions/go-down.png | Bin 0 -> 2208 bytes src/app/share/resources/theme.qrc | 3 +++ 10 files changed, 9 insertions(+), 10 deletions(-) delete mode 100644 src/app/share/resources/icon/16x16/go-next.png rename src/app/share/resources/{icon/16x16 => icons/win.icon.theme/16x16/actions}/go-down.png (100%) create mode 100755 src/app/share/resources/icons/win.icon.theme/24x24/actions/go-down.png mode change 100644 => 100755 src/app/share/resources/icons/win.icon.theme/24x24/actions/go-next.png mode change 100644 => 100755 src/app/share/resources/icons/win.icon.theme/24x24/actions/process-stop.png create mode 100755 src/app/share/resources/icons/win.icon.theme/32x32/actions/go-down.png diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index cc9d6c676..573e1a921 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -79,14 +79,14 @@ void DialogEndLine::DeployFormulaTextEdit() if (ui->plainTextEditFormula->height() < DIALOGENDLINE_MAX_FORMULA_HEIGHT) { ui->plainTextEditFormula->setFixedHeight(DIALOGENDLINE_MAX_FORMULA_HEIGHT); - QIcon icon(":/icon/16x16/go-next.png"); - ui->pushButtonGrowLength->setIcon(icon); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next")); } else { ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); - QIcon icon(":/icon/16x16/go-down.png"); - ui->pushButtonGrowLength->setIcon(icon); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down")); } } diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 862afb117..5a287426e 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -7,7 +7,7 @@ 0 0 486 - 522 + 586 @@ -186,9 +186,7 @@ - - :/icon/16x16/go-down.png - :/icon/16x16/go-next.png:/icon/16x16/go-down.png + diff --git a/src/app/share/resources/icon.qrc b/src/app/share/resources/icon.qrc index 7fae467c5..64d48ee8e 100644 --- a/src/app/share/resources/icon.qrc +++ b/src/app/share/resources/icon.qrc @@ -52,7 +52,5 @@ icon/flags/uk.png icon/Graduation.png icon/individual.png - icon/16x16/go-down.png - icon/16x16/go-next.png diff --git a/src/app/share/resources/icon/16x16/go-next.png b/src/app/share/resources/icon/16x16/go-next.png deleted file mode 100644 index 5883d9dcaecfda05982f44d05e6a2edaf0783213..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 829 zcmV-D1H$}?P)Px#AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy33hNnX8-^I5C8xG5CB}pt-}BS00v@9M??Ss00000`9r&Z00009 za7bBm000tn000tn0p4aGcmMzbQAtEWR5%f}!D&d-aU2KWZ&0s-mJ*Us1VO1U%rsXd zSSG_PgtW{uk143hQd?wRo9X6}_wr(DR?0S-W-}dgF{6cftY*h%g)bx`qx4Nez0jh5 zpY{)h>C|^U57DCP+r6|FiK3g<)nRx+&f+fDBm_h&r6*IGitZ@=HqxS8MIX87GQX!K z=d!hp(pxWCTG*6p#_7e(%Qkfp`Adu#LO!6A803~$iBZWEsQe=? zlsyE8GM|8QZ6IMk^NiBKVKX_~Cy)?lPm~h=kAYo1KiK}k1$gOZuvAGYN~!=pW&zs{x`rg8x5|Wj;uUvRzkt&%aMMz8tZ{j(m}zd z+)8pem*nz_NqKqeV%*qw(D1Vljs82}yB8W5OX>@rnBI&>MjLu?x}!E!5kzNBD%ix3 zbtE*F7azXU5mHVH2h0mN>ZgF|wovKv7LN zbK{Q;{1%}S>K~9%b6K9VnfxRMhA%vF2jX@=o?2}n23L*rhl79Wv*nH^%>_Z6vJm(3 zm5=>^#pVhC+rw*I{p%@$*+RWAxuK1I#k0+QR5sJ2-+Vpyzx>n~00Z#tQw^e5{FKMX z*Y!vkXwqIZB&lFUFd{H}Zc8>ISR*@SEeG*% zxufk?*OEBF8NpgX%)NzRgqht4&I#=Wi|^B}hI$y0ZuHy%XoOI3sOWR3o*A-q7HG{J zBKH=X*|po5Pnrt#nxPzWD3lzEaqjnx6FF61357mNNj=ZaJP@3P#2T!*SAsQ$#9FKY zYi4R1xdBf-6#8fwD_{R}j?)N9TheNz2dojY#NbQ8`2{kUBM1$70J-a&L<~(?Mty;* zQiKuS-6TyEXCkrE1GYvQD=nP{2ql?%y3WodixXDl5gvQ+`_$3~RvfKt0cF+)?b-rg z`}k3UdM4$NKU{i_>+S@`Mx28(YByA51Sw4nN~|=h62yWthDM$-NdLyh@B;ff53$_d zkFyD?imKvl%5r-@AMAXT^}%^Y+1oVpI*GN25j0AO6)^@d8k7)ps!=yoAh8K`*PzvM zoY^_Xr5mfW=2b;Rkh?DYV((4P^d1L)0lGb~)Y8^6{lerq>;HiA*rqDpm)yZs~J)H$^a+bGyCue=EaBlNeM(zTO?L|^sr{?Mu8rU8U z356c_rJjx9u11R$5b?3%`SGwie`R=$3Qy+h)NF(0y^CBPyh?9ym9?FVtW8d`vS*3R z=G0tHsTG&|YYhA4`B3t_5qvCX6=wl1yy$uO%NC++1+VW;%kncLJ7{<7UApNKjkHTG zOSruG4!!X^EHCHO(i#y@uUzBw_9`2jJ8RXL!-AYth2MRvxB~#V@KWHRFIj@;@3G>o z(RlKSp5J(&up>!aO1riPwFR{XWVvIrxWc*qDNe7iYVX?MOgZ9vzT!^+zkjN@|G@de z3mG~UNOZrkJe@RnB5$Q1?ljv;J!=3kDMs8H^s7<7{6{t7Sg80pLEbf~^77NgzvX+s zk!j|0!q%6hw*PbX!OlnI(`lPe+LR?#2qjzPEmm(`(buoM;xA3MDS!aXZj*V-zYo9w z36KLVpb4b&qfC(bfKoi*=gBHy1PtcyUD$mU$ULFjRWb+PJ#Tcr<9zP|!~FmD`WN1X zfuPD%#TNho03v!+SaefwW^{L9a%BJjc-kv3FW1Y=%Pvk%EJ)SMFG>dhHrNJO5L3!r P00000NkvXXu0mjfkNUaj literal 0 HcmV?d00001 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 8eabaafe8a30883440ea84dafc50d295551e1b97..989e8d4359da1bab52d9f616bb0010a482049f4b GIT binary patch delta 1452 zcmV;d1ylO;4zvp)iBL{Q4GJ0x0000DNk~Le0000O0000O2nGNE0N{5$_>q4ce+v@; z01FcV0GgZ_000FhNklpJ(nQnQ_9{)>0+KOidL<2L+4N zht`THmhU%y14Npq%e*-+R+T``Kk-huO-Z0{!vd{;szAl6jQvfz)D{06pNkdMVloL1p z8dv8J7=HH7;=cpFw%o*6Qa|G0a3dZmR`tNBt5*Fj+2blma|z8kIaix9e?PS;&%{9a ztA*nBfUmyXL>w(Y(C=(t(I@)XwP_Pb8er@=TL4wi097A+1@&1eT66N0&E&^1u>JH0 zinjv}Ej6(zt{Uj~dvEA>%S}xhxnSIQKUM~UMY0l+o9Bui23v}olBzW?KeCxV8B6iM z{%{`v1MroXnnbVoA&>O0f9sLZ(y@^$y*}MfHm-;J09lH{-1Mi_7LI|i~(x} z=Y)LP;=AP4wjM^L6FoNp8X=5W9CcZ&rGj%2k(~h%fO}@{=dlAnf8i4|-=4L41#!5@00YXWpo{qENtRZuCvgGYyjYCxt z5fnv<%;oRm^9w)Zqto9)2Q91xjoJy7W*Wf7pokJx3Dycm1QCM~gZ@hes_~YW@!ds@ ztZcr@)xi>3-D5_AMhRMJM8RoLqB111ssck_aB=+{iOqI)f20UAtvhICov}N_Fs%Cg z<;rs`ZTyC^c9}XBEkPrzAu_ap(;#R?K=e#BaEWRn~fMaAxJVT+`=iP7lbm#m2D0Mi;C;q~8hq4zAiW?@%*_avvzNCWG|Hesa4e5vPS zxTVoz1w?$TININ?E?nBaN`)W0$=1nilf=|m-uN?vf9zH6oSUPaO_ACi||@a+4ng(x?I*Nell{CHt|d8gi?lg?7NIrX%~%=9$7^W9i+ z7-NWd*2)#mt}n5AZF8mSb6AiURN;?b9^C{0EI%7~&u1*b^S4;>a?u~WZ_Tg1V`K|S zl9X1~f1#1KL4=_eTrV&2O7|tsURlz$tG#n&!8d%xNr2}Ljcz}19)3DQhXRS-Z7h!` zO%68N>77%pJgH|5P#BbbwtC&F=$4nOf@ea-F9~wdq{@lMM?3BPZziSz9AN7+QoH+; z_MWM`x)|0M+ELsJ8z@;j|==^1poj50drDELIAGL9O(c603c&XQcVB=dL{q>fP?@5`Tzg`fam}Kbua(` z>RI+y?e7jT@qQ9J+u010+*L1zE}03ZMW03ZN|`kbASAsl}abN~PnbOGLGA9w%& z28c;SK~z}7?Us2^lw};pA8jn1bQ*LrsVqt*AtytUL`fPPP4NIypyXDFg}ATfl32M` z1U6O#l|$~+g=M)xSXf{YR1S9qQ9)ZoR6wr8)actIR@2ms0_uN$XTI~>_t|Hk@8@~m z=Y94iIb zFDJ+4rG#^miWEZQ3mAsZi32RN6huc`}yC(c60v0%*9 zJ*g!+ODO+B!V`;{)-xjn725U%zh_r=qy5?tn%nQ7y77MoN~*7+sHz*KHP<0J+lvdG z1L%~EfJfW6+X)7k9D(I?g=bbtRZP7ydmWB6Of+{5p^Ap43px>(CB@OyHgFSL5P7m? zvPRSE_?(N#F1~^~x-t^kD4dTr4x4#qq%!bl|A83kZ#C z1}mxw-kg61xQErl?Qk7DX!ZH|3<9E?5T4M2m`n+Hr@PU5eFWYK&BGRcxyjQ8IB@*5 zt$BF;c%^gzvHT8%o@|BBkw!Suz#jsuVeVH2W8cb2Td;(%@E5{5s0J<+#xMFTB9hyX zTyz-?S4XfvOx(eW6Dm(RJf&PZf4xoq2*0@>(fNOu;2(D$PISim0!1+Nsf4aaIka6$ zVGm@75JV4Sq0a^joXMIdVAuEucBCb7aMHz`%cweoj)Z2Yj$Cv ze`d!}T*Wo`&?WydLJZ@B)zI}ijV-RF&~zw*hJ6tZWwhaMO-%fOL+NeUO26MtAGd}eaH>;g6H@3uB>*+6+&i(gePE?Y@nd8o_R_(2cvV1)&RX5B5UMr; zs8|aSlzsvK)?;1zqnqz^=vaAQ5x|=!&qap-nfRF5P%C zx)1&faWGwiZ@jCpC#V*d+$MyU$e?Lkdc*xNU;n89CJr$oC4K&Vr?gAh$r52TovnY0 zSu(nMhcF%eP9f|$l~A?H!Jc3-ym(ikVpMq7%qd3rQ~*OpWIIua!~%_E5Tyu^_xHiX zF$Ocy;LsS}QZxrqj)I(4D#%C2@VzZp^7IvOJSrwj!$97%1zEBWM8O6NRjiR)(LAm2 z;n8uZ>#;!IH3C^|3?gqy$7I9IDO!K@Q~>wTQ|6C5l9k8lk12qnGl&WkMAa2!E&Z%U ztGXw(7sv)L$nOe4OUHGLjEqcrbaWKGxB8)G6biD+4&-A8IuTPkP81!F17=vR{xdh? zYfIcQS1k`@g%b_+2hrkyY>NTel>nkgZ_VzsNiW$Q4$--bkjZ3|?&;~lr7M5kP_^KK zd>uqhS8|Ong|Npw)m*&xjy3JzBrZ0x{-;m=}RqmV=n^ zU=YHCL?Zdejptjjnh{U?$ATDSQs6iW9}co90dkwmep{i&m>PhsUt;v@Yfs``k2a8R z6KNO?wx*%ZXF!;=&9@!IwH|-k>;j0z;z?K5)M1rd4((R};#f~1ODHf8L^lEQF0Gie zCIJrqiQ!ZJKX^}RFBHAoAm?}SNw{AJW{3A;?vXw$h`9~9m_96F^6AM}hGV>PtPK?4 z&4W#NgWCsk_y&l#WD;WG0Vx!jtyrr39muq`%om$7?_zP(ZOrD-z~p~HC}a;~dEO{i z=8s`T+AmPxit%B1HI|*cg5|j*_%Le-Zzm0ag!kc{Be$THK7d&td(9x6%8GfkhY$&}?`#Sv6`O()I`Vtn5CP@$X@yXaf3GEKq|ErO=m!sO#VmhiZ|Ly*;6e{Wvm3yUi%-1gGGIV$*a_^S*W23xQyJhs2<+tb zVwSQe?0lm$p8LHpIJR)n2cPQUedA16Ru6;oE5N0P%^~XGziK3P#2Bz&I1Kr{X@4lJ z(gAtVa`xk9e6rR6^VI$EDdQBhBbs1vT#Bt>jZm`A8J)ZCCn#opX$W^#)Cuyk70gZ1 zw(|%UTRZt)v-b!Qv7=Hql2>}A=hUAfur4}d`0IiI001I-R9JLFZ*6U5Zgct<8 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 fc2c75622c85ce88eb0d80684678f77973c65dc1..95cc6e0e15887b5fc624e7b77884f92a06aed7ed GIT binary patch delta 1371 zcmV-h1*H1$4yOwtiBL{Q4GJ0x0000DNk~Le0000O0000O2nGNE0N{5$_>mzge+3yy zL_t(Y$HkUkY*SSn$3N%ZwkxbHEnS;-Z70<-2;ediV(?#>5FhkGAmK?&V3EX-7>)ch zAu&E8s0j~BqC^vCe3B<)jPU`@%$&YRh?pp2P6q3?_O`IC>)LzIIX>LBbTFPh$uH;J z^XL2hp5OWX&bfjIl*51qJm3Yye}m>}a7<7iKVW>th3^BiU~Y=V4un#veZn+XCeT_` zOQpXH6BB2Ara5y>N`WvMt>3--Ojk4-k(PyCTtrnW=*30XDiw64e}bx1@PY_s zvzxK)?%C<-;XQ`2_-#`}JHdOvFCbn>CJ*Lz?K-`x|N$qfvA5DAB)(z0B4NaGs(+ zrsIe;*=(PoRD3$0AKqpdf7Nfb#{3BQ9mJkw^5xvXz=x4wu&Z5paN9P_&Q9txGwxO! zz@AWuHBUW-Jv)o4R?+o3rsIgvx^;af#H@UN_$9+wGWYrYWQ6F;?cV*_+Hg4GSXS!* z!_PcJ_p7fG=<8$YpMR)LPrKm3Al-)!5#PTbGZdn7_3B*`+cts^e?8Q1FDzL72M&xF zrr(c066xv;hoiDwMk|GO9K6vevAuioghKe!X;Mdy(79m)W@jhK!9l`1cOp!a$iM)h z?c33|4N4*B=kZEubjIU7{pZf%X$H7fO6!Kdwbs=0c?uUVk{ld#NirGIufI-xW`^L_ ztq8+FE5+?gmzWzFe?c_PODF}7)AGXIJZLD_jX|X~*7x6|rKJ1tVV9(*2Y*jbQxN4J zeqieSd7Rs~5kjl*Q z%R=6{L*n2;BF{gM5CSbFs#XJFb#E`Z^XCaa`6Pzcm|DB_GSK$6)-G_NK=sc*v2WcX z^~M`S_v~pMXkloGe~%x>E*4#qO`FJFxWJknJ1`nq+awT;4SBSbXva}%X^HyyIJKKM z(Mr*gOyck9e`$eRLqkj+JLdX)VS&uqvv{IWys;P^u^81hwWiO9l2QSfFDgZ?QmOlV zz9%~U{w#$8hSunX1uCPXtlF}L%J49gM~|W`3lpebxq>Vd@Ne8m{?sYvzWy4cLEuZJ znCt2)Q1jeqjVU*cWhkzkOy#l?-;&6__>z|-pLe^s=U2*B6fjaphlmP&}W2Sj+i zbYwErZ`?pQjvFzl6y;2&cztZ_t*?s3FP{T#{s=r$uagY~iqlh5quzM@v2Z+|F^WYu zROjar)oRPPEmI0rE@LRwQeIA{t?SpXAG=sA4m}I{Wb-y10W$SE>jQyeeroDhPb{`I z9FM1se_|0s>*c_02idH>sT5W^T^bu3JMoQWeepyCeA#>OE6`uBlL!O~(^FHwnX%a8 zk$61iDVH&|#x#ukO$fZH6vcG9d~Iy(Hm)Ku`wLyPSuih>#?s->t+h(K!c(wjt`Mnd7ijtS5T+t_PoZJfr;&dy%voIdPr zX2Fo=B}W>anWLHW{rsTTecf;`1w4K3HB@IN^gi8~EA(D_|H{1QFJ>pR`7!ziHpQ zw*kXINm+pwd!>|X%o7Y^m?qaQUc9(GKY!c@^Eu$9uPR^|m<7?UX@^>)f6=pTk3ZgM z$70BAwqSl0u+%HZy}z*$Q%ZI1;>8QM=jTuOU?BsXtYT@^@FCy^(5Yz$TcgplZM%0j z<%@7ufmeF~rO2Bm0bLh$9UYyic)TTH82|Kxxd-^$Y66CUkAYp9_M_Hlbf|4$pgA9l zAv2l6#6|Zj$30S3#!F+xf6GoJsMU25>gb5178kb}hH)tf$#&p!wSXbuJ>Y<*{h&1( z9cu0G-FWHF%fr5yx^y1=H!!Ry2L-IqXfMMWQz%Mjyur(ST zZtd&aoS&U_!IhNgU0n#jpZu3!-VIg?p=qq$xf7X8VkeUbrBHxve;CvTgCf+?(Vbpe z3LA!T=>S+C0@~|B5YTnLlh1#z^~on+Z|&>blBC!S#Q zkt6u(>ru8{2$hs%=I2=ho{hb|`!#42Lf`=qLf{Pqyu!ATnGC8JUuD|}ub28gd+=@8 zP)=4o5+Qv2I5pugC{=(TI)oMo6l&Y!p{}owKwDcOCrY^^e-u#z?B8F81K6n)@zGHdSFRKmn&N!InY6{` zaV-K$LD6MS*QKVWm>U|xoSbyMu6K9SI5>zF3|8QlMf|O|SU!Iq~DHh*;o8|N8A(ulGtrk)ilCjtehXAk3BuCpQdKhrs_qM<#*pD{^pygY_=fWIbSKKayjgE>sAp^3;{|NV&~lH zl)|HFta*V+Tix#6Jp9^g=#fal)x{W>F0DH0N@ZA5Ba|w~4BJMUCfS)8QlEXsx_$fDbmWLD z+w+D&dTOe&3j(3NdwKYcH&_#i+!OA>y#>3gpj4}-N#^EFtceM-v$Je`<{7rW@(SA8 zwUvZ3e@$YiPxJ4=K@uN*}Hr_pTDbL|?l$BtnZMPy?!V#kk@ymYB- zy$1OFezfh|Sy@`TtzZQ}`!mo#Geatqxt>{B*;3!#-4n>?g}ig8>@HUZiZ{2dmOA7=FYkMwNshp~qYPyb0r3#5$a4}M#K9TZI z-*&)V0s#I2M1dMG6P7iWGK{uRPfw>_l@p$?2=^A?OVbk*Kff;JA0t)py95CI1^6!D z2h+5yG3(Bq_Ru4b?9gpnu(EPjS>0=~@z&Jf9T?z0hH-mpV&deCl<#ZY-XeFZ?_XyySVY}JFo zU)R>v?Ldh8o(%<%&t~(3Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iXS- z4kjh0JfT_u00-E};Z7{)WW6Wj1atI^{2`K_( zzz_~2AjC+7T#$rM$p=WjgoH$iu%ZAF5+sUk?%RTZgM%?>g9SFm1Tf$LK9@aaXLe?~ z=jg7gmk+axcN0J{D59iNx77XK|5xwzd({PB@K6VDG7P){_&`gwU1)(p;PQiZc@S@} zQ<+SvTdlzW3JV~=Ad|`Wrm2W?wLxgS1A4dTb*I*b0%yzT1b7R07U))h2f+zH`RU0w zEIp;`g5yu)6^e^VN%lX7gNR5LPKH8NUF+q0HRIWkhI8)rpi^VTt0cEOf)aL<>t zzSnE}yz76Bz+ZtU$z;z7XZ3b2zxUyj?pu6fm)~euj1im@oC6U-CLAb*)`F)s+JnH? zOe=W&Y4yJPwJWz=mdWV#t=94s?gYN~X#g()rxAvaWsW~?#x)PETY7t;)0bw`sx%dh zaX1Igf|~@O6nGl6r|^A^?<;~(Q^;xAzP+Z-IJN((AZR?0rkAF$4LJFe00iG(7vws! z=WTxN^hY~8eTnN4femmhW84}Uc8 zq=64xDvB(%$PmSjsBYV{VX*?IoOlRKo_v z=I&lQl#9yI2AF4|9{@dG*2skzph@QvsYX z99xDW%gFe<#mG>KEn~4^EOv~=hI-4%g)8Tr2gygN_uH2b6uA76^E!?l8B0{9?ij0E zsn8w46!?es&dTU=WQkgqYEy`dssznntehfs0H#!+rr zF&hy9+lPLD!IyL1UOgc_C6$Vl=Y zx9++aW!^!~Phk_E@<(((@JEnpiY^pen}(jP_H-=BEzI}%SuJUYR(;(8i*g<_vYOtE zrZ?2|dYU;N)CI~7i)uJgiBs}Y`6+(8^V=x(Hga47%Yd(c8UVn9z;{4yFtDuTwv0a4 z+#c^p=XNZhH=H@*E1IE}&Wu*sP@_FfO@ud^PWHxDsj5L$3~g`f9m_NW3s1Cj@qZ|~`eZg)}NK+u3N25Evy;C%T%9Zmu61$tEbL=Y-y iIEV!<{_HNlsPS)VoJbLtH#dL)0000icons/win.icon.theme/24x24/actions/list-add.png icons/win.icon.theme/32x32/actions/list-remove.png icons/win.icon.theme/32x32/actions/list-add.png + icons/win.icon.theme/16x16/actions/go-down.png + icons/win.icon.theme/24x24/actions/go-down.png + icons/win.icon.theme/32x32/actions/go-down.png From 404505ecf32722050af4391aa688d3acce1d8c3b Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 5 Jun 2014 09:48:40 +0300 Subject: [PATCH 30/42] Error when compile on Windows. --HG-- branch : develop --- src/app/version.h | 2 ++ 1 file changed, 2 insertions(+) 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; From dab44eb163b78418072c6e8a2058ef7cff93d287 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sun, 8 Jun 2014 11:14:16 +0200 Subject: [PATCH 31/42] DialogAlongLine Tool change --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogalongline.cpp | 57 +++++++++++++++++--- src/app/dialogs/tools/dialogalongline.h | 21 +++++++- src/app/dialogs/tools/dialogalongline.ui | 61 +++++++++++++++++++--- src/app/dialogs/tools/dialogendline.ui | 7 ++- src/app/mainwindow.cpp | 15 ++++-- src/app/mainwindow.h | 1 + src/app/tools/drawTools/vtoolalongline.cpp | 14 +++-- src/app/tools/drawTools/vtoolalongline.h | 4 +- 8 files changed, 157 insertions(+), 23 deletions(-) diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 2d69e0f79..d5e87e17e 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -38,9 +38,11 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + flagFormula = false; flagName = false; InitOkCancelApply(ui); @@ -55,11 +57,37 @@ 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); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::FormulaTextChanged() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +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")); + } + else + { + ui->plainTextEditFormula->setFixedHeight(this->formulaBaseHeight); + //Set icon from theme (internal for Windows system) + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down")); + } +} + //--------------------------------------------------------------------------------------------------------------------- DialogAlongLine::~DialogAlongLine() { @@ -93,15 +121,27 @@ void DialogAlongLine::ChoosedObject(quint32 id, const Valentina::Scenes &type) } } -//--------------------------------------------------------------------------------------------------------------------- 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); } //--------------------------------------------------------------------------------------------------------------------- @@ -120,7 +160,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 69ef285f8..f485a5c9a 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; @@ -113,12 +114,24 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); - /** TODO ISSUE 79 : create real function + /** * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(){} + 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) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -147,6 +160,10 @@ private: * @brief secondPointId id second point of line */ quint32 secondPointId; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogAlongLine::getPointName() const diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index 9113f9e04..c935b0f11 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,50 @@ + + + + + + + 16777215 + 24 + + + + + + + + + 16 + 16 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -390,14 +440,13 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - lineEditFormula toolButtonEqual lineEditNamePoint comboBoxFirstPoint diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 5a287426e..12be8bf7a 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -169,6 +169,9 @@ 0 + + QPlainTextEdit::NoWrap + @@ -186,7 +189,8 @@ - + + :/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 @@ -673,6 +677,7 @@ + diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 4215af96e..86f0b0e4d 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -421,8 +421,17 @@ void MainWindow::ClosedDialogLine(int result) */ void MainWindow::ToolAlongLine(bool checked) { - SetToolButton(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", - tr("Select point"), &MainWindow::ClosedDialogAlongLine); + SetToolButton2(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(); } //--------------------------------------------------------------------------------------------------------------------- @@ -432,7 +441,7 @@ void MainWindow::ToolAlongLine(bool checked) */ void MainWindow::ClosedDialogAlongLine(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index eac2e1886..c5bd288b3 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -106,6 +106,7 @@ public slots: void ApplyDialogEndLine(); void ClosedDialogLine(int result); void ClosedDialogAlongLine(int result); + void ApplyDialogAlongLine(); void ClosedDialogShoulderPoint(int result); void ClosedDialogNormal(int result); void ClosedDialogBisector(int result); diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index a0c8da771..19f1f703e 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -158,7 +158,7 @@ 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) { SCASSERT(dialog != nullptr); DialogAlongLine *dialogTool = qobject_cast(dialog); @@ -168,12 +168,18 @@ void VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatt 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); From 52761f04ceeb57b64305740e0270db6bc10eb5de Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sun, 8 Jun 2014 15:46:04 +0200 Subject: [PATCH 32/42] Changed Icon path --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogalongline.cpp | 9 +++++++-- src/app/dialogs/tools/dialogalongline.ui | 16 +++++++++++----- src/app/dialogs/tools/dialogendline.cpp | 11 ++++++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index d5e87e17e..90412de76 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -61,6 +61,9 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) 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"))); } //--------------------------------------------------------------------------------------------------------------------- @@ -78,13 +81,15 @@ void DialogAlongLine::DeployFormulaTextEdit() { ui->plainTextEditFormula->setFixedHeight(DIALOGALONLINE_MAX_FORMULA_HEIGHT); //Set icon from theme (internal for Windows system) - ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next")); + 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")); + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); } } diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index c935b0f11..5bf4d8691 100644 --- a/src/app/dialogs/tools/dialogalongline.ui +++ b/src/app/dialogs/tools/dialogalongline.ui @@ -172,8 +172,14 @@ - 16 - 16 + 18 + 18 + + + + + 0 + 0 @@ -183,9 +189,8 @@ - - - + + :/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 @@ -463,6 +468,7 @@ + diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 573e1a921..580db8ebe 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -62,7 +62,10 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit); - //ui-> + + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); + } //--------------------------------------------------------------------------------------------------------------------- @@ -80,13 +83,15 @@ void DialogEndLine::DeployFormulaTextEdit() { ui->plainTextEditFormula->setFixedHeight(DIALOGENDLINE_MAX_FORMULA_HEIGHT); //Set icon from theme (internal for Windows system) - ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-next")); + 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")); + ui->pushButtonGrowLength->setIcon(QIcon::fromTheme("go-down", + QIcon(":/icons/win.icon.theme/icons/win.icon.theme/16x16/actions/go-down.png"))); } } From 094f29492da9fa048e7b5482cfafae2d87c05466 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sun, 8 Jun 2014 19:56:09 +0200 Subject: [PATCH 33/42] DialogBisector Change --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogbisector.cpp | 62 ++++++++++++++++++-- src/app/dialogs/tools/dialogbisector.h | 21 ++++++- src/app/dialogs/tools/dialogbisector.ui | 69 +++++++++++++++++++---- src/app/mainwindow.cpp | 16 +++++- src/app/mainwindow.h | 1 + src/app/tools/drawTools/vtoolbisector.cpp | 14 ++++- src/app/tools/drawTools/vtoolbisector.h | 4 +- 7 files changed, 161 insertions(+), 26 deletions(-) diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index e24511c88..774bba5ea 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -39,9 +39,12 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + InitOkCancelApply(ui); flagFormula = false; flagName = false; @@ -57,7 +60,38 @@ 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() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +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"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -129,7 +163,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); } //--------------------------------------------------------------------------------------------------------------------- @@ -152,12 +191,25 @@ void DialogBisector::setThirdPointId(const quint32 &value, const quint32 &id) //--------------------------------------------------------------------------------------------------------------------- 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 948140d98..f1ca2ae3b 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; @@ -124,12 +125,24 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); - /** TODO ISSUE 79 : create real function + /** * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(){} + 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) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -162,6 +175,10 @@ private: * @brief thirdPointId id of third point */ quint32 thirdPointId; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogBisector::getTypeLine() const 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/mainwindow.cpp b/src/app/mainwindow.cpp index 86f0b0e4d..21c50ea62 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -493,8 +493,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); + SetToolButton2(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(); } //--------------------------------------------------------------------------------------------------------------------- @@ -504,7 +514,7 @@ void MainWindow::ToolBisector(bool checked) */ void MainWindow::ClosedDialogBisector(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index c5bd288b3..8623e07f9 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -110,6 +110,7 @@ public slots: void ClosedDialogShoulderPoint(int result); void ClosedDialogNormal(int result); void ClosedDialogBisector(int result); + void ApplyDialogBisector(); void ClosedDialogLineIntersect(int result); void ClosedDialogSpline(int result); void ClosedDialogArc(int result); diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 7aa79e7f0..f4b5b371b 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -87,7 +87,7 @@ void VToolBisector::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, +VToolBisector* VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); @@ -99,12 +99,18 @@ void VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatte 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, @@ -145,7 +151,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; } //--------------------------------------------------------------------------------------------------------------------- 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, From 0b4f1a21ede910d834c70ef59eae8e823103b8f9 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Sun, 8 Jun 2014 22:28:09 +0200 Subject: [PATCH 34/42] DialogNormal change --HG-- branch : DialogTools --- src/app/dialogs/tools/dialognormal.cpp | 59 ++++++++++++++++++-- src/app/dialogs/tools/dialognormal.h | 21 +++++++- src/app/dialogs/tools/dialognormal.ui | 71 +++++++++++++++++++++---- src/app/mainwindow.cpp | 16 ++++-- src/app/mainwindow.h | 1 + src/app/tools/drawTools/vtoolnormal.cpp | 14 +++-- src/app/tools/drawTools/vtoolnormal.h | 4 +- 7 files changed, 160 insertions(+), 26 deletions(-) diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index ba20c3755..056bfaf26 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -39,11 +39,13 @@ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + flagFormula = false; flagName = false; CheckState(); @@ -58,7 +60,36 @@ 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() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +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")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -96,14 +127,27 @@ void DialogNormal::ChoosedObject(quint32 id, const Valentina::Scenes &type) //--------------------------------------------------------------------------------------------------------------------- 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); } //--------------------------------------------------------------------------------------------------------------------- @@ -129,7 +173,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 ad8147cc9..3e16e9884 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; @@ -123,12 +124,24 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); - /** TODO ISSUE 79 : create real function + /** * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(){} + 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) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -161,6 +174,10 @@ private: * @brief secondPointId id second point of line */ quint32 secondPointId; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogNormal::getPointName() const 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/mainwindow.cpp b/src/app/mainwindow.cpp index 21c50ea62..dd4d4c4f7 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -472,8 +472,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); + SetToolButton2(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogNormal, + &MainWindow::ApplyDialogNormal); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogNormal actions after apply in ApplyDialogNormal. + */ +void MainWindow::ApplyDialogNormal() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -483,7 +493,7 @@ void MainWindow::ToolNormal(bool checked) */ void MainWindow::ClosedDialogNormal(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 8623e07f9..37e4be09d 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -109,6 +109,7 @@ public slots: void ApplyDialogAlongLine(); void ClosedDialogShoulderPoint(int result); void ClosedDialogNormal(int result); + void ApplyDialogNormal(); void ClosedDialogBisector(int result); void ApplyDialogBisector(); void ClosedDialogLineIntersect(int result); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 1a601436d..453b212b2 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -66,7 +66,7 @@ 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) { SCASSERT(dialog != nullptr); DialogNormal *dialogTool = qobject_cast(dialog); @@ -77,12 +77,18 @@ void VToolNormal::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern 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, @@ -121,7 +127,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; } //--------------------------------------------------------------------------------------------------------------------- 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, From a167cda90c14a85feb22b815ff26f4de9c43f5b3 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 9 Jun 2014 12:56:07 +0200 Subject: [PATCH 35/42] DialogShoulderPoinr change --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogshoulderpoint.cpp | 61 ++++++++++++++-- src/app/dialogs/tools/dialogshoulderpoint.h | 21 +++++- src/app/dialogs/tools/dialogshoulderpoint.ui | 71 ++++++++++++++++--- src/app/mainwindow.cpp | 16 ++++- src/app/mainwindow.h | 1 + .../tools/drawTools/vtoolshoulderpoint.cpp | 14 +++- src/app/tools/drawTools/vtoolshoulderpoint.h | 4 +- 7 files changed, 162 insertions(+), 26 deletions(-) diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 663424ff0..fe9af1bc7 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -40,11 +40,13 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent number = 0; InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); + this->formulaBaseHeight=ui->plainTextEditFormula->height(); + flagFormula = false; flagName = false; CheckState(); @@ -58,7 +60,38 @@ 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() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +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"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -114,14 +147,27 @@ void DialogShoulderPoint::ChoosedObject(quint32 id, const Valentina::Scenes &typ //--------------------------------------------------------------------------------------------------------------------- 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); } //--------------------------------------------------------------------------------------------------------------------- @@ -146,7 +192,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 933c4f96b..2b88ab209 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; @@ -124,12 +125,24 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); - /** TODO ISSUE 79 : create real function + /** * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(){} + 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) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -162,6 +175,10 @@ private: * @brief pShoulder id shoulder point */ quint32 pShoulder; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogShoulderPoint::getPointName() const 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/mainwindow.cpp b/src/app/mainwindow.cpp index dd4d4c4f7..48c45b976 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -451,8 +451,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); + SetToolButton2(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint, + &MainWindow::ApplyDialogShoulderPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ApplyDialogShoulderPoint actions after apply in DialogEndLine. + */ +void MainWindow::ApplyDialogShoulderPoint() +{ + ApplyDialog(); } //--------------------------------------------------------------------------------------------------------------------- @@ -462,7 +472,7 @@ void MainWindow::ToolShoulderPoint(bool checked) */ void MainWindow::ClosedDialogShoulderPoint(int result) { - ClosedDialog(result); + ClosedDialog2(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 37e4be09d..a1eef0b61 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -108,6 +108,7 @@ public slots: void ClosedDialogAlongLine(int result); void ApplyDialogAlongLine(); void ClosedDialogShoulderPoint(int result); + void ApplyDialogShoulderPoint(); void ClosedDialogNormal(int result); void ApplyDialogNormal(); void ClosedDialogBisector(int result); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 1c8d1f932..b92d0e300 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -94,7 +94,7 @@ 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) { SCASSERT(dialog != nullptr); DialogShoulderPoint *dialogTool = qobject_cast(dialog); @@ -105,12 +105,18 @@ void VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, V 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, @@ -154,7 +160,9 @@ void VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint doc->IncrementReferens(p1Line); doc->IncrementReferens(p2Line); doc->IncrementReferens(pShoulder); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- 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); From be8b8c9c95d8257c9bd3543e8b9ef5c4330c625c Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 9 Jun 2014 15:00:26 +0200 Subject: [PATCH 36/42] DialogPointOfContact + DialogLine (no changes) Also renamed specific functions in mainwindow --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogendline.cpp | 1 - src/app/dialogs/tools/dialogline.cpp | 2 +- .../dialogs/tools/dialogpointofcontact.cpp | 147 ++++++++++++------ src/app/dialogs/tools/dialogpointofcontact.h | 27 +++- src/app/dialogs/tools/dialogpointofcontact.ui | 71 +++++++-- src/app/mainwindow.cpp | 40 +++-- src/app/mainwindow.h | 7 +- .../tools/drawTools/vtoolpointofcontact.cpp | 14 +- src/app/tools/drawTools/vtoolpointofcontact.h | 4 +- 9 files changed, 226 insertions(+), 87 deletions(-) diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 580db8ebe..3f341ab32 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -43,7 +43,6 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - // TODO : auto extend height on first value length. this->formulaBaseHeight=ui->plainTextEditFormula->height(); InitOkCancelApply(ui); diff --git a/src/app/dialogs/tools/dialogline.cpp b/src/app/dialogs/tools/dialogline.cpp index 7e15ab494..0e7512024 100644 --- a/src/app/dialogs/tools/dialogline.cpp +++ b/src/app/dialogs/tools/dialogline.cpp @@ -36,7 +36,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); - InitOkCancelApply(ui); + InitOkCancel(ui); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 57d3dedab..fd3de2f51 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -32,60 +32,95 @@ //--------------------------------------------------------------------------------------------------------------------- DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *parent) - :DialogTool(data, parent), ui(), number(0), pointName(QString()), radius(QString()), center(0), + :DialogTool(data, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), radius(QString()), center(0), firstPoint(0), secondPoint(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); + 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); 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() +{ + // TODO issue #79 : back to FormulaChanged when full update + // Also remove this function if only one function called here + this->FormulaChanged2(); +} + +//--------------------------------------------------------------------------------------------------------------------- +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"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -96,10 +131,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; @@ -107,10 +142,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; @@ -118,10 +153,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(""); } @@ -136,30 +171,43 @@ 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); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfContact::setSecondPoint(const quint32 &value, const quint32 &id) { - setCurrentPointId(ui.comboBoxSecondPoint, secondPoint, value, id); + setCurrentPointId(ui->comboBoxSecondPoint, secondPoint, value, id); } //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfContact::setFirstPoint(const quint32 &value, const quint32 &id) { - setCurrentPointId(ui.comboBoxFirstPoint, firstPoint, value, id); + setCurrentPointId(ui->comboBoxFirstPoint, firstPoint, value, id); } //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfContact::setCenter(const quint32 &value, const quint32 &id) { - setCurrentPointId(ui.comboBoxCenter, center, value, id); + setCurrentPointId(ui->comboBoxCenter, center, value, id); center = value; } @@ -167,12 +215,17 @@ 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); } //--------------------------------------------------------------------------------------------------------------------- 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 acde2b352..c9d0a3dd7 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. */ @@ -109,16 +114,28 @@ public slots: * @brief DialogAccepted save data and emit signal about closed dialog. */ virtual void DialogAccepted(); - /** TODO ISSUE 79 : create real function + /** * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(){} + 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 SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ - Ui::DialogPointOfContact ui; + Ui::DialogPointOfContact *ui; /** * @brief number number of handled objects */ @@ -143,6 +160,10 @@ private: * @brief secondPoint id second point of line */ quint32 secondPoint; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline QString DialogPointOfContact::getPointName() const 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/mainwindow.cpp b/src/app/mainwindow.cpp index 48c45b976..b5705a1d5 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -264,7 +264,7 @@ template * @param closeDialogSlot function to handle close of dialog. * @param applyDialogSlot function to handle apply in dialog. */ -void MainWindow::SetToolButton2(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, +void MainWindow::SetToolButtonWithApply(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot, Func2 applyDialogSlot) { if (checked) @@ -314,7 +314,7 @@ void MainWindow::ClosedDialog(int result) */ // TODO ISSUE 79 : rename template -void MainWindow::ClosedDialog2(int result) +void MainWindow::ClosedDialogWithApply(int result) { SCASSERT(dialogTool != nullptr); if (result == QDialog::Accepted) @@ -370,7 +370,7 @@ void MainWindow::ToolEndLine(bool checked) {// TODO ISSUE 79 : copy // SetToolButton(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), // &MainWindow::ClosedDialogEndLine); - SetToolButton2(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), + SetToolButtonWithApply(checked, Valentina::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogEndLine,&MainWindow::ApplyDialogEndLine); } @@ -390,7 +390,7 @@ void MainWindow::ApplyDialogEndLine() */ void MainWindow::ClosedDialogEndLine(int result) { - ClosedDialog2(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -421,7 +421,7 @@ void MainWindow::ClosedDialogLine(int result) */ void MainWindow::ToolAlongLine(bool checked) { - SetToolButton2(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", + SetToolButtonWithApply(checked, Valentina::AlongLineTool, ":/cursor/alongline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogAlongLine, &MainWindow::ApplyDialogAlongLine); } @@ -441,7 +441,7 @@ void MainWindow::ApplyDialogAlongLine() */ void MainWindow::ClosedDialogAlongLine(int result) { - ClosedDialog2(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -451,7 +451,7 @@ void MainWindow::ClosedDialogAlongLine(int result) */ void MainWindow::ToolShoulderPoint(bool checked) { - SetToolButton2(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + SetToolButtonWithApply(checked, Valentina::ShoulderPointTool, ":/cursor/shoulder_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint, &MainWindow::ApplyDialogShoulderPoint); } @@ -472,7 +472,7 @@ void MainWindow::ApplyDialogShoulderPoint() */ void MainWindow::ClosedDialogShoulderPoint(int result) { - ClosedDialog2(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -482,7 +482,7 @@ void MainWindow::ClosedDialogShoulderPoint(int result) */ void MainWindow::ToolNormal(bool checked) { - SetToolButton2(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png", + SetToolButtonWithApply(checked, Valentina::NormalTool, ":/cursor/normal_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogNormal, &MainWindow::ApplyDialogNormal); } @@ -503,7 +503,7 @@ void MainWindow::ApplyDialogNormal() */ void MainWindow::ClosedDialogNormal(int result) { - ClosedDialog2(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -513,7 +513,7 @@ void MainWindow::ClosedDialogNormal(int result) */ void MainWindow::ToolBisector(bool checked) { - SetToolButton2(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png", + SetToolButtonWithApply(checked, Valentina::BisectorTool, ":/cursor/bisector_cursor.png", tr("Select first point of angle"), &MainWindow::ClosedDialogBisector, &MainWindow::ApplyDialogBisector); } @@ -534,7 +534,7 @@ void MainWindow::ApplyDialogBisector() */ void MainWindow::ClosedDialogBisector(int result) { - ClosedDialog2(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- @@ -671,8 +671,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(); } //--------------------------------------------------------------------------------------------------------------------- @@ -682,7 +692,7 @@ void MainWindow::ToolPointOfContact(bool checked) */ void MainWindow::ClosedDialogPointOfContact(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index a1eef0b61..285b78956 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -119,6 +119,7 @@ public slots: 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); @@ -218,17 +219,15 @@ private: void MinimumScrollBar(); template - // TODO ISSUE 79 : delete void SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot); template - // TODO ISSUE 79 : copy - void SetToolButton2(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, + void SetToolButtonWithApply(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot, Func2 applyDialogSlot); template void ClosedDialog(int result); template - void ClosedDialog2(int result); + void ClosedDialogWithApply(int result); template void ApplyDialog(); bool SavePattern(const QString &curFile); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index b374baf18..52615b8b2 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -92,7 +92,7 @@ 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) { SCASSERT(dialog != nullptr); DialogPointOfContact *dialogTool = qobject_cast(dialog); @@ -102,12 +102,18 @@ void VToolPointOfContact::Create(DialogTool *dialog, VMainGraphicsScene *scene, 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) @@ -151,7 +157,9 @@ void VToolPointOfContact::Create(const quint32 _id, QString &radius, const quint doc->IncrementReferens(center); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index ce02fdd50..ea39684b5 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); From 26067c363659f7ae12823bf769b92ff9b474977c Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 9 Jun 2014 18:37:11 +0200 Subject: [PATCH 37/42] DialogCutArc change + start code cleaning --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogalongline.cpp | 4 +- src/app/dialogs/tools/dialogarc.cpp | 2 +- src/app/dialogs/tools/dialogbisector.cpp | 4 +- src/app/dialogs/tools/dialogcutarc.cpp | 60 ++++++++++++++-- src/app/dialogs/tools/dialogcutarc.h | 21 +++++- src/app/dialogs/tools/dialogcutarc.ui | 70 ++++++++++++++++--- src/app/dialogs/tools/dialogcutspline.cpp | 2 +- src/app/dialogs/tools/dialogcutsplinepath.cpp | 2 +- src/app/dialogs/tools/dialogendline.cpp | 4 +- src/app/dialogs/tools/dialogheight.cpp | 2 +- src/app/dialogs/tools/dialoglineintersect.cpp | 2 +- src/app/dialogs/tools/dialognormal.cpp | 4 +- .../dialogs/tools/dialogpointofcontact.cpp | 8 +-- .../tools/dialogpointofintersection.cpp | 2 +- src/app/dialogs/tools/dialogshoulderpoint.cpp | 4 +- src/app/dialogs/tools/dialogsinglepoint.cpp | 2 +- src/app/dialogs/tools/dialogspline.cpp | 2 +- src/app/dialogs/tools/dialogsplinepath.cpp | 2 +- src/app/dialogs/tools/dialogtool.cpp | 18 ++--- src/app/dialogs/tools/dialogtool.h | 17 +++-- src/app/dialogs/tools/dialogtriangle.cpp | 2 +- src/app/dialogs/tools/dialoguniondetails.cpp | 2 +- src/app/mainwindow.cpp | 38 +++++----- src/app/mainwindow.h | 1 + src/app/tools/drawTools/vtoolcutarc.cpp | 14 +++- src/app/tools/drawTools/vtoolcutarc.h | 4 +- 26 files changed, 211 insertions(+), 82 deletions(-) diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 90412de76..92b98a43f 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -69,9 +69,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- void DialogAlongLine::FormulaTextChanged() { - // TODO issue #79 : back to FormulaChanged when full update - // Also remove this function if only one function called here - this->FormulaChanged2(); + this->FormulaChangedPlainText(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 873e9808e..3fe156386 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -48,7 +48,7 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) timerF2 = new QTimer(this); connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); - InitOkCancelApply(ui); + InitOkCancel(ui); FillComboBoxPoints(ui->comboBoxBasePoint); diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 774bba5ea..f7cfbbcf5 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -70,9 +70,7 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- void DialogBisector::FormulaTextChanged() { - // TODO issue #79 : back to FormulaChanged when full update - // Also remove this function if only one function called here - this->FormulaChanged2(); + this->FormulaChangedPlainText(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 1bdd471c2..bf7e0f873 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -41,7 +41,7 @@ DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) : ui->setupUi(this); InitVariables(ui); labelResultCalculation = ui->labelResultCalculation; - lineEditFormula = ui->lineEditFormula; + plainTextEditFormula = ui->plainTextEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; @@ -49,6 +49,7 @@ DialogCutArc::DialogCutArc(const VContainer *data, QWidget *parent) : flagFormula = false; flagName = false; CheckState(); + this->formulaBaseHeight=ui->plainTextEditFormula->height(); FillComboBoxArcs(ui->comboBoxArc); @@ -57,7 +58,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"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -89,12 +119,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 @@ -114,7 +157,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 3c2fa5dbe..e527c4aa1 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; @@ -55,12 +56,24 @@ 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(){} + 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 SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -77,6 +90,10 @@ private: * @brief arcId keep id of arc */ quint32 arcId; + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; //--------------------------------------------------------------------------------------------------------------------- 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 aa5b6ce56..d21bf80d1 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -39,7 +39,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, QWidget *parent) lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancelApply(ui); + InitOkCancel(ui); flagFormula = false; flagName = false; diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index bea8089c0..cf1d3d5ed 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -41,7 +41,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, QWidget *parent labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancelApply(ui); + InitOkCancel(ui); flagFormula = false; flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 3f341ab32..d016fd1e5 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -70,9 +70,7 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- void DialogEndLine::FormulaTextChanged() { - // TODO issue #79 : back to FormulaChanged when full update - // Also remove this function if only one function called here - this->FormulaChanged2(); + this->FormulaChangedPlainText(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index f9b03c0a2..a07e09a11 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -38,7 +38,7 @@ DialogHeight::DialogHeight(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancelApply(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 9c24a6e35..179e80eaf 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -38,7 +38,7 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent { ui->setupUi(this); number = 0; - InitOkCancelApply(ui); + InitOkCancel(ui); labelEditNamePoint = ui->labelEditNamePoint; flagName = false; diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index 056bfaf26..1fd36750d 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -70,9 +70,7 @@ DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- void DialogNormal::FormulaTextChanged() { - // TODO issue #79 : back to FormulaChanged when full update - // Also remove this function if only one function called here - this->FormulaChanged2(); + this->FormulaChangedPlainText(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index fd3de2f51..b9696aa0b 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -50,8 +50,10 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *pare labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; + this->formulaBaseHeight=ui->plainTextEditFormula->height(); InitOkCancelApply(ui); -/* bOk = ui.buttonBox->button(QDialogButtonBox::Ok); + + /* bOk = ui.buttonBox->button(QDialogButtonBox::Ok); SCASSERT(bOk != nullptr); connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); @@ -99,9 +101,7 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *pare //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfContact::FormulaTextChanged() { - // TODO issue #79 : back to FormulaChanged when full update - // Also remove this function if only one function called here - this->FormulaChanged2(); + this->FormulaChangedPlainText(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index 34a736aa1..a5e09ef40 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -38,7 +38,7 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, QWi { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancelApply(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index fe9af1bc7..9a4081a25 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -70,9 +70,7 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent //--------------------------------------------------------------------------------------------------------------------- void DialogShoulderPoint::FormulaTextChanged() { - // TODO issue #79 : back to FormulaChanged when full update - // Also remove this function if only one function called here - this->FormulaChanged2(); + this->FormulaChangedPlainText(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogsinglepoint.cpp b/src/app/dialogs/tools/dialogsinglepoint.cpp index f65840db2..6e929ee23 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.cpp +++ b/src/app/dialogs/tools/dialogsinglepoint.cpp @@ -40,7 +40,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; - InitOkCancelApply(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialogspline.cpp b/src/app/dialogs/tools/dialogspline.cpp index 193a5db87..b76e06f3b 100644 --- a/src/app/dialogs/tools/dialogspline.cpp +++ b/src/app/dialogs/tools/dialogspline.cpp @@ -37,7 +37,7 @@ DialogSpline::DialogSpline(const VContainer *data, QWidget *parent) kAsm1(1), kAsm2(1), kCurve(1) { ui->setupUi(this); - InitOkCancelApply(ui); + InitOkCancel(ui); FillComboBoxPoints(ui->comboBoxP1); FillComboBoxPoints(ui->comboBoxP4); diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index de42f970b..592443515 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -37,7 +37,7 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) { ui->setupUi(this); - InitOkCancelApply(ui); + InitOkCancel(ui); bOk->setEnabled(false); FillComboBoxPoints(ui->comboBoxPoint); diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 469ed6473..e075e63ed 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -290,7 +290,7 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const quint32 &value) const } void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) -{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit +{ SCASSERT(lineEdit != nullptr); SCASSERT(listWidget != nullptr); QListWidgetItem *item = listWidget->currentItem(); @@ -324,7 +324,7 @@ void DialogTool::PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidg //--------------------------------------------------------------------------------------------------------------------- void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) -{// TODO issue #79 : erase this function after all tools updated to plainTextEdit +{ SCASSERT(edit != nullptr); SCASSERT(timer != nullptr); SCASSERT(labelEditFormula != nullptr); @@ -358,7 +358,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim } void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) -{ // TODO issue #79 : erase this function after all tools updated to plainTextEdit +{ SCASSERT(edit != nullptr); SCASSERT(timer != nullptr); SCASSERT(label != nullptr); @@ -565,9 +565,11 @@ void DialogTool::CheckState() { SCASSERT(bOk != nullptr); bOk->setEnabled(flagFormula && flagName); - SCASSERT(bApply != nullptr); - bApply->setEnabled(flagFormula && flagName); - + // In case dialog hasn't apply button + if ( bApply != nullptr) + { + bApply->setEnabled(flagFormula && flagName); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -617,7 +619,7 @@ void DialogTool::DialogRejected() //--------------------------------------------------------------------------------------------------------------------- void DialogTool::FormulaChanged() -{ // TODO issue #79 : erase after full update of tools. +{ QLineEdit* edit = qobject_cast(sender()); if (edit) { @@ -625,7 +627,7 @@ void DialogTool::FormulaChanged() } } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::FormulaChanged2() +void DialogTool::FormulaChangedPlainText() { QPlainTextEdit* edit = qobject_cast(sender()); if (edit) diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 3c1f83f33..ccd8d99d4 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -117,10 +117,13 @@ public slots: */ virtual void DialogRejected(); /** - * @brief formula check formula + * @brief FormulaChanged check formula (one line input only) */ void FormulaChanged(); - void FormulaChanged2(); + /** + * @brief FormulaChangedPlainText check formula (plain text editor editor) + */ + void FormulaChangedPlainText(); /** * @brief ArrowUp set angle value 90 degree */ @@ -475,16 +478,22 @@ protected: connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves); } template + /** + * @brief InitOkCancelApply initialise OK / Cancel and Apply buttons + * @param ui Dialog container + */ void InitOkCancelApply(T *ui) { InitOkCancel(ui); - // TODO issue #79 bApply = ui->buttonBox->button(QDialogButtonBox::Apply); SCASSERT(bApply != nullptr); connect(bApply, &QPushButton::clicked, this, &DialogTool::DialogApply); } - //Left this method for dialog what do not need apply button template + /** + * @brief InitOkCancel initialise OK and Cancel buttons + * @param ui Dialog container + */ void InitOkCancel(T *ui) { bOk = ui->buttonBox->button(QDialogButtonBox::Ok); diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index ea011f33e..63da15c19 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -38,7 +38,7 @@ DialogTriangle::DialogTriangle(const VContainer *data, QWidget *parent) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancelApply(ui); + InitOkCancel(ui); flagName = false; CheckState(); diff --git a/src/app/dialogs/tools/dialoguniondetails.cpp b/src/app/dialogs/tools/dialoguniondetails.cpp index b9e0a2566..7c430437f 100644 --- a/src/app/dialogs/tools/dialoguniondetails.cpp +++ b/src/app/dialogs/tools/dialoguniondetails.cpp @@ -35,7 +35,7 @@ DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) numberP(0), p1(0), p2(0) { ui->setupUi(this); - InitOkCancelApply(ui); + InitOkCancel(ui); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index b5705a1d5..175e16c0a 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -223,7 +223,6 @@ void MainWindow::OptionDraw() * @param toolTip first tooltipe. * @param closeDialogSlot function what handle after close dialog. */ -// TODO Issue 79 : remove function template void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString &cursor, const QString &toolTip, Func closeDialogSlot) @@ -253,10 +252,9 @@ void MainWindow::SetToolButton(bool checked, Valentina::Tools t, const QString & } //--------------------------------------------------------------------------------------------------------------------- -// TODO Issue 79 : rename to SetToolButton template /** - * @brief SetToolButton set tool and show dialog. + * @brief SetToolButtonWithApply set tool and show dialog. * @param checked true if tool button checked. * @param t tool type. * @param cursor path tool cursor icon. @@ -298,7 +296,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Valentina::Tools t, const */ template void MainWindow::ClosedDialog(int result) -{// TODO ISSUE 79 : delete +{ SCASSERT(dialogTool != nullptr); if (result == QDialog::Accepted) { @@ -309,10 +307,9 @@ void MainWindow::ClosedDialog(int result) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief ClosedDialog handle close dialog + * @brief ClosedDialogWithApply handle close dialog that has apply button * @param result result working dialog. */ -// TODO ISSUE 79 : rename template void MainWindow::ClosedDialogWithApply(int result) { @@ -345,7 +342,7 @@ void MainWindow::ClosedDialogWithApply(int result) */ template void MainWindow::ApplyDialog() -{// TODO ISSUE 79 : copy +{ SCASSERT(dialogTool != nullptr); // Only create tool if not already created with apply @@ -367,19 +364,17 @@ void MainWindow::ApplyDialog() * @param checked true - button checked. */ void MainWindow::ToolEndLine(bool checked) -{// TODO ISSUE 79 : copy -// 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); } //--------------------------------------------------------------------------------------------------------------------- -/** // TODO ISSUE 79 : copy +/** * @brief ApplyDialogEndLine actions after apply in DialogEndLine. */ void MainWindow::ApplyDialogEndLine() -{ // TODO ISSUE 79 : copy +{ ApplyDialog(); } @@ -458,7 +453,7 @@ void MainWindow::ToolShoulderPoint(bool checked) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief ApplyDialogShoulderPoint actions after apply in DialogEndLine. + * @brief ApplyDialogShoulderPoint actions after apply in DialogShoulderPoint. */ void MainWindow::ApplyDialogShoulderPoint() { @@ -489,7 +484,7 @@ void MainWindow::ToolNormal(bool checked) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief ApplyDialogNormal actions after apply in ApplyDialogNormal. + * @brief ApplyDialogNormal actions after apply in DialogNormal. */ void MainWindow::ApplyDialogNormal() { @@ -816,8 +811,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(); } //--------------------------------------------------------------------------------------------------------------------- @@ -827,7 +831,7 @@ void MainWindow::ToolCutArc(bool checked) */ void MainWindow::ClosedDialogCutArc(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 285b78956..268103c30 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -127,6 +127,7 @@ public slots: void ClosedDialogUnionDetails(int result); void ClosedDialogCutSpline(int result); void ClosedDialogCutArc(int result); + void ApplyDialogCutArc(); void About(); void AboutQt(); diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index f9e94a570..b46a7c7ab 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -77,7 +77,7 @@ void VToolCutArc::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -void VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, +VToolCutArc* VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); @@ -86,11 +86,17 @@ void VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern 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) { @@ -149,7 +155,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; } //--------------------------------------------------------------------------------------------------------------------- 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; From 3c3e29522ee49560f53a13de249a92759926545b Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 9 Jun 2014 21:27:18 +0300 Subject: [PATCH 38/42] Fix radius spline control point. --HG-- branch : develop --- src/app/widgets/vcontrolpointspline.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/widgets/vcontrolpointspline.cpp b/src/app/widgets/vcontrolpointspline.cpp index 56bbf6e2c..ec28865bd 100644 --- a/src/app/widgets/vcontrolpointspline.cpp +++ b/src/app/widgets/vcontrolpointspline.cpp @@ -36,10 +36,11 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, const QPointF &splinePoint, QGraphicsItem *parent) - :QGraphicsEllipseItem(parent), radius(qApp->toPixel(1.5)), controlLine(nullptr), indexSpline(indexSpline), + :QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position) { //create circle + radius = (1.5/*mm*/ / 25.4) * VApplication::PrintDPI; QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); From b300bfb8f8a16e5c7d250dcff526046f0e975100 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Mon, 9 Jun 2014 22:38:10 +0200 Subject: [PATCH 39/42] DialogArc change... Seems the end at last !!! --HG-- branch : DialogTools --- src/app/dialogs/tools/dialogarc.cpp | 61 ++++++++++++++++++++++++---- src/app/dialogs/tools/dialogarc.h | 15 ++++++- src/app/dialogs/tools/dialogarc.ui | 53 ++++++++++++++++++++---- src/app/dialogs/tools/dialogtool.cpp | 5 --- src/app/dialogs/tools/dialogtool.h | 15 ++++++- src/app/mainwindow.cpp | 16 ++++++-- src/app/mainwindow.h | 1 + src/app/tools/drawTools/vtoolarc.cpp | 14 +++++-- src/app/tools/drawTools/vtoolarc.h | 4 +- 9 files changed, 152 insertions(+), 32 deletions(-) diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 3fe156386..c1248034e 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -48,7 +48,9 @@ DialogArc::DialogArc(const VContainer *data, QWidget *parent) timerF2 = new QTimer(this); connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2); - InitOkCancel(ui); + InitOkCancelApply(ui); + + this->formulaBaseHeight=ui->plainTextEditFormula->height(); FillComboBoxPoints(ui->comboBoxBasePoint); @@ -64,9 +66,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"))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -100,7 +125,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); } //--------------------------------------------------------------------------------------------------------------------- @@ -119,11 +149,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); } //--------------------------------------------------------------------------------------------------------------------- @@ -147,7 +190,7 @@ void DialogArc::ValChenged(int row) //--------------------------------------------------------------------------------------------------------------------- void DialogArc::PutRadius() { - PutValHere(ui->lineEditRadius, ui->listWidget); + PutValHere(ui->plainTextEditFormula, ui->listWidget); } //--------------------------------------------------------------------------------------------------------------------- @@ -173,7 +216,7 @@ void DialogArc::LineAngles() void DialogArc::RadiusChanged() { labelEditFormula = ui->labelEditRadius; - ValFormulaChanged(flagRadius, ui->lineEditRadius, timerRadius); + ValFormulaChanged(flagRadius, ui->plainTextEditFormula, timerRadius); } //--------------------------------------------------------------------------------------------------------------------- @@ -195,13 +238,15 @@ void DialogArc::CheckState() { SCASSERT(bOk != nullptr); bOk->setEnabled(flagRadius && flagF1 && flagF2); + SCASSERT(bApply != nullptr); + bApply->setEnabled(flagRadius && flagF1 && flagF2); } //--------------------------------------------------------------------------------------------------------------------- void DialogArc::EvalRadius() { labelEditFormula = ui->labelEditRadius; - Eval(ui->lineEditRadius, flagRadius, timerRadius, ui->labelResultRadius); + Eval(ui->plainTextEditFormula, flagRadius, timerRadius, ui->labelResultRadius); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogarc.h b/src/app/dialogs/tools/dialogarc.h index dda31681b..554c0a2bd 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; @@ -104,7 +105,11 @@ public slots: /** TODO ISSUE 79 : create real function * @brief DialogApply apply data and emit signal about applied dialog. */ - virtual void DialogApply(){} + virtual void DialogApply(); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployFormulaTextEdit(); /** * @brief ValChenged show description angles of lines * @param row number of row @@ -146,6 +151,10 @@ protected: virtual void CheckState(); private: Q_DISABLE_COPY(DialogArc) + /** + * @brief SaveData Put dialog data in local variables + */ + void SaveData(); /** * @brief ui keeps information about user interface */ @@ -206,6 +215,10 @@ private: * @brief ShowLineAngles show varibles angles of lines */ void ShowLineAngles(); + /** + * @brief formulaBaseHeight base height defined by dialogui + */ + int formulaBaseHeight; }; inline quint32 DialogArc::GetCenter() const 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/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index e075e63ed..5a90c094d 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -34,11 +34,6 @@ #include #include "../../../libs/qmuparser/qmuparsererror.h" -// TODO : for issue #79 -// replace lineEditFormula -> plainTextEditFormula -// delete lineEditFormala everywhrer -// delete PutValHere and eval overloaded functions - //--------------------------------------------------------------------------------------------------------------------- DialogTool::DialogTool(const VContainer *data, QWidget *parent) :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(nullptr), diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index ccd8d99d4..9797c6f87 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -376,7 +376,21 @@ protected: * @param timer timer of formula */ void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); + /** + * @brief ValFormulaChanged handle change formula + * @param flag flag state of formula + * @param edit PlainTextEdit + * @param timer timer of formula + */ void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); + /** + * @brief Eval evaluate formula and show result + * @param edit PlainTextEdit of formula + * @param flag flag state of formula + * @param timer timer of formula + * @param label label for signal error + */ + void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); /** * @brief Eval evaluate formula and show result * @param edit lineEdit of formula @@ -384,7 +398,6 @@ protected: * @param timer timer of formula * @param label label for signal error */ - void Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *label); void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); /** * @brief setCurrentPointId set current point id in combobox diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 175e16c0a..14c3cd1c7 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -602,8 +602,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(); } //--------------------------------------------------------------------------------------------------------------------- @@ -613,7 +623,7 @@ void MainWindow::ToolArc(bool checked) */ void MainWindow::ClosedDialogArc(int result) { - ClosedDialog(result); + ClosedDialogWithApply(result); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 268103c30..2c64f31d9 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -116,6 +116,7 @@ public slots: 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); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index fadf1a9ed..b486e6660 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -73,7 +73,7 @@ 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) { SCASSERT(dialog != nullptr); DialogArc *dialogTool = qobject_cast(dialog); @@ -82,11 +82,17 @@ void VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *d 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) { @@ -121,7 +127,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; } //--------------------------------------------------------------------------------------------------------------------- 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; From 8e7c45488a2b01f640eb4d015e9dd785ab853680 Mon Sep 17 00:00:00 2001 From: Patrick Proy Date: Tue, 10 Jun 2014 08:34:46 +0200 Subject: [PATCH 40/42] Changes to solve issue #161 --HG-- branch : develop --- src/app/xml/vpattern.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 67bd9edc1..154926e73 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -89,6 +89,7 @@ void VPattern::CreateEmptyFile(const QString &tablePath) QDomElement version = createElement(TagVersion); QDomText newNodeText = createTextNode(VAL_STR_VERSION); version.appendChild(newNodeText); + patternElement.appendChild(version); patternElement.appendChild(createElement(TagAuthor)); patternElement.appendChild(createElement(TagDescription)); From efdc947768aac3aba270a40b0fa0dac89b59364d Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 10 Jun 2014 12:49:14 +0300 Subject: [PATCH 41/42] GCC warnings. --HG-- branch : develop --- src/app/dialogs/app/dialogpatternxmledit.cpp | 6 +++--- src/app/dialogs/app/dialogpatternxmledit.h | 2 +- src/app/dialogs/tools/dialogalongline.cpp | 4 ++-- src/app/dialogs/tools/dialogarc.cpp | 3 ++- src/app/dialogs/tools/dialogbisector.cpp | 4 ++-- src/app/dialogs/tools/dialogcutarc.cpp | 5 +++-- src/app/dialogs/tools/dialogendline.cpp | 4 ++-- src/app/dialogs/tools/dialognormal.cpp | 4 ++-- src/app/dialogs/tools/dialognormal.h | 3 ++- src/app/dialogs/tools/dialogpointofcontact.cpp | 4 ++-- src/app/dialogs/tools/dialogshoulderpoint.cpp | 2 +- 11 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/app/dialogs/app/dialogpatternxmledit.cpp b/src/app/dialogs/app/dialogpatternxmledit.cpp index 21044fd26..87ef3a882 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.cpp +++ b/src/app/dialogs/app/dialogpatternxmledit.cpp @@ -1196,9 +1196,9 @@ 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, int nodetype, QDomNode source, bool editor) - : QStandardItem(name), DocNode(source), addedNode(editor), elementType(nodetype), treeNodeValue(""), - treeNodeValueSet(false), treeNodeName(name), selectable(true), parentnode(nullptr) +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) { diff --git a/src/app/dialogs/app/dialogpatternxmledit.h b/src/app/dialogs/app/dialogpatternxmledit.h index 51e3e316f..498701075 100644 --- a/src/app/dialogs/app/dialogpatternxmledit.h +++ b/src/app/dialogs/app/dialogpatternxmledit.h @@ -51,7 +51,7 @@ public: * @param nodetype : node type (node, attribute, root) * @param source : the source dom node */ - explicit VXMLTreeElement (QString name, int nodetype, QDomNode source, bool editor); + explicit VXMLTreeElement (QString name, short int nodetype, QDomNode source, bool editor); explicit VXMLTreeElement (QString name, int nodetype); diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index fa58cf61c..f5491a0d8 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -38,8 +38,8 @@ * @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; diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index c03425285..725a5b917 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -40,7 +40,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); diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 30afe5795..70caa9363 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -38,8 +38,8 @@ * @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); diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index bf7e0f873..337c8aadd 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -35,8 +35,9 @@ * @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); diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 6fc808beb..ff79155c8 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -38,8 +38,8 @@ * @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); diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index dfe72aa7f..00d83ef1e 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -38,8 +38,8 @@ * @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); diff --git a/src/app/dialogs/tools/dialognormal.h b/src/app/dialogs/tools/dialognormal.h index f575fd33f..a2e8f7336 100644 --- a/src/app/dialogs/tools/dialognormal.h +++ b/src/app/dialogs/tools/dialognormal.h @@ -105,8 +105,9 @@ private: /** @brief secondPointId id second point of line */ quint32 secondPointId; + /** @brief formulaBaseHeight base height defined by dialogui */ - int formulaBaseHeight; + int formulaBaseHeight; /** * @brief SaveData Put dialog data in local variables diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index cd99125d5..123f491f3 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -37,8 +37,8 @@ * @param parent parent widget */ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *parent) - :DialogTool(data, parent), ui(new Ui::DialogPointOfContact), 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); InitVariables(ui); diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 36aef56d5..1f349d0cf 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -39,7 +39,7 @@ */ 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; From 2f2e72964a419fcf8dc662837949bac8d8e47094 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 10 Jun 2014 13:13:45 +0300 Subject: [PATCH 42/42] New member of team. --HG-- branch : develop --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) 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. +