Skip to content
Permalink
Browse files
Added functions to move composer items front/back
git-svn-id: http://svn.osgeo.org/qgis/trunk@9153 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 24, 2008
1 parent d64e451 commit 1f1532a516635e4a6bd67e3e2048a4df072714c5
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -76,6 +76,10 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()

toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionGroupItems.png" ) ), tr( "&Group Items" ), this, SLOT( groupItems() ) );
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionUngroupItems.png" ) ), tr( "&Ungroup Items" ), this, SLOT( ungroupItems() ) );
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionRaiseItems.png")), tr("Raise selected items"), this, SLOT(raiseSelectedItems()));
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionLowerItems.png")), tr("Lower selected items"), this, SLOT(lowerSelectedItems()));
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionMoveItemsToTop.png")), tr("Move selected items to top"), this, SLOT(moveSelectedItemsToTop()));
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionMoveItemsToBottom.png")), tr("Move selected items to bottom"), this, SLOT(moveSelectedItemsToBottom()));

QActionGroup* toggleActionGroup = new QActionGroup( this );
toggleActionGroup->addAction( moveItemContentAction );
@@ -1028,6 +1032,38 @@ void QgsComposer::ungroupItems( void )
}
}

void QgsComposer::raiseSelectedItems()
{
if(mComposition)
{
mComposition->raiseSelectedItems();
}
}

void QgsComposer::lowerSelectedItems()
{
if(mComposition)
{
mComposition->lowerSelectedItems();
}
}

void QgsComposer::moveSelectedItemsToTop()
{
if(mComposition)
{
mComposition->moveSelectedItemsToTop();
}
}

void QgsComposer::moveSelectedItemsToBottom()
{
if(mComposition)
{
mComposition->moveSelectedItemsToBottom();
}
}

void QgsComposer::moveEvent( QMoveEvent *e ) { saveWindowState(); }

void QgsComposer::resizeEvent( QResizeEvent *e )
@@ -1305,6 +1341,7 @@ void QgsComposer::readXML( const QDomDocument& doc )
mComposition->update();
}

mComposition->sortZList();
mView->setComposition( mComposition );
}

@@ -147,6 +147,18 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Ungroup selected item group
void ungroupItems( void );

//! Move selected items one position up
void raiseSelectedItems();

//!Move selected items one position down
void lowerSelectedItems();

//!Move selected items to top
void moveSelectedItemsToTop();

//!Move selected items to bottom
void moveSelectedItemsToBottom();

//! read project
void projectRead();

@@ -37,6 +37,12 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition ): QGraphicsRectIt
QPen defaultPen( QColor( 0, 0, 0 ) );
defaultPen.setWidth( 1 );
setPen( defaultPen );

//let z-Value be managed by composition
if(mComposition)
{
mComposition->addItemToZList(this);
}
}

QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QGraphicsRectItem( 0, 0, width, height, 0 ), mComposition( composition ), mBoundingResizeRectangle( 0 ), mFrame( true )
@@ -53,10 +59,20 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
QPen defaultPen( QColor( 0, 0, 0 ) );
defaultPen.setWidth( 1 );
setPen( defaultPen );

//let z-Value be managed by composition
if(mComposition)
{
mComposition->addItemToZList(this);
}
}

QgsComposerItem::~QgsComposerItem()
{
if(mComposition)
{
mComposition->removeItemFromZList(this);
}
}

void QgsComposerItem::setSelected( bool s )
@@ -63,12 +63,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
mExtent = mMapRenderer->extent();
}
setSceneRect( QRectF( x, y, width, height ) );

QGraphicsRectItem::setZValue( 20 );

setToolTip( tr( "Map" ) + " " + QString::number( mId ) );

QGraphicsRectItem::show();
}

QgsComposerMap::QgsComposerMap( QgsComposition *composition )
@@ -189,3 +189,215 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu

return true;
}

void QgsComposition::addItemToZList(QgsComposerItem* item)
{
if(!item)
{
return;
}
mItemZList.push_back(item);
qWarning(QString::number(mItemZList.size()).toLocal8Bit().data());
item->setZValue(mItemZList.size());
}

void QgsComposition::removeItemFromZList(QgsComposerItem* item)
{
if(!item)
{
return;
}
mItemZList.removeAll(item);
}

void QgsComposition::raiseSelectedItems()
{
QList<QgsComposerItem*> selectedItems = selectedComposerItems();
QList<QgsComposerItem*>::iterator it = selectedItems.begin();
for(; it != selectedItems.end(); ++it)
{
raiseItem(*it);
}

//update all positions
updateZValues();
update();
}

void QgsComposition::raiseItem(QgsComposerItem* item)
{
//search item
QMutableLinkedListIterator<QgsComposerItem*> it(mItemZList);
if(it.findNext(item))
{
if(it.hasNext())
{
it.remove();
it.next();
it.insert(item);
}
}
}

void QgsComposition::lowerSelectedItems()
{
QList<QgsComposerItem*> selectedItems = selectedComposerItems();
QList<QgsComposerItem*>::iterator it = selectedItems.begin();
for(; it != selectedItems.end(); ++it)
{
lowerItem(*it);
}

//update all positions
updateZValues();
update();
}

void QgsComposition::lowerItem(QgsComposerItem* item)
{
//search item
QMutableLinkedListIterator<QgsComposerItem*> it(mItemZList);
if(it.findNext(item))
{
it.previous();
if(it.hasPrevious())
{
it.remove();
it.previous();
it.insert(item);
}
}
}

void QgsComposition::moveSelectedItemsToTop()
{
QList<QgsComposerItem*> selectedItems = selectedComposerItems();
QList<QgsComposerItem*>::iterator it = selectedItems.begin();
for(; it != selectedItems.end(); ++it)
{
moveItemToTop(*it);
}

//update all positions
updateZValues();
update();
}

void QgsComposition::moveItemToTop(QgsComposerItem* item)
{
//search item
QMutableLinkedListIterator<QgsComposerItem*> it(mItemZList);
if(it.findNext(item))
{
it.remove();
}
mItemZList.push_back(item);
}

void QgsComposition::moveSelectedItemsToBottom()
{
QList<QgsComposerItem*> selectedItems = selectedComposerItems();
QList<QgsComposerItem*>::iterator it = selectedItems.begin();
for(; it != selectedItems.end(); ++it)
{
moveItemToBottom(*it);
}

//update all positions
updateZValues();
update();
}

void QgsComposition::moveItemToBottom(QgsComposerItem* item)
{
//search item
QMutableLinkedListIterator<QgsComposerItem*> it(mItemZList);
if(it.findNext(item))
{
it.remove();
}
mItemZList.push_front(item);
}

void QgsComposition::updateZValues()
{
int counter = 1;
QLinkedList<QgsComposerItem*>::iterator it = mItemZList.begin();
QgsComposerItem* currentItem = 0;

for(; it != mItemZList.end(); ++it)
{
currentItem = *it;
if(currentItem)
{
qWarning(QString::number(counter).toLocal8Bit().data());
currentItem->setZValue(counter);
}
++counter;
}
}

void QgsComposition::sortZList()
{
//debug: list before sorting
qWarning("before sorting");
QLinkedList<QgsComposerItem*>::iterator before_it = mItemZList.begin();
for(; before_it != mItemZList.end(); ++before_it)
{
qWarning(QString::number((*before_it)->zValue()).toLocal8Bit().data());
}

QMutableLinkedListIterator<QgsComposerItem*> it(mItemZList);
int previousZ, afterZ; //z values of items before and after
QgsComposerItem* previousItem;
QgsComposerItem* afterItem;

while(it.hasNext())
{
previousItem = it.next();
if(previousItem)
{
previousZ = previousItem->zValue();
}
else
{
previousZ = -1;
}

if(!it.hasNext())
{
break; //this is the end...
}
afterItem = it.peekNext();

if(afterItem)
{
afterZ = afterItem->zValue();
}
else
{
afterZ = -1;
}

if(previousZ > afterZ)
{
//swap items
if(previousItem && afterItem)
{
it.remove();
it.next();
it.insert(previousItem);
it.previous();
}
}
}

//debug: list after sorting
//debug: list before sorting
qWarning("after sorting");
QLinkedList<QgsComposerItem*>::iterator after_it = mItemZList.begin();
for(; after_it != mItemZList.end(); ++after_it)
{
qWarning(QString::number((*after_it)->zValue()).toLocal8Bit().data());
}
}

0 comments on commit 1f1532a

Please sign in to comment.