-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.cpp
108 lines (101 loc) · 2.89 KB
/
backend.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "backend.h"
#include <QTextStream>
#include <QFile>
#include <QStandardPaths>
#include <QDebug>
Backend::Backend(QObject *parent) : QObject(parent)
{
dir.setPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
dir.mkdir("annotation");
dir.mkdir("annotation_forms");
uidir.setPath(dir.path()+"/annotation_forms");
filedir.setPath(dir.path()+"/annotation");
m_filelist = filedir.entryList(QStringList() << "*.ant",QDir::Files);
m_filelist.push_front(tr("Nouveau fichier..."));
m_uilist = uidir.entryList(QStringList() << "*.ui",QDir::Files);
m_uilist.push_front(tr("Choisir..."));
m_uiindex=0;
}
QString Backend::createFunctions(QString s)
{
QString base;
QFile file(":/pagebase.yml");
if(file.open(QIODevice::ReadOnly)) {
base = file.readAll();
}
file.close();
QString resetfunc,titlefunc,datafunc;
QStringList sl,tok;
sl = s.split('\n');
QString id;
bool haveid=false;
for(const QString &line:qAsConst(sl)){
if(line.trimmed().startsWith("//"))
continue;
if(line.contains("id:")){
id=line.mid(line.indexOf(':')+2);
haveid=true;
}
if((haveid)&&(line.contains("}"))){
resetfunc+=id+".reset();\n";
titlefunc+="+"+id+".label+t";
datafunc+="+"+id+".stringvalue";
haveid=false;
}
}
return base.arg(resetfunc,titlefunc,datafunc,s,tr("Enregistrer"));
}
QString Backend::getMainPage(QString uifile)
{
QFile f(uidir.path()+"/"+uifile);
f.open(QFile::ReadOnly);
QTextStream ts(&f);
QString s = ts.readAll();
f.close();
QString gui = createFunctions(s);
return gui;
}
void Backend::createFile(QString filename,QString ui,QString projet, QString domaine, QString obs)
{
if(!filename.endsWith(".ant"))
filename+=".ant";
//qDebug()<<"Creating"<<filename;
m_currentfile=filename;
QFile f(filedir.path()+"/"+m_currentfile);
f.open(QIODevice::WriteOnly);
QTextStream ts(&f);
ts<<ui<<"\n"<<projet<<"\n"<<domaine<<"\n"<<obs<<"\n\n";
ts<<m_title<<"\n";
f.close();
m_filelist.append(m_currentfile);
m_projet=projet;
emit filelistChanged();
emit projectChanged();
}
void Backend::selectFile(QString filename)
{
//qDebug()<<filename<<"selected";
m_currentfile=filename;
}
void Backend::writeData(QString s)
{
QFile f(filedir.path()+"/"+m_currentfile);
f.open(QIODevice::Append);
QTextStream ts(&f);
ts<<s;
f.close();
}
void Backend::filechanged(QString filename)
{
QFile f(filedir.path()+"/"+filename);
if(!f.open(QFile::ReadOnly))return;
QTextStream ts(&f);
QString m_uifile = ts.readLine();
m_uiindex=m_uilist.indexOf(m_uifile);
m_projet = ts.readLine();
m_domaine = ts.readLine();
f.close();
emit projectChanged();
emit domaineChanged();
emit uifileChanged();
}