Skip to content

Commit 1c03067

Browse files
committedSep 29, 2014
[composer] Add a basic test suite for QgsComposerModel
1 parent 6fb7ba2 commit 1c03067

File tree

5 files changed

+626
-10
lines changed

5 files changed

+626
-10
lines changed
 

‎src/core/composer/qgscomposerlabel.cpp

100644100755
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
6161
setExpressionContext( mComposition->atlasComposition().currentFeature(), mComposition->atlasComposition().coverageLayer() );
6262
}
6363

64-
//connect to atlas feature changes
65-
//to update the expression context
66-
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );
67-
64+
if ( mComposition )
65+
{
66+
//connect to atlas feature changes
67+
//to update the expression context
68+
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );
69+
}
6870
}
6971

7072
QgsComposerLabel::~QgsComposerLabel()

‎src/core/composer/qgscomposermodel.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,11 @@ void QgsComposerModel::updateItemSelectStatus( QgsComposerItem *item )
693693

694694
bool QgsComposerModel::reorderItemUp( QgsComposerItem *item )
695695
{
696+
if ( !item )
697+
{
698+
return false;
699+
}
700+
696701
if ( mItemsInScene.first() == item )
697702
{
698703
//item is already topmost item present in scene, nothing to do
@@ -738,6 +743,11 @@ bool QgsComposerModel::reorderItemUp( QgsComposerItem *item )
738743

739744
bool QgsComposerModel::reorderItemDown( QgsComposerItem *item )
740745
{
746+
if ( !item )
747+
{
748+
return false;
749+
}
750+
741751
if ( mItemsInScene.last() == item )
742752
{
743753
//item is already lowest item present in scene, nothing to do
@@ -783,6 +793,11 @@ bool QgsComposerModel::reorderItemDown( QgsComposerItem *item )
783793

784794
bool QgsComposerModel::reorderItemToTop( QgsComposerItem *item )
785795
{
796+
if ( !item || !mItemsInScene.contains( item ) )
797+
{
798+
return false;
799+
}
800+
786801
if ( mItemsInScene.first() == item )
787802
{
788803
//item is already topmost item present in scene, nothing to do
@@ -814,6 +829,11 @@ bool QgsComposerModel::reorderItemToTop( QgsComposerItem *item )
814829

815830
bool QgsComposerModel::reorderItemToBottom( QgsComposerItem *item )
816831
{
832+
if ( !item || !mItemsInScene.contains( item ) )
833+
{
834+
return false;
835+
}
836+
817837
if ( mItemsInScene.last() == item )
818838
{
819839
//item is already lowest item present in scene, nothing to do

‎src/core/composer/qgscomposermodel.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ class CORE_EXPORT QgsComposerModel: public QAbstractItemModel
237237
*/
238238
void setSelected( const QModelIndex &index );
239239

240+
protected:
241+
242+
/**Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item)*/
243+
QList<QgsComposerItem*> mItemZList;
244+
245+
/**Cached list of items from mItemZList which are currently in the scene*/
246+
QList<QgsComposerItem*> mItemsInScene;
247+
240248
private:
241249

242250
enum Columns
@@ -249,12 +257,6 @@ class CORE_EXPORT QgsComposerModel: public QAbstractItemModel
249257
/**Parent composition*/
250258
QgsComposition* mComposition;
251259

252-
/**Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item)*/
253-
QList<QgsComposerItem*> mItemZList;
254-
255-
/**Cached list of items from mItemZList which are currently in the scene*/
256-
QList<QgsComposerItem*> mItemsInScene;
257-
258260
/**Returns the QgsComposerItem corresponding to a QModelIndex, if possible
259261
* @param index QModelIndex for item
260262
* @returns item corresponding to index
@@ -283,6 +285,8 @@ class CORE_EXPORT QgsComposerModel: public QAbstractItemModel
283285
* @see refreshItemsInScene
284286
*/
285287
void rebuildSceneItemList();
288+
289+
friend class TestQgsComposerModel;
286290
};
287291

288292
#endif //QGSCOMPOSERMODEL

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
108108
ADD_QGIS_TEST(composerobject testqgscomposerobject.cpp)
109109
ADD_QGIS_TEST(composerutils testqgscomposerutils.cpp)
110110
ADD_QGIS_TEST(compositiontest testqgscomposition.cpp)
111+
ADD_QGIS_TEST(composermodel testqgscomposermodel.cpp)
111112
ADD_QGIS_TEST(composermultiframetest testqgscomposermultiframe.cpp)
112113
ADD_QGIS_TEST(composerpapertest testqgscomposerpaper.cpp)
113114
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)

‎tests/src/core/testqgscomposermodel.cpp

Lines changed: 589 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.