diff options
| author | 2014-12-06 17:33:25 -0500 | |
|---|---|---|
| committer | 2014-12-06 17:33:25 -0500 | |
| commit | 7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch) | |
| tree | a35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/guiSQLiteStudio/common/tablewidget.cpp | |
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/common/tablewidget.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/common/tablewidget.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/common/tablewidget.cpp b/SQLiteStudio3/guiSQLiteStudio/common/tablewidget.cpp new file mode 100644 index 0000000..c9e1446 --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/common/tablewidget.cpp @@ -0,0 +1,49 @@ +#include "tablewidget.h" +#include <QKeyEvent> +#include <QApplication> +#include <QClipboard> +#include <QLabel> + +TableWidget::TableWidget(QWidget *parent) : + QTableWidget(parent) +{ +} + +void TableWidget::keyPressEvent(QKeyEvent *event) +{ + if (event->matches(QKeySequence::Copy)) + { + copy(); + return; + } + + QTableWidget::keyPressEvent(event); +} + +void TableWidget::copy() +{ + QStringList strings; + QStringList cols; + for (int i = 0, total = rowCount(); i < total; ++i) + { + if (!item(i, 0)->isSelected()) + continue; + + for (int c = 1; c <= 2; c++) + { + if (cellWidget(i, c)) + { + QLabel* l = dynamic_cast<QLabel*>(cellWidget(i, c)); + if (l) + cols << l->text(); + } + else + { + cols << item(i, c)->text(); + } + } + strings << cols.join(" "); + } + + QApplication::clipboard()->setText(strings.join("\n")); +} |
