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 ) )
66 return a.position() < b.position();
74 QTreeWidgetItem *headerItem = mTabPositionTreeWidget->headerItem();
78void QgsTabPositionWidget::mAddButton_clicked()
80 const QList<QgsTextFormat::Tab> currentPositions =
positions();
81 double newPosition = 6;
82 if ( !currentPositions.empty() )
84 newPosition = currentPositions.last().position() + 6;
87 QTreeWidgetItem *entry =
new QTreeWidgetItem();
88 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
89 entry->setText( 0, QLocale().toString( newPosition ) );
90 entry->setData( 0, Qt::EditRole, newPosition );
91 mTabPositionTreeWidget->addTopLevelItem( entry );
92 emitPositionsChanged();
95void QgsTabPositionWidget::mRemoveButton_clicked()
97 if ( QTreeWidgetItem *currentItem = mTabPositionTreeWidget->currentItem() )
99 mTabPositionTreeWidget->takeTopLevelItem( mTabPositionTreeWidget->indexOfTopLevelItem( currentItem ) );
101 emitPositionsChanged();
104void QgsTabPositionWidget::emitPositionsChanged()
111 : QDialog( parent, f )
113 QVBoxLayout *vLayout =
new QVBoxLayout();
115 vLayout->addWidget( mWidget );
116 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
117 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsTabPositionDialog::accept );
118 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsTabPositionDialog::reject );
119 vLayout->addWidget( bbox );
120 setLayout( vLayout );
121 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.