From: Konrad Rosenbaum Date: Wed, 29 Feb 2012 20:28:10 +0000 (+0100) Subject: warnings for parser errors in odf editor X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=87cad720456a7226b100f267c585012747eb2f57;p=web%2Fkonrad%2Fsmoke.git warnings for parser errors in odf editor --- diff --git a/src/templates/odfedit.cpp b/src/templates/odfedit.cpp index 0fceebb..a6ce47d 100644 --- a/src/templates/odfedit.cpp +++ b/src/templates/odfedit.cpp @@ -78,6 +78,7 @@ class DPTR_CLASS_NAME(MOdfEditor) QTextEdit*mText,*mComment; QTableView*mTagAttrs; QStandardItemModel*mTagAttrModel; + bool mChanged; //tree menu QAction*maAddIntoCalc,*maWrapInCond,*maAddIntoComment,*maInsBehindElse,*maWrapInLoop; QAction*maInsBehindCalc,*maInsBehindComment,*maUnwrap,*maDelItem; @@ -95,6 +96,7 @@ class DPTR_CLASS_NAME(MOdfEditor) File(QString n,Type t,const QByteArray&c):name(n),type(t),content(c){} }; QList mFiles; + Private():mChanged(false){st_none=st_tag=st_text=st_loop=st_calc=st_comment=st_cond=-1;} }; DEFINE_DPTR(MOdfEditor); @@ -198,10 +200,14 @@ MOdfEditor::MOdfEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(parent, vl->addLayout(hl=new QHBoxLayout); hl->addWidget(new QLabel(tr("Tag Name:"))); hl->addWidget(d->mTagName=new QLineEdit,1); + connect(d->mTagName,SIGNAL(textEdited(QString)),this,SLOT(setChanged())); vl->addSpacing(15); vl->addWidget(new QLabel(tr("Attributes:"))); vl->addWidget(d->mTagAttrs=new QTableView,1); d->mTagAttrs->setModel(d->mTagAttrModel=new QStandardItemModel); + connect(d->mTagAttrModel,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this,SLOT(setChanged())); + connect(d->mTagAttrModel,SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this,SLOT(setChanged())); + connect(d->mTagAttrModel,SIGNAL(rowsInserted(const QModelIndex&,int,int)), this,SLOT(setChanged())); //loop editor d->st_loop=stack->addWidget(w=new QWidget); w->setLayout(vl=new QVBoxLayout); @@ -209,6 +215,7 @@ MOdfEditor::MOdfEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(parent, vl->addLayout(hl=new QHBoxLayout); hl->addWidget(new QLabel(tr("Loop Variable"))); hl->addWidget(d->mLoopVar=new QLineEdit); + connect(d->mLoopVar,SIGNAL(textEdited(QString)), this,SLOT(setChanged())); vl->addStretch(1); //calc editor d->st_calc=stack->addWidget(w=new QWidget); @@ -217,6 +224,7 @@ MOdfEditor::MOdfEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(parent, vl->addLayout(hl=new QHBoxLayout); hl->addWidget(new QLabel(tr("Expression"))); hl->addWidget(d->mCalcExpr=new QLineEdit); + connect(d->mCalcExpr,SIGNAL(textEdited(QString)), this,SLOT(setChanged())); vl->addStretch(1); //calc editor d->st_cond=stack->addWidget(w=new QWidget); @@ -225,21 +233,26 @@ MOdfEditor::MOdfEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(parent, vl->addLayout(hl=new QHBoxLayout); hl->addWidget(new QLabel(tr("Expression"))); hl->addWidget(d->mCondExpr=new QLineEdit); + connect(d->mCondExpr,SIGNAL(textEdited(QString)), this,SLOT(setChanged())); vl->addStretch(1); //comment editor d->st_comment=stack->addWidget(w=new QWidget); w->setLayout(vl=new QVBoxLayout); vl->addWidget(new QLabel(tr("

Comment

"))); vl->addWidget(d->mComment=new QTextEdit,1); - + connect(d->mComment,SIGNAL(textChanged()),this,SLOT(setChanged())); //statusbar statusBar()->setSizeGripEnabled(true); setAttribute(Qt::WA_DeleteOnClose); updateDisplay(); } +void MOdfEditor::setChanged(bool ch) +{ + d->mChanged=ch; +} -void MOdfEditor::loadFile(QString fn) +void MOdfEditor::loadFile(QString fn,bool istempl) { qDebug()<<"loading ODF template file"<mFiles<mContent.clear(); d->mDomModel->clear(); @@ -306,10 +319,13 @@ void MOdfEditor::parseTemplate(QByteArray bytes) if(!d->mContent.setContent(MOdtRenderer::convertV1toV2(bytes),false,&err,&errln,&errcl)){ qDebug()<<"Hmm, definitely not XML - even after conversion, aborting..."; qDebug()<<" Info: line ="<mFileName)); return; }else{ qDebug()<<"Successfully converted the template."; // qDebug()<<"document has"<mContent.documentElement().childNodes().size()<<"children and"<mContent.documentElement().attributes().size()<<"attribs"; + if(istempl) + QMessageBox::information(this,tr("Conversion Info"),tr("The file '%1' did contain a version 1 template. It has been converted to version 2.\nPlease correct all formulas.").arg(d->mFileName)); } // qDebug()<<"dump\n"<mContent.toByteArray(); d->mDomModel->setDomDocument(d->mContent); @@ -317,15 +333,23 @@ void MOdfEditor::parseTemplate(QByteArray bytes) qDebug()<<"done converting and parsing template"; } -void MOdfEditor::openFile() +void MOdfEditor::openFile(bool istemp) { - QString fn=QFileDialog::getOpenFileName(this,tr("Open Ticket Template")); + QString title=istemp?tr("Open ODF Template"):tr("Open ODF File"); + QString flt=istemp?tr("ODF Template File (*.od?t);;All Files (*)"):tr("ODF File (*.od?);;All Files (*)"); + QString fn=QFileDialog::getOpenFileName(this,title,currentDir(),flt); if(fn!=""){ + setCurrentDir(fn); d->mFileName=fn; - loadFile(fn); + loadFile(fn,istemp); } } +void MOdfEditor::openFile2() +{ + openFile(false); +} + void MOdfEditor::saveFile() { if(d->mFileName=="" || d->mFileName.left(2)==":/") @@ -449,6 +473,11 @@ void MOdfEditor::selectionChange() d->setActions(QList()<maInsBehindCalc<maInsBehindComment<maAddIntoCalc<maAddIntoComment<maWrapInCond<maWrapInLoop<maUnwrap<maDelItem<<(allowElse?d->maInsBehindElse:nullptr)); return; } + if(nn[1]=="template"){ + emit switchStack(d->st_none); + d->setActions(QList()); + return; + } //else: fall through to normal tags } //else: other tags @@ -483,7 +512,13 @@ void MOdfEditor::displayTag() void MOdfEditor::saveCurrentNode() { + //nothing to do? + if(!d->mChanged)return; #warning implement + + qDebug()<<"fake saving item"; + //done! + d->mChanged=false; } void MOdfEditor::Private::setActions(const QList< QAction* >& act) diff --git a/src/templates/odfedit.h b/src/templates/odfedit.h index 96de8f7..5989439 100644 --- a/src/templates/odfedit.h +++ b/src/templates/odfedit.h @@ -33,18 +33,21 @@ class MOdfEditor:public QMainWindow public slots: ///loads a template file, this is a helper for openFile and download - void loadFile(QString); + void loadFile(QString,bool isTemplate=true); ///shows a file open dialog and then opens the selected file - void openFile(); + void openFile(bool isTemplate=true); + ///shows a file open dialog and then opens the selected file + void openFile2(); ///saves the file - if it is local, otherwise calls saveFileAs void saveFile(); ///asks for a new file name void saveFileAs(); ///helper for saveFile and upload void saveFile(QString); + private slots: ///parses the XML part of the template file and fills internal ressources - void parseTemplate(QByteArray); + void parseTemplate(QByteArray,bool isTemplate=true); ///pushes all data from internal ressources to the display void updateDisplay(); ///saves all data to the file (must be open ReadWrite) @@ -53,6 +56,8 @@ class MOdfEditor:public QMainWindow void saveXmlPart(QIODevice&); ///helper: react on selection changes in the DOM tree void selectionChange(); + ///helper: remember that an editor element changed + void setChanged(bool ch=true); signals: ///used to switch to the correct editor widget void switchStack(int); diff --git a/src/templates/odtrender.cpp b/src/templates/odtrender.cpp index 086c359..adc659f 100644 --- a/src/templates/odtrender.cpp +++ b/src/templates/odtrender.cpp @@ -64,6 +64,7 @@ class MOdtRendererPrivate //data the parent uses QString extension; + MOdtRenderer::FileFormat fileformat; private: //methods that the parent does not call @@ -103,7 +104,7 @@ MOdtRenderer::MOdtRenderer(MTemplate file) const QString OdfTemplateNS("http://smoke.silmor.de/odftemplate/namespace"); const QString OdfTemplatePrefix("msmoketpl"); MOdtRendererPrivate::MOdtRendererPrivate(QString file,MOdtRenderer*p) - :tfile(file) + :fileformat(MOdtRenderer::FileFormat::None),tfile(file) { parent=p; //open ZIP @@ -139,14 +140,19 @@ MOdtRendererPrivate::MOdtRendererPrivate(QString file,MOdtRenderer*p) } } //conversion process - if(!dov1)return; + if(!dov1){ + fileformat=MOdtRenderer::FileFormat::Version2; + return; + } //try again if(!cdoc.setContent(MOdtRenderer::convertV1toV2(buffer.data()),false,&err,&errln,&errcl)){ qDebug()<<"Hmm, definitely not XML - even after conversion, aborting..."; qDebug()<<" Info: line ="<fileformat; +} + void MOdtRenderer::renderToFile(QString file) { QFile f(file); diff --git a/src/templates/odtrender.h b/src/templates/odtrender.h index ef19414..cf99d14 100644 --- a/src/templates/odtrender.h +++ b/src/templates/odtrender.h @@ -43,8 +43,21 @@ class MOdtRenderer virtual void renderToPrinter(); ///helper routine: converts a V1 template to V2 + ///you have to make sure to not do a double conversion on an already converted document static QByteArray convertV1toV2(const QByteArray&); + ///format of the file represented by this renderer + enum class FileFormat{ + ///no file loaded or loading was not successful + None, + ///file was a valid v2 format + Version2, + ///file was probably v1 or plain ODF, it has been converted + ConvertedV1, + }; + ///returns the format of the file + FileFormat fileFormat()const; + protected: friend class MOdtRendererPrivate; friend class MOdfEngine;