--HG--
branch : XML Editor
This commit is contained in:
dismine 2014-05-16 20:00:13 +03:00
parent 1489dc6a1c
commit b28bd29092
8 changed files with 128 additions and 99 deletions

View File

@ -30,7 +30,8 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VIncrement::VIncrement() 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) VIncrement::VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description)
:id(id), base(base), ksize(ksize), kheight(kheight), description(description) :id(id), base(base), ksize(ksize), kheight(kheight), description(description)

View File

@ -30,6 +30,10 @@
#include "ui_dialogaboutapp.h" #include "ui_dialogaboutapp.h"
#include "../../version.h" #include "../../version.h"
#include <QDesktopServices>
#include <QMessageBox>
//---------------------------------------------------------------------------------------------------------------------
DialogAboutApp::DialogAboutApp(QWidget *parent) : DialogAboutApp::DialogAboutApp(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::DialogAboutApp) ui(new Ui::DialogAboutApp)
@ -50,16 +54,18 @@ DialogAboutApp::DialogAboutApp(QWidget *parent) :
} }
//---------------------------------------------------------------------------------------------------------------------
DialogAboutApp::~DialogAboutApp() DialogAboutApp::~DialogAboutApp()
{ {
delete ui; delete ui;
} }
void DialogAboutApp::webButtonClicked() { //---------------------------------------------------------------------------------------------------------------------
if ( ! QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR))) { void DialogAboutApp::webButtonClicked()
QMessageBox::warning(this, {
tr("Warning"), if ( QDesktopServices::openUrl(QUrl(VER_COMPANYDOMAIN_STR)) == false)
tr("Cannot open your default browser")); {
QMessageBox::warning(this, tr("Warning"), tr("Cannot open your default browser"));
} }
} }

View File

@ -31,7 +31,8 @@
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui
{
class DialogAboutApp; class DialogAboutApp;
} }

View File

@ -26,17 +26,17 @@
** **
*************************************************************************/ *************************************************************************/
#include "dialogpatternxmledit.h" #include "dialogpatternxmledit.h"
#include "ui_dialogpatternxmledit.h" #include "ui_dialogpatternxmledit.h"
const short int DialogPatternXmlEdit::ChangeTypeDelete=1; const short int DialogPatternXmlEdit::ChangeTypeDelete=1;
const short int DialogPatternXmlEdit::ChangeTypeAdd=2; const short int DialogPatternXmlEdit::ChangeTypeAdd=2;
const short int DialogPatternXmlEdit::ChangeTypeModify=3; 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); ui->setupUi(this);
@ -86,10 +86,13 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent,VPattern *xmldoc):QDi
connect(ui->pushButton_Remove_attribute, &QPushButton::clicked, connect(ui->pushButton_Remove_attribute, &QPushButton::clicked,
this, &DialogPatternXmlEdit::ButtonDeleteAttributeClicked); this, &DialogPatternXmlEdit::ButtonDeleteAttributeClicked);
connect(ui->pushButton_Add_son, &QPushButton::clicked, this, &DialogPatternXmlEdit::ButtonAddSonClicked); connect(ui->pushButton_Add_son, &QPushButton::clicked, this, &DialogPatternXmlEdit::ButtonAddSonClicked);
connect(ui->pushButton_Add_attribute,&QPushButton::clicked,this,&DialogPatternXmlEdit::ButtonAddAttributeClicked); connect(ui->pushButton_Add_attribute, &QPushButton::clicked, this,
connect(ui->pushButton_Apply_Changes,&QPushButton::clicked,this,&DialogPatternXmlEdit::ButtonApplyChangesClicked); &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; ChangesStackElement* tmp;
@ -113,6 +116,7 @@ DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElem
return changeStackLast; return changeStackLast;
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ButtonApplyChangesClicked() void DialogPatternXmlEdit::ButtonApplyChangesClicked()
{ {
QString Changes=""; QString Changes="";
@ -165,6 +169,7 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked()
// TODO : clear stack and apply // TODO : clear stack and apply
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ButtonCancelClicked() void DialogPatternXmlEdit::ButtonCancelClicked()
{ {
this->ClearEditData(); this->ClearEditData();
@ -185,6 +190,7 @@ void DialogPatternXmlEdit::ButtonCancelClicked()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt) void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt)
{ {
ChangesStackElement* index = this->changeStackRoot; ChangesStackElement* index = this->changeStackRoot;
@ -207,7 +213,8 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt)
delete elmt; delete elmt;
return; return;
} }
while (index->next!=nullptr) { while (index->next!=nullptr)
{
if (index->next == elmt) if (index->next == elmt)
{ {
break; break;
@ -235,6 +242,7 @@ void DialogPatternXmlEdit::RemoveChangeStackElement(ChangesStackElement* elmt)
delete elmt; delete elmt;
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ButtonDeleteAttributeClicked() void DialogPatternXmlEdit::ButtonDeleteAttributeClicked()
{ {
ChangesStackElement* newstack; ChangesStackElement* newstack;
@ -262,6 +270,7 @@ void DialogPatternXmlEdit::ButtonDeleteAttributeClicked()
this->ClearEditData(); this->ClearEditData();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ButtonAddSonClicked() void DialogPatternXmlEdit::ButtonAddSonClicked()
{ {
ChangesStackElement* newstack; ChangesStackElement* newstack;
@ -295,12 +304,9 @@ void DialogPatternXmlEdit::ButtonAddSonClicked()
// create element tree but do not add attribute in DOM (will be done in apply). // create element tree but do not add attribute in DOM (will be done in apply).
QDomNode empty; QDomNode empty;
VXMLTreeElement* tElement = new VXMLTreeElement( VXMLTreeElement* tElement = new VXMLTreeElement(name, VXMLTreeElement::TypeNode, empty, true);
name,
VXMLTreeElement::TypeNode,
empty,true);
if (!value.isEmpty()) if (value.isEmpty() == false)
{ {
tElement->setTreeNodeValue(value); tElement->setTreeNodeValue(value);
} }
@ -323,6 +329,7 @@ void DialogPatternXmlEdit::ButtonAddSonClicked()
ui->pushButton_Apply_Changes->setEnabled(true); ui->pushButton_Apply_Changes->setEnabled(true);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ButtonAddAttributeClicked() void DialogPatternXmlEdit::ButtonAddAttributeClicked()
{ {
ChangesStackElement* newstack; ChangesStackElement* newstack;
@ -355,10 +362,7 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked()
} }
// create element tree but do not add attribute in DOM (will be done in apply). // 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, empty, true);
name,
VXMLTreeElement::TypeAttr,
empty,true);
tElement->setTreeNodeValue(value); tElement->setTreeNodeValue(value);
currentNodeEdited->appendRow(tElement); currentNodeEdited->appendRow(tElement);
@ -377,13 +381,17 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked()
ui->pushButton_Apply_Changes->setEnabled(true); ui->pushButton_Apply_Changes->setEnabled(true);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ButtonSetClicked() void DialogPatternXmlEdit::ButtonSetClicked()
{ {
QString name, value; QString name, value;
ChangesStackElement* newstack; ChangesStackElement* newstack;
// TODO : check if a change has already been done // TODO : check if a change has already been done
if (this->currentNodeEdited == nullptr) return; if (this->currentNodeEdited == nullptr)
{
return;
}
name=ui->lineEdit_Name->text(); name=ui->lineEdit_Name->text();
value=ui->lineEdit_Value->text(); value=ui->lineEdit_Value->text();
bool nameedit, valueedit; bool nameedit, valueedit;
@ -418,6 +426,7 @@ void DialogPatternXmlEdit::ButtonSetClicked()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::NameTextEdited(QString newtext) void DialogPatternXmlEdit::NameTextEdited(QString newtext)
{ {
//QMessageBox::information(this, "nameTextEdited", QString("%1").arg(newtext)); //QMessageBox::information(this, "nameTextEdited", QString("%1").arg(newtext));
@ -425,6 +434,7 @@ void DialogPatternXmlEdit::NameTextEdited(QString newtext)
ui->pushButton_Cancel_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)); //QMessageBox::information(this, "valueTextEdited", QString("%1").arg(newtext));
@ -432,6 +442,7 @@ void DialogPatternXmlEdit::ValueTextEdited(QString newtext)
ui->pushButton_Cancel_Values->setEnabled(true); ui->pushButton_Cancel_Values->setEnabled(true);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ClearEditData() void DialogPatternXmlEdit::ClearEditData()
{ {
ui->lineEdit_Name->setText(""); ui->lineEdit_Name->setText("");
@ -447,6 +458,7 @@ void DialogPatternXmlEdit::ClearEditData()
ui->pushButton_Cancel_Values->setEnabled(false); ui->pushButton_Cancel_Values->setEnabled(false);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ClearStack() void DialogPatternXmlEdit::ClearStack()
{ {
ChangesStackElement * tmp; ChangesStackElement * tmp;
@ -467,6 +479,7 @@ void DialogPatternXmlEdit::ClearStack()
changeStackLast=nullptr; changeStackLast=nullptr;
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::BaseSelectionChanged(int value) void DialogPatternXmlEdit::BaseSelectionChanged(int value)
{ {
QDomNode newbase; QDomNode newbase;
@ -506,6 +519,7 @@ void DialogPatternXmlEdit::BaseSelectionChanged(int value)
return; return;
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index ) void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index )
{ {
@ -563,6 +577,7 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index )
} }
} }
//---------------------------------------------------------------------------------------------------------------------
DialogPatternXmlEdit::~DialogPatternXmlEdit() DialogPatternXmlEdit::~DialogPatternXmlEdit()
{ {
//xmlmodel->clearTree(); //xmlmodel->clearTree();
@ -576,6 +591,7 @@ DialogPatternXmlEdit::~DialogPatternXmlEdit()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXMLTreeView* xmlmodel, bool refresh) void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root, VXMLTreeView* xmlmodel, bool refresh)
{ {
@ -605,7 +621,7 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT
QVariant(rootBasesNum)); QVariant(rootBasesNum));
rootBases[rootBasesNum]=new VXMLTreeElement( rootBases[rootBasesNum]=new VXMLTreeElement(
QString("Drawing %1").arg(tNode.attributes().item(i).nodeValue()), QString("Drawing %1").arg(tNode.attributes().item(i).nodeValue()),
VXMLTreeElement::TypeRoot,tNode,false);; VXMLTreeElement::TypeRoot, tNode, false);
rootBasesNum++; rootBasesNum++;
//QStandardItem* rootNode = (QStandardItem*) rootBases[rootBasesNum]->invisibleRootItem(); //QStandardItem* rootNode = (QStandardItem*) rootBases[rootBasesNum]->invisibleRootItem();
//rootNode->appendRow(tElement); //rootNode->appendRow(tElement);
@ -640,9 +656,7 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT
for (int i = 0; i < tNode.attributes().size(); i++) for (int i = 0; i < tNode.attributes().size(); i++)
{ {
tElement2 = new VXMLTreeElement( tElement2 = new VXMLTreeElement(tNode.attributes().item(i).nodeName(), VXMLTreeElement::TypeAttr,
tNode.attributes().item(i).nodeName(),
VXMLTreeElement::TypeAttr,
tNode, false); tNode, false);
tElement2->setTreeNodeValue(tNode.attributes().item(i).nodeValue()); tElement2->setTreeNodeValue(tNode.attributes().item(i).nodeValue());
tElement->appendRow(tElement2); tElement->appendRow(tElement2);
@ -655,13 +669,15 @@ void DialogPatternXmlEdit::ReadNodes(QDomNode dNode, VXMLTreeElement* root,VXMLT
return; return;
} }
// vXMLTreeView Code ----------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent) VXMLTreeView::VXMLTreeView(QObject *parent) : QStandardItemModel(parent)
{ {
current=last=items=nullptr; current=last=items=nullptr;
} }
void VXMLTreeView::ClearTree() { //---------------------------------------------------------------------------------------------------------------------
void VXMLTreeView::ClearTree()
{
// TODO check if treeitems are deleted with the delete row command of QDom // TODO check if treeitems are deleted with the delete row command of QDom
@ -675,14 +691,13 @@ void VXMLTreeView::ClearTree() {
} }
// reset chain counters // reset chain counters
current=last=items=nullptr; current=last=items=nullptr;
} }
//---------------------------------------------------------------------------------------------------------------------
VXMLTreeView::~VXMLTreeView() VXMLTreeView::~VXMLTreeView()
{ {}
}
//---------------------------------------------------------------------------------------------------------------------
void VXMLTreeView::appendchain(VXMLTreeElement* elmt) void VXMLTreeView::appendchain(VXMLTreeElement* elmt)
{ {
if (last == nullptr) if (last == nullptr)
@ -710,20 +725,18 @@ void VXMLTreeView::appendchain(VXMLTreeElement* elmt)
last=temp; last=temp;
} }
// vXMLTreeElement code -----------------------------------------------------------------
const short int VXMLTreeElement::TypeNode=1; const short int VXMLTreeElement::TypeNode=1;
const short int VXMLTreeElement::TypeAttr=2; const short int VXMLTreeElement::TypeAttr=2;
const short int VXMLTreeElement::TypeRoot=3; 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->elementType=nodetype;
this->DocNode=source; this->DocNode=source;
this->addedNode=editor; this->addedNode=editor;
if (!editor) if (editor == false)
{ {
this->DocNode=source; this->DocNode=source;
} }
@ -741,12 +754,11 @@ 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->treeNodeValue=value;
@ -754,24 +766,33 @@ void VXMLTreeElement::setTreeNodeValue(QString value)
this->setText(this->displayText()); this->setText(this->displayText());
} }
//---------------------------------------------------------------------------------------------------------------------
void VXMLTreeElement::setTreeNodeName(QString value) void VXMLTreeElement::setTreeNodeName(QString value)
{ {
this->treeNodeName=value; this->treeNodeName=value;
this->setText(this->displayText()); this->setText(this->displayText());
} }
//---------------------------------------------------------------------------------------------------------------------
QString VXMLTreeElement::displayText() QString VXMLTreeElement::displayText()
{ {
if (this->elementType == VXMLTreeElement::TypeRoot) if (this->elementType == VXMLTreeElement::TypeRoot)
{
return this->treeNodeName; return this->treeNodeName;
}
return QString("%1 : %2").arg((this->treeNodeName)).arg(this->treeNodeValue); return QString("%1 : %2").arg((this->treeNodeName)).arg(this->treeNodeValue);
} }
QString VXMLTreeElement::gettreeNodeValue() { //---------------------------------------------------------------------------------------------------------------------
QString VXMLTreeElement::gettreeNodeValue()
{
// Only return value if it's really set. // Only return value if it's really set.
if (this->treeNodeValueSet) if (this->treeNodeValueSet)
{
return this->treeNodeValue; return this->treeNodeValue;
else
return "";
} }
else
{
return QString();
}
}

View File

@ -37,7 +37,6 @@
/** /**
* @brief The vXMLTreeElement class : node/attribute of xml pattern. Used by vXMLTreeView * @brief The vXMLTreeElement class : node/attribute of xml pattern. Used by vXMLTreeView
* *
**********************************************************************************************
*/ */
#define BACKGROUND_COLOR_ATTRIBUTE QBrush(Qt::GlobalColor::cyan) #define BACKGROUND_COLOR_ATTRIBUTE QBrush(Qt::GlobalColor::cyan)
@ -146,7 +145,8 @@ public:
/** /**
* @brief The TreeElement struct : chained list of vXMLTreeElement * @brief The TreeElement struct : chained list of vXMLTreeElement
*/ */
typedef struct TreeElementchain { typedef struct TreeElementchain
{
VXMLTreeElement* elmt; VXMLTreeElement* elmt;
TreeElementchain* next; TreeElementchain* next;
} TreeElementchain; } TreeElementchain;
@ -197,7 +197,8 @@ inline VXMLTreeView::TreeElementchain * VXMLTreeView::GetItems()
//******************************************************************************************** //********************************************************************************************
namespace Ui { namespace Ui
{
class DialogPatternXmlEdit; class DialogPatternXmlEdit;
} }
/** /**
@ -227,7 +228,8 @@ public:
// Stack of changes definition // Stack of changes definition
typedef struct ChangesStackElement { typedef struct ChangesStackElement
{
short int type; short int type;
VXMLTreeElement *element; VXMLTreeElement *element;
QString *newText; QString *newText;
@ -277,6 +279,4 @@ private:
ChangesStackElement* changeStackLast; ChangesStackElement* changeStackLast;
}; };
#endif // DIALOGPATTERNXMLEDIT_H #endif // DIALOGPATTERNXMLEDIT_H