From cf4765d6a0c5a729d8189b5e047bf18ccb96746d Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 11 Mar 2025 09:36:03 +1000 Subject: [PATCH 1/2] Nicer appearance for NULL values in execute sql results table Match appearance to attribute table, showing application NULL string in a shaded, italic font --- src/core/qgsqueryresultmodel.cpp | 58 ++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/core/qgsqueryresultmodel.cpp b/src/core/qgsqueryresultmodel.cpp index 451b61cbf61d..acbbc088a2dc 100644 --- a/src/core/qgsqueryresultmodel.cpp +++ b/src/core/qgsqueryresultmodel.cpp @@ -16,6 +16,9 @@ #include "qgsqueryresultmodel.h" #include "moc_qgsqueryresultmodel.cpp" #include "qgsexpression.h" +#include "qgsapplication.h" + +#include const int QgsQueryResultModel::FETCH_MORE_ROWS_COUNT = 400; @@ -122,21 +125,72 @@ QVariant QgsQueryResultModel::data( const QModelIndex &index, int role ) const const QList result = mRows.at( index.row() ); if ( index.column() < result.count( ) ) { - return result.at( index.column() ); + const QVariant value = result.at( index.column() ); + + if ( QgsVariantUtils::isNull( value ) ) + { + return QgsApplication::nullRepresentation(); + } + else + { + return value; + } } break; } + case Qt::FontRole: + { + const QList result = mRows.at( index.row() ); + if ( index.column() < result.count( ) ) + { + const QVariant value = result.at( index.column() ); + + if ( QgsVariantUtils::isNull( value ) ) + { + QFont f; + f.setItalic( true ); + return f; + } + } + return QVariant(); + } + + case Qt::ForegroundRole: + { + const QList result = mRows.at( index.row() ); + if ( index.column() < result.count( ) ) + { + const QVariant value = result.at( index.column() ); + + if ( QgsVariantUtils::isNull( value ) ) + { + return QColor( 128, 128, 128 ); + } + } + return QVariant(); + } + case Qt::ToolTipRole: { const QList result = mRows.at( index.row() ); if ( index.column() < result.count( ) ) { const QVariant value = result.at( index.column() ); - return QgsExpression::formatPreviewString( value, true, 255 ); + if ( QgsVariantUtils::isNull( value ) ) + { + return QVariant(); + } + else + { + return QgsExpression::formatPreviewString( value, true, 255 ); + } } break; } + + default: + break; } return QVariant(); } From e22d5aa9acd487d5b41898627a93a97adbdf9cf0 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 11 Mar 2025 09:36:54 +1000 Subject: [PATCH 2/2] Don't try to show raw binary data in query result table --- src/core/qgsqueryresultmodel.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/qgsqueryresultmodel.cpp b/src/core/qgsqueryresultmodel.cpp index acbbc088a2dc..ad56951cfb20 100644 --- a/src/core/qgsqueryresultmodel.cpp +++ b/src/core/qgsqueryresultmodel.cpp @@ -17,6 +17,7 @@ #include "moc_qgsqueryresultmodel.cpp" #include "qgsexpression.h" #include "qgsapplication.h" +#include "qgsfileutils.h" #include @@ -131,6 +132,10 @@ QVariant QgsQueryResultModel::data( const QModelIndex &index, int role ) const { return QgsApplication::nullRepresentation(); } + else if ( value.type() == QVariant::ByteArray ) + { + return tr( "Binary (%1)" ).arg( QgsFileUtils::representFileSize( value.value< QByteArray >().size() ) ); + } else { return value;