FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
QuteSQL/ExportSelectionDialog.cpp at master · jimtendo/QuteSQL · GitHub
jimtendo
QuteSQL
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
QuteSQL
/
ExportSelectionDialog.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (53 loc) · 2 KB
Breadcrumbs
QuteSQL
/
ExportSelectionDialog.cpp
Copy path
File metadata and controls
66 lines (53 loc) · 2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
ExportSelectionDialog.h
"
#
include
"
ui_ExportSelectionDialog.h
"
#
include
<
QFile
>
#
include
<
QFileDialog
>
#
include
<
QTextStream
>
ExportSelectionDialog::ExportSelectionDialog
(QWidget *parent) :
QDialog(parent),
ui(
new
Ui::ExportSelectionDialog)
{
ui->
setupUi
(
this
);
ui->
formatCombo
->
addItem
(
"
CSV
"
);
}
ExportSelectionDialog::~ExportSelectionDialog
()
{
delete
ui;
}
void
ExportSelectionDialog::init
(QTableView *tableView)
{
m_tableView = tableView;
}
void
ExportSelectionDialog::on_buttonBox_accepted
()
{
//
Show dialog and get filename
QString fileName =
QFileDialog::getSaveFileName
(
this
,
tr
(
"
Save File
"
),
QDir::homePath
(),
tr
(
"
CSV Files (*.csv)
"
));
//
If the user chose a file to save to
if
(fileName.
length
()) {
//
Create file handle
QFile
file
(fileName);
//
If we could successfully open the file
if
(file.
open
(QFile::WriteOnly | QFile::Truncate))
{
QTextStream
data
(&file);
QStringList strList;
//
Output header
for
(
int
i =
0
; i < m_tableView->
model
()->
columnCount
(); i++) {
strList <<
"
\"
"
+ m_tableView->
model
()->
headerData
(i, Qt::Horizontal, Qt::DisplayRole).
toString
() +
"
\"
"
;
}
data << strList.
join
(
"
,
"
) +
"
\n
"
;
//
Cycle through each row
for
(
int
row =
0
; row < m_tableView->
model
()->
rowCount
(); row++) {
strList.
clear
();
//
Cycle through each column
for
(
int
column =
0
; column < m_tableView->
model
()->
columnCount
(); column++ ) {
QModelIndex index = m_tableView->
model
()->
index
(row, column,
QModelIndex
());
strList <<
"
\"
"
+ m_tableView->
model
()->
data
(index).
toString
() +
"
\"
"
;
}
data << strList.
join
(
"
,
"
)+
"
\n
"
;
}
//
Close file handle
file.
close
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL