--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()
: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)

View File

@ -30,6 +30,10 @@
#include "ui_dialogaboutapp.h"
#include "../../version.h"
#include <QDesktopServices>
#include <QMessageBox>
//---------------------------------------------------------------------------------------------------------------------
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"));
}
}

View File

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

View File

@ -26,17 +26,17 @@
**
*************************************************************************/
#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);
@ -86,10 +86,13 @@ DialogPatternXmlEdit::DialogPatternXmlEdit(QWidget *parent,VPattern *xmldoc):QDi
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);
}
//---------------------------------------------------------------------------------------------------------------------
DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElement(short int typechange)
{
ChangesStackElement* tmp;
@ -113,6 +116,7 @@ DialogPatternXmlEdit::ChangesStackElement* DialogPatternXmlEdit::CreateStackElem
return changeStackLast;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ButtonApplyChangesClicked()
{
QString Changes="";
@ -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,13 +381,17 @@ void DialogPatternXmlEdit::ButtonAddAttributeClicked()
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;
if (this->currentNodeEdited == nullptr)
{
return;
}
name=ui->lineEdit_Name->text();
value=ui->lineEdit_Value->text();
bool nameedit, valueedit;
@ -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;
@ -506,6 +519,7 @@ void DialogPatternXmlEdit::BaseSelectionChanged(int value)
return;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index )
{
@ -563,6 +577,7 @@ void DialogPatternXmlEdit::ElementClicked ( const QModelIndex & index )
}
}
//---------------------------------------------------------------------------------------------------------------------
DialogPatternXmlEdit::~DialogPatternXmlEdit()
{
//xmlmodel->clearTree();
@ -576,6 +591,7 @@ DialogPatternXmlEdit::~DialogPatternXmlEdit()
}
}
//---------------------------------------------------------------------------------------------------------------------
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));
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);
@ -640,9 +656,7 @@ 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,
tElement2 = new VXMLTreeElement(tNode.attributes().item(i).nodeName(), VXMLTreeElement::TypeAttr,
tNode, false);
tElement2->setTreeNodeValue(tNode.attributes().item(i).nodeValue());
tElement->appendRow(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,20 +725,18 @@ 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;
}
@ -741,12 +754,11 @@ VXMLTreeElement::VXMLTreeElement(QString name, int nodetype, QDomNode source,boo
}
}
//---------------------------------------------------------------------------------------------------------------------
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 "";
}
else
{
return QString();
}
}

View File

@ -37,7 +37,6 @@
/**
* @brief The vXMLTreeElement class : node/attribute of xml pattern. Used by vXMLTreeView
*
**********************************************************************************************
*/
#define BACKGROUND_COLOR_ATTRIBUTE QBrush(Qt::GlobalColor::cyan)
@ -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,7 +197,8 @@ inline VXMLTreeView::TreeElementchain * VXMLTreeView::GetItems()
//********************************************************************************************
namespace Ui {
namespace Ui
{
class DialogPatternXmlEdit;
}
/**
@ -227,7 +228,8 @@ public:
// 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