Skip to content

Commit 2b1443f

Browse files
committed
Merge branch 'master' of github.com:timlinux/Quantum-GIS
2 parents 003f833 + 719db73 commit 2b1443f

File tree

6 files changed

+44
-33
lines changed

6 files changed

+44
-33
lines changed

python/core/qgscomposerframe.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ class QgsComposerFrame: QgsComposerItem
2222

2323
int type() const;
2424

25-
QgsComposerMultiFrame* multiFrame();
26-
};
25+
QgsComposerMultiFrame* multiFrame() const;
26+
};

src/core/composer/qgscomposerframe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
4141

4242
int type() const { return ComposerFrame; }
4343

44-
QgsComposerMultiFrame* multiFrame() { return mMultiFrame; }
44+
QgsComposerMultiFrame* multiFrame() const { return mMultiFrame; }
4545

4646

4747
private:

src/core/composer/qgscomposerhtml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void QgsComposerHtml::setUrl( const QUrl& url )
5858
qApp->processEvents();
5959
}
6060

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

6464
QRectF contentRect = this->mFrameItems.at(0)->boundingRect();

src/core/composer/qgscomposition.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,22 +203,18 @@ const QgsComposerMap* QgsComposition::getComposerMapById( int id ) const
203203

204204
const QgsComposerHtml* QgsComposition::getComposerHtmlByItem( QgsComposerItem *item ) const
205205
{
206-
QList<QGraphicsItem *> itemList = items();
207-
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
208-
for ( ; itemIt != itemList.end(); ++itemIt )
209-
{
210-
const QgsComposerHtml* composerHtml = dynamic_cast<const QgsComposerHtml *>( *itemIt );
211-
if ( composerHtml )
206+
// an html item will be a composer frame and if it is we can try to get
207+
// its multiframe parent and then try to cast that to a composer html
208+
const QgsComposerFrame* composerFrame =
209+
dynamic_cast<const QgsComposerFrame *>( item );
210+
if ( composerFrame )
211+
{
212+
const QgsComposerMultiFrame * mypMultiFrame = composerFrame->multiFrame();
213+
const QgsComposerHtml* composerHtml =
214+
dynamic_cast<const QgsComposerHtml *>( mypMultiFrame );
215+
if (composerHtml)
212216
{
213-
//Now cycle through the items associated with this html composer
214-
//and return the composer if the item matches any of them
215-
for ( int i=0; i<composerHtml->frameCount(); i++ )
216-
{
217-
if ( composerHtml->frame(i)->id() == item->id() )
218-
{
219-
return composerHtml;
220-
}
221-
}
217+
return composerHtml;
222218
}
223219
}
224220
return 0;

tests/src/python/test_qgscomposerhtml.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import os
2121
from utilities import unitTestDataPath, getQgisTestApp
2222
from PyQt4.QtCore import QUrl, QString, qDebug
23+
from PyQt4.QtXml import QDomDocument
2324
from qgis.core import (QgsComposition,
2425
QgsComposerHtml,
2526
QgsComposerFrame,
@@ -36,14 +37,10 @@ def setUp(self):
3637
"""Run before each test."""
3738
self.mComposition = QgsComposition(None)
3839
self.mComposition.setPaperSize(297, 210) #A4 landscape
39-
self.htmlItem = QgsComposerHtml(self.mComposition, False)
4040

4141
def tearDown(self):
4242
"""Run after each test."""
4343
print "Tear down"
44-
if self.htmlItem:
45-
self.mComposition.removeMultiFrame(self.htmlItem)
46-
del self.htmlItem
4744

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

6360
def testTable(self):
6461
"""Test we can render a html table in a single frame."""
62+
composerHtml = QgsComposerHtml(self.mComposition, False)
6563
htmlFrame = QgsComposerFrame(self.mComposition,
66-
self.htmlItem, 0, 0, 100, 200)
64+
composerHtml, 0, 0, 100, 200)
6765
htmlFrame.setFrameEnabled(True)
68-
self.htmlItem.addFrame(htmlFrame)
69-
self.htmlItem.setUrl(self.htmlUrl())
66+
composerHtml.addFrame(htmlFrame)
67+
composerHtml.setUrl(self.htmlUrl())
7068
checker = QgsCompositionChecker()
7169
myResult, myMessage = checker.testComposition(
7270
"Composer html table",
@@ -77,14 +75,14 @@ def testTable(self):
7775

7876
def testTableMultiFrame(self):
7977
"""Test we can render to multiframes."""
80-
htmlFrame = QgsComposerFrame(self.mComposition, self.htmlItem,
78+
composerHtml = QgsComposerHtml(self.mComposition, False)
79+
htmlFrame = QgsComposerFrame(self.mComposition, composerHtml,
8180
10, 10, 100, 50)
82-
self.htmlItem.addFrame(htmlFrame)
83-
self.htmlItem.setResizeMode(QgsComposerMultiFrame.RepeatUntilFinished)
84-
self.htmlItem.setUrl(self.htmlUrl())
85-
self.htmlItem.frame(0).setFrameEnabled(True)
86-
87-
result = True
81+
composerHtml.addFrame(htmlFrame)
82+
composerHtml.setResizeMode(
83+
QgsComposerMultiFrame.RepeatUntilFinished)
84+
composerHtml.setUrl(self.htmlUrl())
85+
composerHtml.frame(0).setFrameEnabled(True)
8886

8987
myPage = 0
9088
checker1 = QgsCompositionChecker()
@@ -119,5 +117,22 @@ def testTableMultiFrame(self):
119117
print "Checking page 3"
120118
assert myResult, myMessage
121119

120+
def testComposerHtmlAccessor(self):
121+
"""Test that we can retrieve the ComposerHtml instance given an item.
122+
"""
123+
myComposition = QgsComposition(CANVAS.mapRenderer())
124+
mySubstitutionMap = {'replace-me': 'Foo bar'}
125+
myFile = os.path.join(TEST_DATA_DIR, 'template.qpt')
126+
myTemplateFile = file(myFile, 'rt')
127+
myTemplateContent = myTemplateFile.read()
128+
myTemplateFile.close()
129+
myDocument = QDomDocument()
130+
myDocument.setContent(myTemplateContent)
131+
myComposition.loadFromTemplate(myDocument, mySubstitutionMap)
132+
myItem = myComposition.getComposerItemById('html-test')
133+
myComposerHtml = myComposition.getComposerHtmlByItem(myItem)
134+
myMessage = 'Could not retrieve the composer html given an item'
135+
assert myComposerHtml is not None, myMessage
136+
122137
if __name__ == '__main__':
123138
unittest.main()
Loading

0 commit comments

Comments
 (0)