API change in the Generator: use an empty construct, and set the document for the generator right after its construction.

Add a protected method to get the document, and hide the real document pointer as private, so the generators can't redefine it.

svn path=/trunk/playground/graphics/okular/; revision=598025
remotes/origin/KDE/4.0
Pino Toscano 20 years ago
parent 0381a0410e
commit 18028a8a2c
  1. 7
      core/document.cpp
  2. 10
      core/generator.cpp
  3. 12
      core/generator.h
  4. 3
      generators/chm/generator_chm.cpp
  5. 2
      generators/chm/generator_chm.h
  6. 2
      generators/djvu/generator_djvu.cpp
  7. 2
      generators/djvu/generator_djvu.h
  8. 4
      generators/dvi/generator_dvi.cpp
  9. 2
      generators/dvi/generator_dvi.h
  10. 6
      generators/ghostview/generator_ghostview.cpp
  11. 4
      generators/ghostview/generator_ghostview.h
  12. 4
      generators/kimgio/generator_kimgio.cpp
  13. 2
      generators/kimgio/generator_kimgio.h
  14. 4
      generators/ooo/generator_ooo.cpp
  15. 2
      generators/ooo/generator_ooo.h
  16. 8
      generators/poppler/generator_pdf.cpp
  17. 2
      generators/poppler/generator_pdf.h
  18. 2
      generators/tiff/generator_tiff.cpp
  19. 2
      generators/tiff/generator_tiff.h
  20. 4
      generators/xps/generator_xps.cpp
  21. 2
      generators/xps/generator_xps.h

@ -215,8 +215,8 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi
return false;
}
Generator* (*create_plugin)(Document* doc) = ( Generator* (*)(Document* doc) ) lib->symbol( "create_plugin" );
generator=create_plugin(this);
Generator* (*create_plugin)() = ( Generator* (*)() ) lib->symbol( "create_plugin" );
generator = create_plugin();
if ( !generator )
{
@ -232,9 +232,10 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi
}
else
{
generator -> setDocument( this );
m_usingCachedGenerator=true;
}
generator->setDocument( this );
// connect error reporting signals
connect( generator, SIGNAL( error( const QString&, int ) ), this, SIGNAL( error( const QString&, int ) ) );
connect( generator, SIGNAL( warning( const QString&, int ) ), this, SIGNAL( warning( const QString&, int ) ) );

@ -13,8 +13,8 @@
using namespace Okular;
Generator::Generator( Document *document )
: m_document( document )
Generator::Generator()
: m_document( 0 )
{
}
@ -177,6 +177,12 @@ void Generator::signalRequestDone( PixmapRequest * request )
m_document->requestDone( request );
}
Document * Generator::document() const
{
return m_document;
}
QTextStream& operator<< (QTextStream& str, const PixmapRequest *req)
{
QString s;

@ -15,7 +15,7 @@
#define OKULAR_EXPORT_PLUGIN( classname ) \
extern "C" { \
OKULAR_EXPORT Okular::Generator* create_plugin(Okular::Document* doc) { return new classname(doc); } \
OKULAR_EXPORT Okular::Generator* create_plugin() { return new classname(); } \
}
@ -65,9 +65,9 @@ class OKULAR_EXPORT Generator : public QObject
public:
/**
* Creates a new generator which works on the given @p document
* Creates a new generator.
*/
Generator( Document *document );
Generator();
/**
@ -315,6 +315,12 @@ class OKULAR_EXPORT Generator : public QObject
*/
void signalRequestDone( PixmapRequest * request );
/**
* Returns a pointer to the document.
*/
Document * document() const;
private:
/**
* The internal pointer to the document.
*/

@ -28,7 +28,8 @@
OKULAR_EXPORT_PLUGIN(CHMGenerator)
CHMGenerator::CHMGenerator( Okular::Document * doc ) : Okular::Generator ( doc )
CHMGenerator::CHMGenerator()
: Okular::Generator()
{
m_syncGen=0;
m_file=0;

@ -29,7 +29,7 @@ class CHMGenerator : public Okular::Generator
{
Q_OBJECT
public:
CHMGenerator(Okular::Document * doc );
CHMGenerator();
bool loadDocument( const QString & fileName, QVector< Okular::Page * > & pagesVector );
bool closeDocument();

@ -52,7 +52,7 @@ static void recurseCreateTOC( QDomDocument &maindoc, QDomNode &parent, QDomNode
OKULAR_EXPORT_PLUGIN(DjVuGenerator)
DjVuGenerator::DjVuGenerator( Okular::Document * doc ) : Okular::Generator ( doc ),
DjVuGenerator::DjVuGenerator() : Okular::Generator(),
m_docInfo( 0 ), m_docSyn( 0 ), ready( false )
{
m_djvu = new KDjVu();

@ -19,7 +19,7 @@ class DjVuGenerator : public Okular::Generator
{
Q_OBJECT
public:
DjVuGenerator( Okular::Document * doc );
DjVuGenerator();
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
bool closeDocument();

@ -29,7 +29,7 @@
OKULAR_EXPORT_PLUGIN(DviGenerator)
DviGenerator::DviGenerator( Okular::Document * doc ) : Okular::Generator ( doc ),
DviGenerator::DviGenerator() : Okular::Generator(),
m_docInfo( 0 ), m_docSynopsis( 0 ), ready( false ), m_dviRenderer( 0 )
{
}
@ -356,7 +356,7 @@ const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
{
Okular::DocumentViewport vp;
const Okular::Page *p = m_document->page( a.page - 1 );
const Okular::Page *p = document()->page( a.page - 1 );
/* Don't care about rotations... */
fillViewportFromAnchor( vp, a, (int)p->width(), (int)p->height(), 0 );
domel->setAttribute( "Viewport", vp.toString() );

@ -24,7 +24,7 @@ class DviGenerator : public Okular::Generator
{
Q_OBJECT
public:
DviGenerator( Okular::Document * doc );
DviGenerator();
bool loadDocument( const QString & fileName, QVector< Okular::Page * > & pagesVector );
bool closeDocument();

@ -37,8 +37,8 @@
OKULAR_EXPORT_PLUGIN(GSGenerator)
GSGenerator::GSGenerator( Okular::Document * doc ) :
Okular::Generator ( doc ),
GSGenerator::GSGenerator() :
Okular::Generator(),
m_converted(false)
{
pixGenerator = 0;
@ -267,7 +267,7 @@ void GSGenerator::setPaperSize( QVector<Okular::Page*> & pagesVector, int newsiz
loadPages(pagesVector);
// FIXME: is it needed to notify the observers? doesn't the document do that already?
Okular::NotifyRequest r(Okular::DocumentObserver::Setup, false);
m_document->notifyObservers( &r );
document()->notifyObservers( &r );
}
void GSGenerator::setupGUI(KActionCollection * ac , QToolBox * tBox )

@ -53,8 +53,8 @@ class GSGenerator : public Okular::Generator
QString fileName();
void addPages( KConfigDialog* dlg );
/** constructor: takes the Document as a parameter **/
GSGenerator( Okular::Document * doc );
/** constructor **/
GSGenerator();
~GSGenerator();
public slots:

@ -18,7 +18,7 @@
OKULAR_EXPORT_PLUGIN(KIMGIOGenerator)
KIMGIOGenerator::KIMGIOGenerator( Okular::Document * document ) : Generator( document )
KIMGIOGenerator::KIMGIOGenerator() : Generator()
{
}
@ -56,7 +56,7 @@ void KIMGIOGenerator::generatePixmap( Okular::PixmapRequest * request )
// perform a smooth scaled generation
QImage smoothImage = m_pix->toImage().scaled( request->width, request->height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
// rotate, if necessary
int rotation = m_document->rotation();
int rotation = request->page->rotation();
QImage finalImage = rotation > 0
? KImageEffect::rotate( smoothImage, (KImageEffect::RotateDirection)( rotation - 1 ) )
: smoothImage;

@ -16,7 +16,7 @@ class KIMGIOGenerator : public Okular::Generator
{
Q_OBJECT
public:
KIMGIOGenerator( Okular::Document * document );
KIMGIOGenerator();
virtual ~KIMGIOGenerator();
// [INHERITED] load a document and fill up the pagesVector

@ -25,8 +25,8 @@
OKULAR_EXPORT_PLUGIN(KOOOGenerator)
KOOOGenerator::KOOOGenerator( Okular::Document * document )
: Okular::Generator( document ), mDocument( 0 )
KOOOGenerator::KOOOGenerator()
: Okular::Generator(), mDocument( 0 )
{
}

@ -20,7 +20,7 @@ class KOOOGenerator : public Okular::Generator
Q_OBJECT
public:
KOOOGenerator( Okular::Document * document );
KOOOGenerator();
virtual ~KOOOGenerator();
// [INHERITED] load a document and fill up the pagesVector

@ -218,8 +218,8 @@ static QLinkedList<Okular::ObjectRect*> generateLinks( const QList<Poppler::Link
OKULAR_EXPORT_PLUGIN(PDFGenerator)
PDFGenerator::PDFGenerator( Okular::Document * doc )
: Generator( doc ), pdfdoc( 0 ), ready( true ),
PDFGenerator::PDFGenerator()
: Generator(), pdfdoc( 0 ), ready( true ),
pixmapRequest( 0 ), docInfoDirty( true ), docSynopsisDirty( true ),
docFontsDirty( true ), docEmbeddedFilesDirty( true )
{
@ -647,7 +647,7 @@ void PDFGenerator::generatePixmap( Okular::PixmapRequest * request )
Poppler::Page *p = pdfdoc->page(page->number());
// 2. Take data from outputdev and attach it to the Page
page->setPixmap( request->id, p->splashRenderToPixmap(fakeDpiX, fakeDpiY, -1, -1, -1, -1, genObjectRects, (Poppler::Page::Rotation)m_document->rotation()) );
page->setPixmap( request->id, p->splashRenderToPixmap(fakeDpiX, fakeDpiY, -1, -1, -1, -1, genObjectRects, (Poppler::Page::Rotation)document()->rotation()) );
if ( genObjectRects )
{
@ -801,7 +801,7 @@ bool PDFGenerator::exportToText( const QString & fileName )
return false;
QTextStream ts( &f );
int num = m_document->pages();
int num = document()->pages();
for ( int i = 0; i < num; ++i )
{
docLock.lock();

@ -48,7 +48,7 @@ class PDFGenerator : public Okular::Generator
{
Q_OBJECT
public:
PDFGenerator( Okular::Document * document );
PDFGenerator();
virtual ~PDFGenerator();
// [INHERITED] load a document and fill up the pagesVector

@ -140,7 +140,7 @@ static QDateTime convertTIFFDateTime( const char* tiffdate )
OKULAR_EXPORT_PLUGIN(TIFFGenerator)
TIFFGenerator::TIFFGenerator( Okular::Document * document ) : Okular::Generator( document ),
TIFFGenerator::TIFFGenerator() : Okular::Generator(),
d( new Private ), ready( false ), m_docInfo( 0 )
{
thread = new TIFFGeneratorThread();

@ -18,7 +18,7 @@ class TIFFGenerator : public Okular::Generator
{
Q_OBJECT
public:
TIFFGenerator( Okular::Document * document );
TIFFGenerator();
virtual ~TIFFGenerator();
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );

@ -607,8 +607,8 @@ XpsPage* XpsFile::page(int pageNum) const
return m_pages.at( pageNum );
}
XpsGenerator::XpsGenerator( Okular::Document * document )
: Okular::Generator( document )
XpsGenerator::XpsGenerator()
: Okular::Generator()
{
m_xpsFile = new XpsFile;
}

@ -202,7 +202,7 @@ class XpsGenerator : public Okular::Generator
{
Q_OBJECT
public:
XpsGenerator( Okular::Document * document );
XpsGenerator();
virtual ~XpsGenerator();
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );

Loading…
Cancel
Save