-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjkqttools.cpp
More file actions
executable file
·122 lines (105 loc) · 4.93 KB
/
Copy pathjkqttools.cpp
File metadata and controls
executable file
·122 lines (105 loc) · 4.93 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
/*
Copyright (c) 2008-2015 Jan W. Krieger (<jan@jkrieger.de>, <j.krieger@dkfz.de>), German Cancer Research Center (DKFZ) & IWR, University of Heidelberg
last modification: $LastChangedDate$ (revision $Rev$)
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License (LGPL) for more details.
You should have received a copy of the GNU Lesser General Public License (LGPL)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "jkqttools.h"
#include <QList>
#include <QApplication>
#include <QDesktopWidget>
#include <QLocale>
#include <QtCore>
void jksaveWidgetGeometry(QSettings& settings, QWidget* widget, QString prefix) {
settings.setValue(prefix+"pos", widget->pos());
settings.setValue(prefix+"size", widget->size());
}
void jkloadWidgetGeometry(QSettings& settings, QWidget* widget, QPoint defaultPosition, QSize defaultSize, QString prefix) {
QPoint pos = settings.value(prefix+"pos", defaultPosition).toPoint();
QSize size = settings.value(prefix+"size", defaultSize).toSize();
widget->resize(size.boundedTo(QApplication::desktop()->screenGeometry(widget).size()));
if (pos.x()<0 || pos.x()>QApplication::desktop()->screenGeometry(widget).width()) pos.setX(0);
if (pos.y()<0 || pos.y()>QApplication::desktop()->screenGeometry(widget).height()) pos.setY(0);
widget->move(pos);
}
void jkloadWidgetGeometry(QSettings& settings, QWidget* widget, QString prefix) {
jkloadWidgetGeometry(settings, widget, QPoint(10, 10), QSize(100, 100), prefix);
}
void jksaveSplitter(QSettings& settings, QSplitter* splitter, QString prefix) {
/*QList<int> sizes=splitter->sizes();
QString data="";
for (int i=0; i<sizes.size(); i++) {
if (!data.isEmpty()) data=data+",";
data=data+QLocale::system().toString(sizes[i]);
}
settings.setValue(prefix+"splitter_sizes", data);*/
settings.setValue(prefix+"splitter_sizes", splitter->saveState());
}
void jkloadSplitter(QSettings& settings, QSplitter* splitter, QString prefix) {
/*QString data=settings.value(prefix+"splitter_sizes", "").toString();
QList<int> sizes, s1;
QStringList sl=data.split(",");
for (int i=0; i<sl.size(); i++) {
sizes.append(sl[i].toInt());
}
s1=splitter->sizes();
for (int i=0; i<s1.count(); i++) {
if (i<sizes.size()) s1[i]=sizes[i];
}*/
splitter->restoreState(settings.value(prefix+"splitter_sizes").toByteArray());
}
QString jkVariantListToString(const QList<QVariant>& data, QString separator) {
QString r="";
QLocale loc=QLocale::c();
loc.setNumberOptions(QLocale::OmitGroupSeparator);
for (int i=0; i<data.size(); i++) {
if (i>0) r=r+separator;
QVariant v=data[i];
switch (v.type()) {
case QVariant::Bool: r=r+loc.toString(v.toBool()); break;
case QVariant::Char: r=r+loc.toString(v.toInt()); break;
case QVariant::Date: r=r+loc.toString(v.toDate()); break;
case QVariant::DateTime: r=r+loc.toString(v.toDateTime()); break;
case QVariant::Double: r=r+loc.toString(v.toDouble()); break;
case QVariant::Int: r=r+loc.toString(v.toInt()); break;
case QVariant::LongLong: r=r+loc.toString(v.toLongLong()); break;
case QVariant::String: r=r+QString("\"%1\"").arg(v.toString().replace("\"", "_").replace("\t", " ").replace("\r", "").replace("\n", " ").replace(",", " ").replace(";", " ")); break;
case QVariant::Time: r=r+loc.toString(v.toTime()); break;
case QVariant::UInt: r=r+loc.toString(v.toUInt()); break;
case QVariant::ULongLong: r=r+loc.toString(v.toULongLong()); break;
//case : r=r+loc.toString(v.); break;
default: r=r+v.toString(); break;
}
}
return r;
}
LIB_EXPORT QString filenameize(const QString& data) {
QString r;
QString data1=data.simplified();
for (int i=0; i<data1.size(); i++) {
QCharRef c=data1[i];
if (c.isLetterOrNumber() || (c=='-') || (c=='_') || (c=='.')) {
r+=c;
} else {
r+='_';
}
}
return r;
}
QString toValidVariableName(const QString& input) {
QString out="";
for (int i=0; i<input.size(); i++) {
if (input[i].isLetter()) out=out+input[i];
if (input[i].isDigit()&&(out.size()>0)) out=out+input[i];
if ((input[i]=='_')&&(out.size()>0)) out=out+input[i];
}
return out;
}