mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Added functions to move composer items front/back
git-svn-id: http://svn.osgeo.org/qgis/trunk@9153 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
d64e4510f6
commit
1f1532a516
BIN
images/themes/default/mActionLowerItems.png
Normal file
BIN
images/themes/default/mActionLowerItems.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 860 B |
BIN
images/themes/default/mActionMoveItemsToBottom.png
Normal file
BIN
images/themes/default/mActionMoveItemsToBottom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 430 B |
BIN
images/themes/default/mActionMoveItemsToTop.png
Normal file
BIN
images/themes/default/mActionMoveItemsToTop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 514 B |
BIN
images/themes/default/mActionRaiseItems.png
Normal file
BIN
images/themes/default/mActionRaiseItems.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 877 B |
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define QGSCOMPOSITION_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QLinkedList>
|
||||
|
||||
class QgsComposerItem;
|
||||
class QgsComposerMap;
|
||||
@ -27,8 +28,10 @@ class QDomDocument;
|
||||
class QDomElement;
|
||||
|
||||
/** \ingroup MapComposer
|
||||
* Graphics scene for map printing. It manages the paper item which always
|
||||
* is the item in the back (z-value 0).
|
||||
* Graphics scene for map printing. The class manages the paper item which always
|
||||
* is the item in the back (z-value 0). It maintains the z-Values of the items and stores
|
||||
* them in a list in ascending z-Order. This list can be changed to lower/raise items one position
|
||||
* or to bring them to front/back.
|
||||
* */
|
||||
class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
{
|
||||
@ -89,16 +92,41 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
|
||||
/**Reads settings from xml file*/
|
||||
bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );
|
||||
|
||||
/**Adds item to z list. Usually called from constructor of QgsComposerItem*/
|
||||
void addItemToZList(QgsComposerItem* item);
|
||||
/**Removes item from z list. Usually called from destructor of QgsComposerItem*/
|
||||
void removeItemFromZList(QgsComposerItem* item);
|
||||
|
||||
void raiseSelectedItems();
|
||||
void raiseItem(QgsComposerItem* item);
|
||||
void lowerSelectedItems();
|
||||
void lowerItem(QgsComposerItem* item);
|
||||
void moveSelectedItemsToTop();
|
||||
void moveItemToTop(QgsComposerItem* item);
|
||||
void moveSelectedItemsToBottom();
|
||||
void moveItemToBottom(QgsComposerItem* item);
|
||||
|
||||
/**Sorts the zList. The only time where this function needs to be called is from QgsComposer
|
||||
after reading all the items from xml file*/
|
||||
void sortZList();
|
||||
|
||||
|
||||
private:
|
||||
/**Pointer to map renderer of QGIS main map*/
|
||||
QgsMapRenderer* mMapRenderer;
|
||||
QgsComposition::PlotStyle mPlotStyle;
|
||||
QGraphicsRectItem* mPaperItem;
|
||||
|
||||
/**Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item)*/
|
||||
QLinkedList<QgsComposerItem*> mItemZList;
|
||||
|
||||
/**Dpi for printout*/
|
||||
int mPrintoutResolution;
|
||||
|
||||
QgsComposition(); //default constructor is forbidden
|
||||
|
||||
/**Reset z-values of items based on position in z list*/
|
||||
void updateZValues();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -101,7 +101,6 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
|
||||
emit composerLabelAdded( newLabelItem );
|
||||
scene()->clearSelection();
|
||||
newLabelItem->setSceneRect( QRectF( scenePoint.x(), scenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
|
||||
newLabelItem->setZValue( 60 );
|
||||
newLabelItem->setSelected( true );
|
||||
emit selectedItemChanged( newLabelItem );
|
||||
emit actionFinished();
|
||||
@ -124,7 +123,6 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
|
||||
scene()->addItem( newScaleBar );
|
||||
emit composerScaleBarAdded( newScaleBar );
|
||||
scene()->clearSelection();
|
||||
newScaleBar->setZValue( 60 );
|
||||
newScaleBar->setSelected( true );
|
||||
emit selectedItemChanged( newScaleBar );
|
||||
emit actionFinished();
|
||||
@ -137,7 +135,6 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
|
||||
scene()->addItem( newLegend );
|
||||
emit composerLegendAdded( newLegend );
|
||||
scene()->clearSelection();
|
||||
newLegend->setZValue( 60 );
|
||||
newLegend->setSceneRect( QRectF( scenePoint.x(), scenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
|
||||
newLegend->setSelected( true );
|
||||
emit selectedItemChanged( newLegend );
|
||||
@ -150,7 +147,6 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
|
||||
scene()->addItem( newPicture );
|
||||
emit composerPictureAdded( newPicture );
|
||||
scene()->clearSelection();
|
||||
newPicture->setZValue( 60 );
|
||||
newPicture->setSceneRect( QRectF( scenePoint.x(), scenePoint.y(), 30, 30 ) );
|
||||
newPicture->setSelected( true );
|
||||
emit selectedItemChanged( newPicture );
|
||||
@ -212,8 +208,6 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
|
||||
composerMap->setPreviewMode( QgsComposerMap::Rectangle );
|
||||
|
||||
emit composerMapAdded( composerMap );
|
||||
|
||||
composerMap->setZValue( 50 );
|
||||
scene()->addItem( composerMap );
|
||||
scene()->clearSelection();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user