Skip to content
Permalink
Browse files

Fixes for fetching a CompositionHtml from a Composition

  • Loading branch information
timlinux committed Sep 21, 2012
1 parent b220bd4 commit 6b878341f217e03ecb35c4e2d684c420bf32d232
@@ -22,5 +22,5 @@ class QgsComposerFrame: QgsComposerItem

int type() const;

QgsComposerMultiFrame* multiFrame();
};
QgsComposerMultiFrame* multiFrame() const;
};
@@ -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:
@@ -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();
@@ -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;
@@ -36,14 +36,14 @@ def setUp(self):
"""Run before each test."""
self.mComposition = QgsComposition(None)
self.mComposition.setPaperSize(297, 210) #A4 landscape
self.htmlItem = QgsComposerHtml(self.mComposition, False)
self.mComposerHtml = 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
if self.mComposerHtml:
self.mComposition.removeMultiFrame(self.mComposerHtml)
del self.mComposerHtml

def controlImagePath(self, theImageName):
"""Helper to get the path to a control image."""
@@ -63,10 +63,10 @@ def htmlUrl(self):
def testTable(self):
"""Test we can render a html table in a single frame."""
htmlFrame = QgsComposerFrame(self.mComposition,
self.htmlItem, 0, 0, 100, 200)
self.mComposerHtml, 0, 0, 100, 200)
htmlFrame.setFrameEnabled(True)
self.htmlItem.addFrame(htmlFrame)
self.htmlItem.setUrl(self.htmlUrl())
self.mComposerHtml.addFrame(htmlFrame)
self.mComposerHtml.setUrl(self.mComposerHtmlUrl())
checker = QgsCompositionChecker()
myResult, myMessage = checker.testComposition(
"Composer html table",
@@ -77,14 +77,13 @@ def testTable(self):

def testTableMultiFrame(self):
"""Test we can render to multiframes."""
htmlFrame = QgsComposerFrame(self.mComposition, self.htmlItem,
htmlFrame = QgsComposerFrame(self.mComposition, self.mComposerHtml,
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
self.mComposerHtml.addFrame(htmlFrame)
self.mComposerHtml.setResizeMode(
QgsComposerMultiFrame.RepeatUntilFinished)
self.mComposerHtml.setUrl(self.mComposerHtmlUrl())
self.mComposerHtml.frame(0).setFrameEnabled(True)

myPage = 0
checker1 = QgsCompositionChecker()

0 comments on commit 6b87834

Please sign in to comment.
You can’t perform that action at this time.