From 65a14f4da02f31bcedf6a5a4ae908bdb96e9895e Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 25 Oct 2010 19:29:55 +0000 Subject: [PATCH] template manager: * add save template option * start on template editor for labels git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@613 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/mwin/overview.cpp | 4 +- src/templates/templatedlg.cpp | 103 ++++++++++++++++++++++++++++++++++++++++- src/templates/templatedlg.h | 2 + src/templates/templates.cpp | 25 +++++++++- src/templates/templates.h | 12 ++++- src/templates/templates.pri | 6 ++- src/templates/ticketedit.cpp | 33 +++++++++++++ src/templates/ticketedit.h | 33 +++++++++++++ 8 files changed, 207 insertions(+), 11 deletions(-) create mode 100644 src/templates/ticketedit.cpp create mode 100644 src/templates/ticketedit.h diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index d5a4f04..e3c7858 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -526,8 +526,8 @@ void MOverview::aclWindow() void MOverview::editTemplates() { - MTemplateEditor te(MSInterface::instance()->templateStore()); - te.exec(); + MTemplateEditor *te=new MTemplateEditor(MSInterface::instance()->templateStore()); + te->show(); } void MOverview::wizardMode() diff --git a/src/templates/templatedlg.cpp b/src/templates/templatedlg.cpp index 641b834..5b14dbb 100644 --- a/src/templates/templatedlg.cpp +++ b/src/templates/templatedlg.cpp @@ -11,15 +11,17 @@ // #include "templatedlg.h" +#include "ticketedit.h" -#include #include +#include +#include #include #include +#include #include #include #include -#include #include #include @@ -87,6 +89,11 @@ MTemplateEditor::MTemplateEditor(MTemplateStore*s) connect(p,SIGNAL(clicked()),this,SLOT(addItem())); vl2->addWidget(p=new QPushButton(tr("Delete Variant"))); connect(p,SIGNAL(clicked()),this,SLOT(deleteItem())); + vl2->addSpacing(20); + vl2->addWidget(p=new QPushButton(tr("Save Template"))); + connect(p,SIGNAL(clicked()),this,SLOT(saveItem())); + vl2->addWidget(p=new QPushButton(tr("Edit Template"))); + connect(p,SIGNAL(clicked()),this,SLOT(editItem())); vl2->addStretch(1); vl->addSpacing(15); @@ -226,3 +233,95 @@ void MTemplateEditor::forceUpdate() store->updateTemplates(true); updateView(); } + +void MTemplateEditor::editItem() +{ + //get selection + QModelIndex idx=tree->currentIndex(); + if(!idx.isValid())return; + QModelIndex pidx=idx.parent(); + QModelIndex bidx=model->index(idx.row(),0,pidx); + QString base=model->data(bidx,BASEROLE).toString(); + if(base=="")return; + //query file name + QString fn=model->data(bidx,NAMEROLE).toString(); + qDebug()<<"editing base"<getTemplateByFile(fn); + MTemplate::Type tp=tmp.type(); + if(tp&MTemplate::OdfTemplateMask){ + QMessageBox::warning(this,"Sorry","Sorry, no ODF editor yet."); + }else + if(tp==MTemplate::LabelTemplate){ + MTicketEditor *ed=new MTicketEditor(this); + ed->loadFile(tmp.cacheFileName()); + ed->show(); + }else + if(tp==MTemplate::ZipTemplate){ + QMessageBox::warning(this,"Sorry","Sorry, no ZIP selection"); + }else{ + QMessageBox::warning(this,tr("Warning"),tr("Unknown template type, cannot edit it.")); + } + }else{ + } + /*QString ext=QFileInfo(fn).completeSuffix(); + if(!MTemplate::legalSuffixes(base).contains(ext)){ + QMessageBox::warning(this,tr("Warning"),tr("Files with this extension (%1) are not legal for this template.").arg(ext)); + return; + } + //get new variant name + QStringList lst; + for(int i=0;irowCount(pidx);i++){ + QStringList f=model->data(model->index(i,0,pidx),NAMEROLE).toString().split(","); + if(f.size()>1) + lst<setTemplate(base+"."+ext+","+nvar,fn)) + forceUpdate(); + else + QMessageBox::warning(this,tr("Warning"),tr("Unable to upload file."));*/ +} + +void MTemplateEditor::saveItem() +{ + //get selection + QModelIndex idx=tree->currentIndex(); + if(!idx.isValid())return; + QModelIndex pidx=idx.parent(); + QModelIndex bidx=model->index(idx.row(),0,pidx); + QString base=model->data(bidx,BASEROLE).toString(); + if(base=="")return; + //query file name + QString fn=model->data(bidx,NAMEROLE).toString(); + if(fn=="")return; + //get it + MTemplate tmp=store->getTemplateByFile(fn); + fn=tmp.cacheFileName(); + if(fn==""){ + QMessageBox::warning(this,tr("Warning"),tr("Ooops. Lost the template file, cannot store it.")); + return; + } + //get file name + QString nfn; + { + QFileDialog fd(this,tr("Save template as...")); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setDefaultSuffix(tmp.extension()); + fd.selectFile(tmp.baseName()); + if(fd.exec()!=QDialog::Accepted) + return; + nfn=fd.selectedFiles().at(0); + if(nfn=="")return; + } + //store it + if(!QFile::copy(fn,nfn)) + QMessageBox::warning(this,tr("Error"),tr("Unable to save the template file.")); + +} diff --git a/src/templates/templatedlg.h b/src/templates/templatedlg.h index b4e7fcb..b5a7bc8 100644 --- a/src/templates/templatedlg.h +++ b/src/templates/templatedlg.h @@ -52,6 +52,8 @@ class MTemplateEditor:public QDialog void addItem(); void changeDescr(QStandardItem*); void forceUpdate(); + void editItem(); + void saveItem(); private: MTemplateStore*store; QTreeView*tree; diff --git a/src/templates/templates.cpp b/src/templates/templates.cpp index 41271f4..aeddc64 100644 --- a/src/templates/templates.cpp +++ b/src/templates/templates.cpp @@ -75,6 +75,25 @@ MTemplate MTemplateStore::getTemplate(QString f) else return MTemplate(); } +MTemplate MTemplateStore::getTemplateByFile(QString f) +{ + //syntax check + f=f.toLower(); + QRegExp fregexp("[a-z0-9_\\.,]+"); + if(!fregexp.exactMatch(f))return MTemplate(); + //update directory (no force) + updateTemplates(false); + //find files matching the pattern + //basics + QString dname=req->dataDir()+"/templates/"; + QSettings set; + set.beginGroup("templates/"+profileid); + //check directory + if(!set.childGroups().contains(f))return MTemplate(); + //return if found + return MTemplate(dname+"/"+f, set.value(f+"/checksum").toString(), set.value(f+"/description").toString()); +} + void MTemplateStore::updateTemplates(bool force) { //basics @@ -291,7 +310,7 @@ QString MTemplate::targetExtension()const return ""; } -bool MTemplate::isOdf()const{return (type()&OdfTemplate)!=0;} +bool MTemplate::isOdf()const{return (type()&OdfTemplateMask)!=0;} bool MTemplate::isLabel()const{return type()==LabelTemplate;} MTemplate::Type MTemplate::type()const @@ -305,6 +324,8 @@ MTemplate::Type MTemplate::type()const if(x=="odbt")return OdbTemplate; //label? if(x=="xtt")return LabelTemplate; + //script? + if(x=="zip")return ZipTemplate; //hmm, unknown one return UnknownTemplate; } @@ -328,7 +349,7 @@ MTemplate::Types MTemplate::legalTypes(QString bn) if(bn=="ticket" || bn=="voucher") return LabelTemplate; if(bn=="bill" || bn=="eventsummary") - return OdfTemplate; + return OdfTemplateMask; if(bn=="scripts") return ZipTemplate; return UnknownTemplate; diff --git a/src/templates/templates.h b/src/templates/templates.h index b6b52ee..aaf8ad6 100644 --- a/src/templates/templates.h +++ b/src/templates/templates.h @@ -73,7 +73,7 @@ class MTemplate /**ODF DataBase*/ OdbTemplate=0x10, /**ODF template*/ - OdfTemplate=0xff, + OdfTemplateMask=0xff, /**Label template*/ LabelTemplate=0x100, /**Script-Zip template*/ @@ -135,8 +135,14 @@ class MTemplateStore bool retrieveFile(QString,QString); public: - /**returns a specific template, opens a template choice dialog if necessary*/ - MTemplate getTemplate(QString); + /**returns a specific template by its base name, opens a template choice dialog if necessary + \param base the base name of the template to retrieve (eg. "ticket" or "voucher")*/ + MTemplate getTemplate(QString base); + /**returns a specific template by its full name, opens a template choice dialog if necessary + \param full the base name of the template to retrieve (eg. "ticket.xtt,1")*/ + MTemplate getTemplateByFile(QString full); + + private: QString profileid; diff --git a/src/templates/templates.pri b/src/templates/templates.pri index 9085cb3..5ef18a9 100644 --- a/src/templates/templates.pri +++ b/src/templates/templates.pri @@ -4,7 +4,8 @@ HEADERS += \ templates/office.h \ templates/labeldlg.h \ templates/templates.h \ - templates/templatedlg.h + templates/templatedlg.h \ + templates/ticketedit.h SOURCES += \ templates/odtrender.cpp \ @@ -12,6 +13,7 @@ SOURCES += \ templates/office.cpp \ templates/labeldlg.cpp \ templates/templates.cpp \ - templates/templatedlg.cpp + templates/templatedlg.cpp \ + templates/ticketedit.cpp INCLUDEPATH += ./templates \ No newline at end of file diff --git a/src/templates/ticketedit.cpp b/src/templates/ticketedit.cpp new file mode 100644 index 0000000..fe0d37a --- /dev/null +++ b/src/templates/ticketedit.cpp @@ -0,0 +1,33 @@ +// +// C++ Implementation: ticket template editor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "ticketedit.h" + +MTicketEditor::MTicketEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(parent, f) +{ + +} + +void MTicketEditor::loadFile(QString ) +{ + +} + +void MTicketEditor::openFile() +{ + +} + +void MTicketEditor::rerender() +{ + +} diff --git a/src/templates/ticketedit.h b/src/templates/ticketedit.h new file mode 100644 index 0000000..bf7bc8a --- /dev/null +++ b/src/templates/ticketedit.h @@ -0,0 +1,33 @@ +// +// C++ Interface: ticket template editor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_TICKETEDIT_H +#define MAGICSMOKE_TICKETEDIT_H + +#include + +class MTicketEditor:public QMainWindow +{ + Q_OBJECT + public: + MTicketEditor(QWidget* parent = 0, Qt::WindowFlags f = 0); + + public slots: + void loadFile(QString); + void openFile(); + private slots: + void rerender(); + private: + +}; + +#endif -- 1.7.2.5