Skip to content
Permalink
Browse files

Support deletion of guides through manager

  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent 6138b97 commit 9458f1f9346866f82a0f2090a9cfe3f54f3087cc
@@ -166,6 +166,8 @@ class QgsLayoutGuideCollection : QAbstractTableModel

virtual QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const;
virtual bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );


void addGuide( QgsLayoutGuide *guide /Transfer/ );
%Docstring
@@ -235,7 +235,7 @@ bool QgsLayoutGuideCollection::setData( const QModelIndex &index, const QVariant

QgsLayoutMeasurement m = guide->position();
m.setLength( newPos );
guide->setPosition( m );
whileBlocking( guide )->setPosition( m );
guide->update();
return true;
}
@@ -248,7 +248,7 @@ bool QgsLayoutGuideCollection::setData( const QModelIndex &index, const QVariant

QgsLayoutMeasurement m = guide->position();
m.setLength( newPos );
guide->setPosition( m );
whileBlocking( guide )->setPosition( m );
guide->update();
return true;
}
@@ -261,7 +261,7 @@ bool QgsLayoutGuideCollection::setData( const QModelIndex &index, const QVariant

QgsLayoutMeasurement m = guide->position();
m.setUnits( static_cast< QgsUnitTypes::LayoutUnit >( units ) );
guide->setPosition( m );
whileBlocking( guide )->setPosition( m );
guide->update();
return true;
}
@@ -288,6 +288,20 @@ QVariant QgsLayoutGuideCollection::headerData( int section, Qt::Orientation orie
return QAbstractTableModel::headerData( section, orientation, role );
}

bool QgsLayoutGuideCollection::removeRows( int row, int count, const QModelIndex &parent )
{
if ( parent.isValid() )
return false;

beginRemoveRows( parent, row, row + count - 1 );
for ( int i = 0; i < count; ++ i )
{
delete mGuides.takeAt( row );
}
endRemoveRows();
return true;
}

void QgsLayoutGuideCollection::addGuide( QgsLayoutGuide *guide )
{
guide->setLayout( mLayout );
@@ -191,6 +191,7 @@ class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel
Qt::ItemFlags flags( const QModelIndex &index ) const override;
QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const override;
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;

/**
* Adds a \a guide to the collection. Ownership of the guide is transferred to the
@@ -115,6 +115,8 @@ void QgsLayoutItemPage::attemptResize( const QgsLayoutSize &size )
QgsLayoutItem::attemptResize( size );
//update size of attached grid to reflect new page size and position
mGrid->setRect( 0, 0, rect().width(), rect().height() );

mLayout->guides().update();
}

void QgsLayoutItemPage::redraw()
@@ -151,6 +151,27 @@ def testCollection(self):
self.assertEqual(guides.guides(QgsLayoutGuide.Horizontal), [g1, g2])
self.assertEqual(guides.guides(QgsLayoutGuide.Vertical), [g3])

def testDeleteRows(self):
p = QgsProject()
l = QgsLayout(p)
l.initializeDefaults()
guides = l.guides()

g1 = QgsLayoutGuide(QgsLayoutGuide.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters))
guides.addGuide(g1)
g2 = QgsLayoutGuide(QgsLayoutGuide.Horizontal, QgsLayoutMeasurement(15))
guides.addGuide(g2)
g3 = QgsLayoutGuide(QgsLayoutGuide.Vertical, QgsLayoutMeasurement(35))
guides.addGuide(g3)

self.assertTrue(guides.removeRows(1, 1))
self.assertEqual(guides.guides(QgsLayoutGuide.Horizontal), [g1])
self.assertEqual(guides.guides(QgsLayoutGuide.Vertical), [g3])

self.assertTrue(guides.removeRows(0, 2))
self.assertEqual(guides.guides(QgsLayoutGuide.Horizontal), [])
self.assertEqual(guides.guides(QgsLayoutGuide.Vertical), [])

def testQgsLayoutGuideProxyModel(self):
p = QgsProject()
l = QgsLayout(p)

0 comments on commit 9458f1f

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