mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -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
|
%Docstring
|
||||||
Stores and manages the snap guides used by a layout.
|
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 rowCount( const QModelIndex & ) const;
|
||||||
|
|
||||||
|
virtual int columnCount( const QModelIndex & ) const;
|
||||||
|
|
||||||
virtual QVariant data( const QModelIndex &index, int role ) const;
|
virtual QVariant data( const QModelIndex &index, int role ) const;
|
||||||
|
|
||||||
virtual bool setData( const QModelIndex &index, const QVariant &value, int role );
|
virtual bool setData( const QModelIndex &index, const QVariant &value, int role );
|
||||||
|
@ -149,7 +149,7 @@ QgsLayoutGuide::Orientation QgsLayoutGuide::orientation() const
|
|||||||
//
|
//
|
||||||
|
|
||||||
QgsLayoutGuideCollection::QgsLayoutGuideCollection( QgsLayout *layout )
|
QgsLayoutGuideCollection::QgsLayoutGuideCollection( QgsLayout *layout )
|
||||||
: QAbstractListModel( layout )
|
: QAbstractTableModel( layout )
|
||||||
, mLayout( layout )
|
, mLayout( layout )
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -165,6 +165,14 @@ int QgsLayoutGuideCollection::rowCount( const QModelIndex & ) const
|
|||||||
return mGuides.count();
|
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
|
QVariant QgsLayoutGuideCollection::data( const QModelIndex &index, int role ) const
|
||||||
{
|
{
|
||||||
if ( !index.isValid() )
|
if ( !index.isValid() )
|
||||||
@ -179,12 +187,12 @@ QVariant QgsLayoutGuideCollection::data( const QModelIndex &index, int role ) co
|
|||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
case Qt::EditRole:
|
case Qt::EditRole:
|
||||||
{
|
{
|
||||||
|
if ( index.column() == 0 )
|
||||||
return guide->position().length();
|
return guide->position().length();
|
||||||
|
else
|
||||||
|
return QgsUnitTypes::toAbbreviatedString( guide->position().units() );
|
||||||
}
|
}
|
||||||
|
|
||||||
case Qt::TextAlignmentRole:
|
|
||||||
return QVariant( Qt::AlignRight | Qt::AlignVCenter );
|
|
||||||
|
|
||||||
case OrientationRole:
|
case OrientationRole:
|
||||||
return guide->orientation();
|
return guide->orientation();
|
||||||
|
|
||||||
@ -215,7 +223,9 @@ bool QgsLayoutGuideCollection::setData( const QModelIndex &index, const QVariant
|
|||||||
|
|
||||||
QgsLayoutGuide *guide = mGuides.at( index.row() );
|
QgsLayoutGuide *guide = mGuides.at( index.row() );
|
||||||
|
|
||||||
if ( role == Qt::EditRole )
|
switch ( role )
|
||||||
|
{
|
||||||
|
case Qt::EditRole:
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
double newPos = value.toDouble( &ok );
|
double newPos = value.toDouble( &ok );
|
||||||
@ -228,6 +238,34 @@ bool QgsLayoutGuideCollection::setData( const QModelIndex &index, const QVariant
|
|||||||
guide->update();
|
guide->update();
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ class CORE_EXPORT QgsLayoutGuide : public QObject
|
|||||||
* \brief Stores and manages the snap guides used by a layout.
|
* \brief Stores and manages the snap guides used by a layout.
|
||||||
* \since QGIS 3.0
|
* \since QGIS 3.0
|
||||||
*/
|
*/
|
||||||
class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractListModel
|
class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -185,6 +185,7 @@ class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractListModel
|
|||||||
~QgsLayoutGuideCollection();
|
~QgsLayoutGuideCollection();
|
||||||
|
|
||||||
int rowCount( const QModelIndex & ) const override;
|
int rowCount( const QModelIndex & ) const override;
|
||||||
|
int columnCount( const QModelIndex & ) const override;
|
||||||
QVariant data( const QModelIndex &index, int role ) const override;
|
QVariant data( const QModelIndex &index, int role ) const override;
|
||||||
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
|
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
|
||||||
Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user