diff --git a/util.cpp b/util.cpp index 22c27f3..6bab3b6 100644 --- a/util.cpp +++ b/util.cpp @@ -1,4 +1,8 @@ #include "util.h" +#include "csvwriter.h" +#include +#include +#include // Supported range from microseconds to seconds // min:sec to hours::min::sec @@ -47,3 +51,33 @@ QString msfloatToHumanReadableString(float ms) QString result = QString::asprintf("%0.*f", deci, val); return result + unit; } + +void copySelectionToClipboard(const QTableView *view) +{ + //QAbstractItemModel * model = resultModel; //view->model(); + QItemSelectionModel * selection = view->selectionModel(); + + QModelIndexList selectedIndexes = selection->selectedIndexes(); + + if (selectedIndexes.count() > 0) { + QString clipboard_string; + QTextStream out(&clipboard_string, QIODevice::WriteOnly); + CsvWriter csv(&out); + csv.setSeperator('\t'); + csv.setQuote('"'); + + int previous_row = selectedIndexes[0].row(); + // for (int i = 0; i < selectedIndexes.count(); ++i) { + // QModelIndex current = selectedIndexes[i]; + for (auto current : selectedIndexes) { + if (current.row() > previous_row) { + csv.nextRow(); + previous_row = current.row(); + } + QString display_text = current.data(Qt::DisplayRole).toString(); + csv.writeField(display_text); + } + out.flush(); + QApplication::clipboard()->setText(clipboard_string); + } +} diff --git a/util.h b/util.h index 0a9102d..ac204ce 100644 --- a/util.h +++ b/util.h @@ -2,7 +2,9 @@ #define UTIL_H #include +#include QString msfloatToHumanReadableString(float ms); +void copySelectionToClipboard(const QTableView *view); #endif // UTIL_H