QTextEdit*mText,*mComment;
QTableView*mTagAttrs;
QStandardItemModel*mTagAttrModel;
+ bool mChanged;
//tree menu
QAction*maAddIntoCalc,*maWrapInCond,*maAddIntoComment,*maInsBehindElse,*maWrapInLoop;
QAction*maInsBehindCalc,*maInsBehindComment,*maUnwrap,*maDelItem;
File(QString n,Type t,const QByteArray&c):name(n),type(t),content(c){}
};
QList<File> mFiles;
+ Private():mChanged(false){st_none=st_tag=st_text=st_loop=st_calc=st_comment=st_cond=-1;}
};
DEFINE_DPTR(MOdfEditor);
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);
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);
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);
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("<h1>Comment</h1>")));
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"<<fn;
//try to open the file
}
QUnZip unz;
if(!unz.open(&fd)){
- QMessageBox::warning(this, tr("Error"), tr("Unable to interpret file '%1'.").arg(fn));
+ QMessageBox::warning(this, tr("Error"), tr("Unable to interpret file '%1'. It is not an ODF container (PKZip format).").arg(fn));
return;
}
//clear cache
QBuffer buf;buf.open(QIODevice::ReadWrite);
unz.getCurrentFile(buf);
if(ifn=="content.xml")
- parseTemplate(buf.data());
+ parseTemplate(buf.data(),istempl);
else
d->mFiles<<Private::File(ifn,Private::File::Type::FlatFile,buf.data());
}while(unz.gotoNextFile());
}
-void MOdfEditor::parseTemplate(QByteArray bytes)
+void MOdfEditor::parseTemplate(QByteArray bytes,bool istempl)
{
d->mContent.clear();
d->mDomModel->clear();
if(!d->mContent.setContent(MOdtRenderer::convertV1toV2(bytes),false,&err,&errln,&errcl)){
qDebug()<<"Hmm, definitely not XML - even after conversion, aborting...";
qDebug()<<" Info: line ="<<errln<<"column ="<<errcl<<"error ="<<err;
+ QMessageBox::warning(this,tr("Warning"),tr("The file '%1' does not contain a valid ODF file or template of any version.").arg(d->mFileName));
return;
}else{
qDebug()<<"Successfully converted the template.";
// qDebug()<<"document has"<<d->mContent.documentElement().childNodes().size()<<"children and"<<d->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"<<d->mContent.toByteArray();
d->mDomModel->setDomDocument(d->mContent);
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)==":/")
d->setActions(QList<QAction*>()<<d->maInsBehindCalc<<d->maInsBehindComment<<d->maAddIntoCalc<<d->maAddIntoComment<<d->maWrapInCond<<d->maWrapInLoop<<d->maUnwrap<<d->maDelItem<<(allowElse?d->maInsBehindElse:nullptr));
return;
}
+ if(nn[1]=="template"){
+ emit switchStack(d->st_none);
+ d->setActions(QList<QAction*>());
+ return;
+ }
//else: fall through to normal tags
}
//else: other tags
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)