Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:timlinux/Quantum-GIS
  • Loading branch information
timlinux committed Sep 21, 2012
2 parents 003f833 + 719db73 commit 2b1443f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 33 deletions.
4 changes: 2 additions & 2 deletions python/core/qgscomposerframe.sip
Expand Up @@ -22,5 +22,5 @@ class QgsComposerFrame: QgsComposerItem

int type() const;

QgsComposerMultiFrame* multiFrame();
};
QgsComposerMultiFrame* multiFrame() const;
};
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerframe.h
Expand Up @@ -41,7 +41,7 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem

int type() const { return ComposerFrame; }

QgsComposerMultiFrame* multiFrame() { return mMultiFrame; }
QgsComposerMultiFrame* multiFrame() const { return mMultiFrame; }


private:
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerhtml.cpp
Expand Up @@ -58,7 +58,7 @@ void QgsComposerHtml::setUrl( const QUrl& url )
qApp->processEvents();
}

if ( nFrames() < 1) return;
if ( frameCount() < 1) return;
//QSize contentsSize = mWebPage->mainFrame()->contentsSize();

QRectF contentRect = this->mFrameItems.at(0)->boundingRect();
Expand Down
26 changes: 11 additions & 15 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -203,22 +203,18 @@ const QgsComposerMap* QgsComposition::getComposerMapById( int id ) const

const QgsComposerHtml* QgsComposition::getComposerHtmlByItem( QgsComposerItem *item ) const
{
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
const QgsComposerHtml* composerHtml = dynamic_cast<const QgsComposerHtml *>( *itemIt );
if ( composerHtml )
// an html item will be a composer frame and if it is we can try to get
// its multiframe parent and then try to cast that to a composer html
const QgsComposerFrame* composerFrame =
dynamic_cast<const QgsComposerFrame *>( item );
if ( composerFrame )
{
const QgsComposerMultiFrame * mypMultiFrame = composerFrame->multiFrame();
const QgsComposerHtml* composerHtml =
dynamic_cast<const QgsComposerHtml *>( mypMultiFrame );
if (composerHtml)
{
//Now cycle through the items associated with this html composer
//and return the composer if the item matches any of them
for ( int i=0; i<composerHtml->frameCount(); i++ )
{
if ( composerHtml->frame(i)->id() == item->id() )
{
return composerHtml;
}
}
return composerHtml;
}
}
return 0;
Expand Down
43 changes: 29 additions & 14 deletions tests/src/python/test_qgscomposerhtml.py
Expand Up @@ -20,6 +20,7 @@
import os
from utilities import unitTestDataPath, getQgisTestApp
from PyQt4.QtCore import QUrl, QString, qDebug
from PyQt4.QtXml import QDomDocument
from qgis.core import (QgsComposition,
QgsComposerHtml,
QgsComposerFrame,
Expand All @@ -36,14 +37,10 @@ def setUp(self):
"""Run before each test."""
self.mComposition = QgsComposition(None)
self.mComposition.setPaperSize(297, 210) #A4 landscape
self.htmlItem = QgsComposerHtml(self.mComposition, False)

def tearDown(self):
"""Run after each test."""
print "Tear down"
if self.htmlItem:
self.mComposition.removeMultiFrame(self.htmlItem)
del self.htmlItem

def controlImagePath(self, theImageName):
"""Helper to get the path to a control image."""
Expand All @@ -62,11 +59,12 @@ def htmlUrl(self):

def testTable(self):
"""Test we can render a html table in a single frame."""
composerHtml = QgsComposerHtml(self.mComposition, False)
htmlFrame = QgsComposerFrame(self.mComposition,
self.htmlItem, 0, 0, 100, 200)
composerHtml, 0, 0, 100, 200)
htmlFrame.setFrameEnabled(True)
self.htmlItem.addFrame(htmlFrame)
self.htmlItem.setUrl(self.htmlUrl())
composerHtml.addFrame(htmlFrame)
composerHtml.setUrl(self.htmlUrl())
checker = QgsCompositionChecker()
myResult, myMessage = checker.testComposition(
"Composer html table",
Expand All @@ -77,14 +75,14 @@ def testTable(self):

def testTableMultiFrame(self):
"""Test we can render to multiframes."""
htmlFrame = QgsComposerFrame(self.mComposition, self.htmlItem,
composerHtml = QgsComposerHtml(self.mComposition, False)
htmlFrame = QgsComposerFrame(self.mComposition, composerHtml,
10, 10, 100, 50)
self.htmlItem.addFrame(htmlFrame)
self.htmlItem.setResizeMode(QgsComposerMultiFrame.RepeatUntilFinished)
self.htmlItem.setUrl(self.htmlUrl())
self.htmlItem.frame(0).setFrameEnabled(True)

result = True
composerHtml.addFrame(htmlFrame)
composerHtml.setResizeMode(
QgsComposerMultiFrame.RepeatUntilFinished)
composerHtml.setUrl(self.htmlUrl())
composerHtml.frame(0).setFrameEnabled(True)

myPage = 0
checker1 = QgsCompositionChecker()
Expand Down Expand Up @@ -119,5 +117,22 @@ def testTableMultiFrame(self):
print "Checking page 3"
assert myResult, myMessage

def testComposerHtmlAccessor(self):
"""Test that we can retrieve the ComposerHtml instance given an item.
"""
myComposition = QgsComposition(CANVAS.mapRenderer())
mySubstitutionMap = {'replace-me': 'Foo bar'}
myFile = os.path.join(TEST_DATA_DIR, 'template.qpt')
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()
myTemplateFile.close()
myDocument = QDomDocument()
myDocument.setContent(myTemplateContent)
myComposition.loadFromTemplate(myDocument, mySubstitutionMap)
myItem = myComposition.getComposerItemById('html-test')
myComposerHtml = myComposition.getComposerHtmlByItem(myItem)
myMessage = 'Could not retrieve the composer html given an item'
assert myComposerHtml is not None, myMessage

if __name__ == '__main__':
unittest.main()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2b1443f

Please sign in to comment.