-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainviewmodel.cpp
More file actions
108 lines (90 loc) · 2.55 KB
/
Copy pathmainviewmodel.cpp
File metadata and controls
108 lines (90 loc) · 2.55 KB
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 "mainviewmodel.h"
Mainviewmodel::Mainviewmodel()
{
m_DbMan = new DbManager();
QCoreApplication::setOrganizationName("RolfHausen");
QCoreApplication::setApplicationName("FileUploader");
}
bool Mainviewmodel::openDB(QString servername,QString username, QString password, QString dbname)
{
m_DbMan->setDBServer(servername);
m_DbMan->setDBUser(username);
m_DbMan->setDBpwd(password);
m_DbMan->setDBName(dbname);
if(servername.isEmpty() || username.isEmpty() || password.isEmpty())
{
m_Errors.append("missing Serverdata to connect to Database!");
return false;
}
//store settings
QSettings settings; //to declare it needs a companyname and a projectname in mycase its a developername
settings.setValue("server",servername);
settings.setValue("user",username);
settings.setValue("password",password);
settings.setValue("dbname",dbname);
if(m_DbMan->openDB())
{
QStringList TablesNames=m_DbMan->LoadTables();
m_TableNamesModel = new QStringListModel();
m_TableNamesModel->setStringList(TablesNames);
}
else
{
m_Errors.append(m_DbMan->LastError());
return false;
}
return true;
}
QStringListModel *Mainviewmodel::GetTableNamesModel()
{
return m_TableNamesModel;
}
QStringList Mainviewmodel::LoadTables()
{
return m_DbMan->LoadTables();
}
QStringList Mainviewmodel::LoadTableRows(QString table)
{
return m_DbMan->LoadTableRows(table);
}
QSqlQueryModel *Mainviewmodel::GetTableData()
{
return m_DbMan->GetTableData();
}
bool Mainviewmodel::UploadFile(QString itemname, QString tablename, QString filename)
{
if(filename.isEmpty())
{
m_Errors.append("no file specified!");
return false;
}
QFile file(filename);
if(!file.open(QIODevice::ReadOnly)) return false;
QByteArray filedata = file.readAll();
if(m_DbMan->StoreFile(itemname ,tablename,filename,filedata))
{
m_DbMan->LoadTableRows(tablename); // to refresh the Data after the update
}
else
{
m_Errors.append(m_DbMan->LastError());
return false;
}
return true;
}
void Mainviewmodel::setFileNameCol(QString filenamecol)
{
m_DbMan->setFileNameCol(filenamecol);
QSettings settings;
settings.setValue("filenamecol",filenamecol);
}
void Mainviewmodel::setFileDataCol(QString filedatacol)
{
m_DbMan->setFileDataCol(filedatacol);
QSettings settings;
settings.setValue("filedatacol",filedatacol);
}
const QStringList &Mainviewmodel::Errors() const
{
return m_Errors;
}