17#include "moc_qgstabpositionwidget.cpp"
22#include <QDialogButtonBox>
34 connect( mAddButton, &QPushButton::clicked,
this, &QgsTabPositionWidget::mAddButton_clicked );
35 connect( mRemoveButton, &QPushButton::clicked,
this, &QgsTabPositionWidget::mRemoveButton_clicked );
36 connect( mTabPositionTreeWidget, &QTreeWidget::itemChanged,
this, &QgsTabPositionWidget::emitPositionsChanged );
41 mTabPositionTreeWidget->clear();
44 QTreeWidgetItem *entry =
new QTreeWidgetItem();
45 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
46 entry->setText( 0, QLocale().toString( tab.position() ) );
47 entry->setData( 0, Qt::EditRole, tab.position() );
48 mTabPositionTreeWidget->addTopLevelItem( entry );
54 QList<QgsTextFormat::Tab> result;
55 const int nTopLevelItems = mTabPositionTreeWidget->topLevelItemCount();
56 result.reserve( nTopLevelItems );
57 for (
int i = 0; i < nTopLevelItems; ++i )
59 if ( QTreeWidgetItem *currentItem = mTabPositionTreeWidget->topLevelItem( i ) )
67 return a.position() < b.position();
75 QTreeWidgetItem *headerItem = mTabPositionTreeWidget->headerItem();
79void QgsTabPositionWidget::mAddButton_clicked()
81 const QList< QgsTextFormat::Tab > currentPositions =
positions();
82 double newPosition = 6;
83 if ( !currentPositions.empty() )
85 newPosition = currentPositions.last().position() + 6;
88 QTreeWidgetItem *entry =
new QTreeWidgetItem();
89 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
90 entry->setText( 0, QLocale().toString( newPosition ) );
91 entry->setData( 0, Qt::EditRole, newPosition );
92 mTabPositionTreeWidget->addTopLevelItem( entry );
93 emitPositionsChanged();
96void QgsTabPositionWidget::mRemoveButton_clicked()
98 if ( QTreeWidgetItem *currentItem = mTabPositionTreeWidget->currentItem() )
100 mTabPositionTreeWidget->takeTopLevelItem( mTabPositionTreeWidget->indexOfTopLevelItem( currentItem ) );
102 emitPositionsChanged();
105void QgsTabPositionWidget::emitPositionsChanged()
112 : QDialog( parent, f )
114 QVBoxLayout *vLayout =
new QVBoxLayout();
116 vLayout->addWidget( mWidget );
117 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
118 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsTabPositionDialog::accept );
119 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsTabPositionDialog::reject );
120 vLayout->addWidget( bbox );
121 setLayout( vLayout );
122 setWindowTitle( tr(
"Tab Positions" ) );
RenderUnit
Rendering size units.
@ Millimeters
Millimeters.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
QList< QgsTextFormat::Tab > positions() const
Returns the tab positions defined in the dialog.
QgsTabPositionDialog(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor for QgsTabPositionDialog.
void setPositions(const QList< QgsTextFormat::Tab > &positions)
Sets the tab positions to show in the dialog.
void setUnit(Qgis::RenderUnit unit)
Sets the unit type used for the tab positions (used to update interface labels).
Defines a tab position for a text format.
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.