Wat copy paste code en csvwriter alvast toegevoegd maar nog uitgeschakeld.

This commit is contained in:
Eelke Klein 2017-01-13 19:09:58 +01:00
parent cc5bbab0f5
commit be1892ac52
6 changed files with 90 additions and 4 deletions

View file

@ -28,7 +28,8 @@ SOURCES += main.cpp\
asyncdbconnection.cpp \
tsqueue.cpp \
win32event.cpp \
waithandlelist.cpp
waithandlelist.cpp \
csvwriter.cpp
HEADERS += mainwindow.h \
serverproperties.h \
@ -41,7 +42,8 @@ HEADERS += mainwindow.h \
asyncdbconnection.h \
tsqueue.h \
win32event.h \
waithandlelist.h
waithandlelist.h \
csvwriter.h
FORMS += mainwindow.ui \
serverproperties.ui

30
csvwriter.cpp Normal file
View file

@ -0,0 +1,30 @@
#include "csvwriter.h"
CsvWriter::CsvWriter()
{
}
//int complexField = (strchr(field, csvWriter->delimiter_) || strchr(field, '\n') || strchr(field, '\"')) ? 1 : 0;
void CsvWriter::writeField(QString field) {
// if field contains any of seperator quote or newline then it needs to be quoted
// when quoted quotes need to be doubled to escape them
bool needs_quotes = false;
int new_len = field.length();
for (auto ch : field) {
if (ch == m_quote) {
++new_len;
}
if (ch == '\n' || ch == m_seperator || ch == m_quote) {
needs_quotes = true;
}
}
if (needs_quotes) {
new_len += 2;
}
}

23
csvwriter.h Normal file
View file

@ -0,0 +1,23 @@
#ifndef CSVWRITER_H
#define CSVWRITER_H
#include <ostream>
#include <QFileDevice>
class CsvWriter {
public:
CsvWriter();
void setDestination(QFileDevice *output);
void setDestination(QString filename);
void setSeperator(QChar ch);
void writeField(QString field);
void nextLine();
private:
QChar m_seperator = ',';
QChar m_quote = '\'';
QFileDevice *m_output = nullptr;
};
#endif // CSVWRITER_H

View file

@ -435,3 +435,34 @@ void MainWindow::on_actionAbout_triggered()
{
//
}
#if false
void Copy( )
{
QString selected_text;
// You need a pair of indexes to find the row changes
QModelIndex previous = indexes.first();
indexes.removeFirst();
foreach(current, indexes)
{
QVariant data = model->data(current);
QString text = data.toString();
// At this point `text` contains the text in one cell
selected_text.append(text);
// If you are at the start of the row the row number of the previous index
// isn't the same. Text is followed by a row separator, which is a newline.
if (current.row() != previous.row())
{
selected_text.append('\n');
}
// Otherwise it's the same row, so append a column separator, which is a tab.
else
{
selected_text.append('\t');
}
previous = current;
}
QApplication.clipboard().setText(selected_text);
}
#endif

View file

@ -38,7 +38,7 @@
<widget class="QTextEdit" name="queryEdit"/>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<widget class="QWidget" name="messageTab">
<attribute name="title">

View file

@ -205,7 +205,7 @@ public:
retranslateUi(MainWindow);
tabWidget->setCurrentIndex(2);
tabWidget->setCurrentIndex(1);
QMetaObject::connectSlotsByName(MainWindow);