18 const int QgsQueryResultModel::FETCH_MORE_ROWS_COUNT = 400;
 
   21   : QAbstractTableModel( parent )
 
   22   , mQueryResult( queryResult )
 
   23   , mColumns( queryResult.columns() )
 
   25   qRegisterMetaType< QList<QList<QVariant>>>( 
"QList<QList<QVariant>>" );
 
   26   mWorker = std::make_unique<QgsQueryResultFetcher>( &mQueryResult );
 
   27   mWorker->moveToThread( &mWorkerThread );
 
   32   mWorkerThread.start();
 
   35     mRows.reserve( mQueryResult.
rowCount() );
 
   41   beginInsertRows( QModelIndex(), mRows.count( ), mRows.count( ) + rows.count() - 1 );
 
   49   if ( parent.isValid() )
 
   51   return mQueryResult.
rowCount() < 0 || mRows.length() < mQueryResult.
rowCount();
 
   57   if ( ! parent.isValid() )
 
   68     mWorker->stopFetching();
 
   86     mWorker->stopFetching();
 
   98   if ( parent.isValid() )
 
  100   return mRows.count();
 
  105   if ( parent.isValid() )
 
  107   return mColumns.count();
 
  112   if ( !index.isValid() || index.row() < 0 || index.column() >= mColumns.count() ||
 
  113        index.row() >= mRows.count( ) )
 
  118     case  Qt::DisplayRole:
 
  120       const QList<QVariant> result = mRows.at( index.row() );
 
  121       if ( index.column() < result.count( ) )
 
  123         return result.at( index.column() );
 
  133   if ( orientation == Qt::Orientation::Horizontal && role == Qt::ItemDataRole::DisplayRole && section < mColumns.count() )
 
  135     return mColumns.at( section );
 
  137   return QAbstractTableModel::headerData( section, orientation, role );
 
  142 const int QgsQueryResultFetcher::ROWS_BATCH_COUNT = 200;
 
  144 void QgsQueryResultFetcher::fetchRows( 
long long maxRows )
 
  146   long long rowCount { 0 };
 
  147   QList<QList<QVariant>> newRows;
 
  148   newRows.reserve( ROWS_BATCH_COUNT );
 
  149   while ( mStopFetching == 0 && mQueryResult->hasNextRow() && ( maxRows < 0 || rowCount < maxRows ) )
 
  151     newRows.append( mQueryResult->nextRow() );
 
  153     if ( rowCount % ROWS_BATCH_COUNT == 0 && mStopFetching == 0 )
 
  155       emit rowsReady( newRows );
 
  160   if ( rowCount % ROWS_BATCH_COUNT && mStopFetching == 0 )
 
  162     emit rowsReady( newRows );
 
  165   emit fetchingComplete();
 
  168 void QgsQueryResultFetcher::stopFetching()