mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Nicer table view for guide editing
This commit is contained in:
parent
886a1208ef
commit
048a5b79b6
@ -127,7 +127,7 @@ class QgsLayoutGuide : QObject
|
||||
|
||||
};
|
||||
|
||||
class QgsLayoutGuideCollection : QAbstractListModel
|
||||
class QgsLayoutGuideCollection : QAbstractTableModel
|
||||
{
|
||||
%Docstring
|
||||
Stores and manages the snap guides used by a layout.
|
||||
@ -156,6 +156,8 @@ class QgsLayoutGuideCollection : QAbstractListModel
|
||||
|
||||
virtual int rowCount( const QModelIndex & ) const;
|
||||
|
||||
virtual int columnCount( const QModelIndex & ) const;
|
||||
|
||||
virtual QVariant data( const QModelIndex &index, int role ) const;
|
||||
|
||||
virtual bool setData( const QModelIndex &index, const QVariant &value, int role );
|
||||
|
@ -149,7 +149,7 @@ QgsLayoutGuide::Orientation QgsLayoutGuide::orientation() const
|
||||
//
|
||||
|
||||
QgsLayoutGuideCollection::QgsLayoutGuideCollection( QgsLayout *layout )
|
||||
: QAbstractListModel( layout )
|
||||
: QAbstractTableModel( layout )
|
||||
, mLayout( layout )
|
||||
{
|
||||
|
||||
@ -165,6 +165,14 @@ int QgsLayoutGuideCollection::rowCount( const QModelIndex & ) const
|
||||
return mGuides.count();
|
||||
}
|
||||
|
||||
int QgsLayoutGuideCollection::columnCount( const QModelIndex &parent ) const
|
||||
{
|
||||
if ( parent.isValid() )
|
||||
return 0;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant QgsLayoutGuideCollection::data( const QModelIndex &index, int role ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
@ -179,12 +187,12 @@ QVariant QgsLayoutGuideCollection::data( const QModelIndex &index, int role ) co
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
{
|
||||
return guide->position().length();
|
||||
if ( index.column() == 0 )
|
||||
return guide->position().length();
|
||||
else
|
||||
return QgsUnitTypes::toAbbreviatedString( guide->position().units() );
|
||||
}
|
||||
|
||||
case Qt::TextAlignmentRole:
|
||||
return QVariant( Qt::AlignRight | Qt::AlignVCenter );
|
||||
|
||||
case OrientationRole:
|
||||
return guide->orientation();
|
||||
|
||||
@ -215,19 +223,49 @@ bool QgsLayoutGuideCollection::setData( const QModelIndex &index, const QVariant
|
||||
|
||||
QgsLayoutGuide *guide = mGuides.at( index.row() );
|
||||
|
||||
if ( role == Qt::EditRole )
|
||||
switch ( role )
|
||||
{
|
||||
bool ok = false;
|
||||
double newPos = value.toDouble( &ok );
|
||||
if ( !ok )
|
||||
return false;
|
||||
case Qt::EditRole:
|
||||
{
|
||||
bool ok = false;
|
||||
double newPos = value.toDouble( &ok );
|
||||
if ( !ok )
|
||||
return false;
|
||||
|
||||
QgsLayoutMeasurement m = guide->position();
|
||||
m.setLength( newPos );
|
||||
guide->setPosition( m );
|
||||
guide->update();
|
||||
return true;
|
||||
QgsLayoutMeasurement m = guide->position();
|
||||
m.setLength( newPos );
|
||||
guide->setPosition( m );
|
||||
guide->update();
|
||||
return true;
|
||||
}
|
||||
case PositionRole:
|
||||
{
|
||||
bool ok = false;
|
||||
double newPos = value.toDouble( &ok );
|
||||
if ( !ok )
|
||||
return false;
|
||||
|
||||
QgsLayoutMeasurement m = guide->position();
|
||||
m.setLength( newPos );
|
||||
guide->setPosition( m );
|
||||
guide->update();
|
||||
return true;
|
||||
}
|
||||
case UnitsRole:
|
||||
{
|
||||
bool ok = false;
|
||||
int units = value.toInt( &ok );
|
||||
if ( !ok )
|
||||
return false;
|
||||
|
||||
QgsLayoutMeasurement m = guide->position();
|
||||
m.setUnits( static_cast< QgsUnitTypes::LayoutUnit >( units ) );
|
||||
guide->setPosition( m );
|
||||
guide->update();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ class CORE_EXPORT QgsLayoutGuide : public QObject
|
||||
* \brief Stores and manages the snap guides used by a layout.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractListModel
|
||||
class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
@ -185,6 +185,7 @@ class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractListModel
|
||||
~QgsLayoutGuideCollection();
|
||||
|
||||
int rowCount( const QModelIndex & ) const override;
|
||||
int columnCount( const QModelIndex & ) const override;
|
||||
QVariant data( const QModelIndex &index, int role ) const override;
|
||||
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
|
||||
Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user