-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsessionmanager.cpp
More file actions
147 lines (132 loc) · 4.34 KB
/
Copy pathsessionmanager.cpp
File metadata and controls
147 lines (132 loc) · 4.34 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "sessionmanager.h"
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlQueryModel>
#include <QSortFilterProxyModel>
#include <QHeaderView>
#include <QDir>
#include <QFileInfo>
#include <QProcess>
#include <QMessageBox>
SessionManager& SessionManager::instance()
{
static SessionManager instance;
return instance;
}
SessionManager::SessionManager()
{
// Initialize databases or other members if necessary
DataTeX_Settings = QSqlDatabase::addDatabase("QSQLITE", "DataTexSettings");
Bibliography_Settings = QSqlDatabase::addDatabase("QSQLITE", "BibSettings");
}
SessionManager::~SessionManager()
{
}
void SessionManager::updateTableView(QTableView * table,QString QueryText,QSqlDatabase Database,QObject * parent)
{
if(table->model()) table->model()->deleteLater();
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(table);
QSqlQueryModel * model = new QSqlQueryModel(proxyModel);
QSqlQuery query(Database);
query.exec(QueryText);
model->setQuery(query);
proxyModel->setSourceModel(model);
table->setModel(proxyModel);
table->show();
table->setSortingEnabled(true);
}
void SessionManager::LoadTableHeaders(QTableView * table,QStringList list)
{
for (int i=0;i<list.count();i++) {
table->model()->setHeaderData(i,Qt::Horizontal,list.at(i),Qt::DisplayRole);
}
}
void SessionManager::StretchColumns(QTableView * Table, float stretchFactor)
{
QFont myFont = Table->horizontalHeader()->font();
QFontMetrics fm(myFont);
for (int c = 0; c < Table->horizontalHeader()->count(); ++c)
{
QString str = Table->model()->headerData(c,Qt::Horizontal,Qt::DisplayRole).toString();
int width=fm.horizontalAdvance(str)*stretchFactor;
Table->setColumnWidth(c,width);
}
Table->horizontalHeader()->setMinimumSectionSize(100);
}
void SessionManager::StretchColumns(QTreeView * Tree, float stretchFactor)
{
QFont myFont = Tree->header()->font();
QFontMetrics fm(myFont);
for (int c = 0; c < Tree->model()->columnCount(); ++c)
{
QString str = Tree->model()->headerData(c,Qt::Horizontal,Qt::DisplayRole).toString();
int width=fm.horizontalAdvance(str)*stretchFactor;
Tree->setColumnWidth(c,width);
}
Tree->header()->setMinimumSectionSize(100);
}
void SessionManager::StretchColumnsToWidth(QTableView * table)
{
for (int c = 0; c < table->horizontalHeader()->count()-1; ++c)
{
table->horizontalHeader()->setSectionResizeMode(
c, QHeaderView::Stretch);
}
}
QStringList SessionManager::GetListWidgetItems(QListWidget * list)
{
QStringList items;
for(int i=0;i<list->count();i++){
items.append(list->item(i)->text());
}
return items;
}
void SessionManager::DBBackUp(QString database, QString dest_path)
{
QFile file(database);
// QProcess::execute("chmod",{"777",datatexpath});
if (QFile::exists(dest_path))
{
QFile::remove(dest_path);
}
file.copy(dest_path);
// QProcess::execute("chmod",{"555",datatexpath});
}
void SessionManager::runQuery_Root(QString queryText,QSqlDatabase database)
{
/* Make dir writable for DataTex_Settings
* QProcess::execute("chmod",{"777",datatexpath});
* run query for DT and Bib databases
* QProcess::execute("chmod",{"555",datatexpath});
* and back readable again */
// QProcess::execute("chmod",{"777",datatexpath});
QSqlQuery query(database);
query.exec(queryText);
// QProcess::execute("chmod",{"555",datatexpath});
}
QString SessionManager::getDataTexPath()
{
return datatexpath;
}
bool SessionManager::SelectNewFileInModel(QTableView * table,QString newFile)
{
QAbstractItemModel * m = table->model();
QModelIndex ix = table->currentIndex();
while (table->model()->canFetchMore(ix))
table->model()->fetchMore(ix);
QModelIndexList matchList = m->match(m->index(0,0), Qt::DisplayRole,
newFile, -1, Qt::MatchFlags(Qt::MatchContains|Qt::MatchWrap));
bool fileFound = matchList.count()>=1;
if(matchList.count()>=1){
table->setCurrentIndex(matchList.first());
table->scrollTo(matchList.first());
}
return fileFound;
}
void SessionManager::FunctionInProgress()
{
QMessageBox msgBox;
msgBox.setText("This function will soon be completed.");
msgBox.addButton(QMessageBox::Ok);
msgBox.exec();
}