Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query result UX tweaks #60939

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions src/core/qgsqueryresultmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include "qgsqueryresultmodel.h"
#include "moc_qgsqueryresultmodel.cpp"
#include "qgsexpression.h"
#include "qgsapplication.h"
#include "qgsfileutils.h"

#include <QFont>

const int QgsQueryResultModel::FETCH_MORE_ROWS_COUNT = 400;

Expand Down Expand Up @@ -122,21 +126,76 @@ QVariant QgsQueryResultModel::data( const QModelIndex &index, int role ) const
const QList<QVariant> 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 if ( value.type() == QVariant::ByteArray )
{
return tr( "Binary (%1)" ).arg( QgsFileUtils::representFileSize( value.value< QByteArray >().size() ) );
}
else
{
return value;
}
}
break;
}

case Qt::FontRole:
{
const QList<QVariant> 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<QVariant> 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<QVariant> 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();
}
Expand Down
Loading