From db735363f7128568e4dd60c2f5753aa207f839dc Mon Sep 17 00:00:00 2001 From: eelke Date: Thu, 7 Feb 2019 16:48:30 +0100 Subject: [PATCH] QueryResultModel no longer truncates long strings to improve display performance. Optimization of display is now done by PgLabItemDelegate. This also makes it easier in future commit to enabled showing complete string and correctly exporting the data. --- pglab/PgLabItemDelegate.cpp | 11 ++++++++--- pglab/QueryResultModel.cpp | 17 +---------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/pglab/PgLabItemDelegate.cpp b/pglab/PgLabItemDelegate.cpp index 743b34a..c489321 100644 --- a/pglab/PgLabItemDelegate.cpp +++ b/pglab/PgLabItemDelegate.cpp @@ -99,9 +99,14 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option, option->palette.setBrush(QPalette::Text, QBrush(forground_color)); option->features |= QStyleOptionViewItem::HasDisplay; - option->text = oid == Pgsql::bool_oid - ? FormatBoolForDisplay(value.toBool()) - : displayText(value, option->locale); + if (oid == Pgsql::bool_oid) + option->text = FormatBoolForDisplay(value.toBool()); + else { + auto str = value.toString(); + auto s = str.leftRef(100); + auto f = s.indexOf('\n'); + option->text = ((f > 0) ? s.left(f) : s).toString(); + } } else { option->palette.setBrush(QPalette::Text, QBrush(GetDefaultNullColor())); diff --git a/pglab/QueryResultModel.cpp b/pglab/QueryResultModel.cpp index 6d5c5bd..ad82698 100644 --- a/pglab/QueryResultModel.cpp +++ b/pglab/QueryResultModel.cpp @@ -28,19 +28,6 @@ int QueryResultModel::columnCount(const QModelIndex &) const return r; } -//Oid QueryResultModel::getType(int column) const -//{ -// return result->type(column); -//} - -//QVariant QueryResultModel::getData(const QModelIndex &index) const -//{ -// QVariant r; -// int rij = index.row(); -// int col = index.column(); -// return r; -//} - QVariant QueryResultModel::data(const QModelIndex &index, int role) const { // static const QString null_str("null"); @@ -61,9 +48,6 @@ QVariant QueryResultModel::data(const QModelIndex &index, int role) const } else { QString s = value; - if (s.length() > 256) { - s.truncate(256); - } v = s; } } @@ -72,6 +56,7 @@ QVariant QueryResultModel::data(const QModelIndex &index, int role) const v = oid; } + return v; }