Example #1
0
void PageProvider::gotoPage(uint page)
{
  qDebug() << "PageProvider::gotoPage";
  if (numPages() <= page) {
	qDebug() << "Invalid page number" << page;
	return;
  }

  //request synchronously the current page
  sendPageRequest(page);
  if (PageCache::VALID != pageCache_[page % CACHE_SIZE].status) {
    evt_.exec();
  }
  //asynchronous requests (make sure that the entire cache is marked as filled)
  if (1 <= page) {
    sendPageRequest(page-1);
  }
  else if ((numPages() > (page+2))) {
    pageCache_[(page+2) % CACHE_SIZE].status = PageCache::VALID;
  }
  if (numPages() > (page+1)) {
    sendPageRequest(page+1);
  }
  else if (2 <= page) {
    pageCache_[(page-2) % CACHE_SIZE].status = PageCache::VALID;
  }
}
Example #2
0
void QgsComposition::setNumPages( int pages )
{
  int currentPages = numPages();
  int diff = pages - currentPages;
  if ( diff >= 0 )
  {
    for ( int i = 0; i < diff; ++i )
    {
      addPaperItem();
    }
  }
  else
  {
    diff = -diff;
    for ( int i = 0; i < diff; ++i )
    {
      delete mPages.last();
      mPages.removeLast();
    }
  }

  // update the corresponding variable
  QgsExpression::setSpecialColumn( "$numpages", QVariant(( int )numPages() ) );

  emit nPagesChanged();
}
Example #3
0
void QgsComposition::print( QPrinter &printer )
{
  //set resolution based on composer setting
  printer.setFullPage( true );
  printer.setColorMode( QPrinter::Color );

  //set user-defined resolution
  printer.setResolution( printResolution() );

  QPainter p( &printer );

  //QgsComposition starts page numbering at 0
  int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1 ;
  int toPage = ( printer.toPage() < 1 ) ? numPages() - 1 : printer.toPage() - 1;

  if ( mPrintAsRaster )
  {
    for ( int i = fromPage; i <= toPage; ++i )
    {
      if ( i > fromPage )
      {
        printer.newPage();
      }

      QImage image = printPageAsRaster( i );
      if ( !image.isNull() )
      {
        QRectF targetArea( 0, 0, image.width(), image.height() );
        p.drawImage( targetArea, image, targetArea );
      }
    }
  }

  if ( !mPrintAsRaster )
  {
    for ( int i = fromPage; i <= toPage; ++i )
    {
      if ( i > fromPage )
      {
        printer.newPage();
      }
      renderPage( &p, i );
    }
  }
}
Example #4
0
bool PageProvider::setDocument(const QString &filePath)
{
  qDebug() << "PageProvider::setDocument" << filePath;

  bool out = false;
  if (NULL != doc_) {
    if(true == doc_->load(filePath)) {
      cacheSize_ = qMin(static_cast<uint>(pageCache_.count()), numPages());
      currentPage_ = -1;
      filePath_ = filePath;
      out = true;
    }
    else if (!filePath_.isEmpty()) {
      //an error occured -> restore previous document
      out = (EXIT_SUCCESS == doc_->load(filePath_));
    }
  }
  return out;
}
Example #5
0
void QgsComposition::setNumPages( int pages )
{
  int currentPages = numPages();
  int diff = pages - currentPages;
  if ( diff >= 0 )
  {
    for ( int i = 0; i < diff; ++i )
    {
      addPaperItem();
    }
  }
  else
  {
    diff = -diff;
    for ( int i = 0; i < diff; ++i )
    {
      delete mPages.last();
      mPages.removeLast();
    }
  }
  emit nPagesChanged();
}
Example #6
0
void QgsComposition::doPrint( QPrinter& printer, QPainter& p )
{
//QgsComposition starts page numbering at 0
  int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1 ;
  int toPage = ( printer.toPage() < 1 ) ? numPages() - 1 : printer.toPage() - 1;

  if ( mPrintAsRaster )
  {
    for ( int i = fromPage; i <= toPage; ++i )
    {
      if ( i > fromPage )
      {
        printer.newPage();
      }

      QImage image = printPageAsRaster( i );
      if ( !image.isNull() )
      {
        QRectF targetArea( 0, 0, image.width(), image.height() );
        p.drawImage( targetArea, image, targetArea );
      }
    }
  }

  if ( !mPrintAsRaster )
  {
    for ( int i = fromPage; i <= toPage; ++i )
    {
      if ( i > fromPage )
      {
        printer.newPage();
      }
      renderPage( &p, i );
    }
  }
}