19#include "moc_qgslayoutattributeselectiondialog.cpp" 
   30#include <QDialogButtonBox> 
   36#include <QSortFilterProxyModel> 
   42  : QAbstractTableModel( parent )
 
 
   49  if ( !hasIndex( row, column, 
parent ) )
 
   54    return createIndex( row, column );
 
 
   82  if ( !
index.isValid() || ( role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::UserRole ) )
 
  104      if ( role == Qt::DisplayRole )
 
  108          case Qt::AlignHCenter:
 
  112                return tr( 
"Top center" );
 
  113              case Qt::AlignBottom:
 
  114                return tr( 
"Bottom center" );
 
  116                return tr( 
"Middle center" );
 
  122                return tr( 
"Top right" );
 
  123              case Qt::AlignBottom:
 
  124                return tr( 
"Bottom right" );
 
  126                return tr( 
"Middle right" );
 
  133                return tr( 
"Top left" );
 
  134              case Qt::AlignBottom:
 
  135                return tr( 
"Bottom left" );
 
  137                return tr( 
"Middle left" );
 
  149      if ( role == Qt::DisplayRole )
 
  151        return column.
width() <= 0 ? tr( 
"Automatic" ) : tr( 
"%L1 mm" ).arg( column.
width(), 0, 
'f', 2 );
 
  156        return column.
width();
 
  160      if ( role == Qt::DisplayRole )
 
  164          case Qt::DescendingOrder:
 
  165            return tr( 
"Descending" );
 
  166          case Qt::AscendingOrder:
 
  168            return tr( 
"Ascending" );
 
 
  188  if ( role == Qt::DisplayRole )
 
  190    if ( orientation == Qt::Vertical ) 
 
  192      return QVariant( section );
 
  200          return QVariant( tr( 
"Attribute" ) );
 
  203          return QVariant( tr( 
"Heading" ) );
 
  206          return QVariant( tr( 
"Alignment" ) );
 
  209          return QVariant( tr( 
"Width" ) );
 
  212          return QVariant( tr( 
"Sort Order" ) );
 
 
  222  if ( !
index.isValid() || role != Qt::EditRole || !
mTable )
 
  241        emit dataChanged( createIndex( 
index.row(), 1 ), createIndex( 
index.row(), 1 ) );
 
  253      colToUpdate.
setHAlignment( Qt::AlignmentFlag( value.toInt() & Qt::AlignHorizontal_Mask ) );
 
  254      colToUpdate.
setVAlignment( Qt::AlignmentFlag( value.toInt() & Qt::AlignVertical_Mask ) );
 
  259      colToUpdate.
setWidth( value.toDouble() );
 
  264      colToUpdate.
setSortOrder( 
static_cast<Qt::SortOrder
>( value.toInt() ) );
 
 
  274  Qt::ItemFlags 
flags = QAbstractTableModel::flags( 
index );
 
  276  if ( 
index.isValid() )
 
  278    return flags | Qt::ItemIsEditable;
 
 
  290  const int maxRow = std::min<int>( row + count - 1, 
columns().length() - 1 );
 
  291  beginRemoveRows( QModelIndex(), row, maxRow );
 
  293  for ( 
int i = maxRow; i >= row; --i )
 
 
  304  beginInsertRows( QModelIndex(), row, row + count - 1 );
 
  306  for ( 
int i = row; i < row + count; ++i )
 
 
  323  const int swapWithRow = direction == 
ShiftUp ? row - 1 : row + 1;
 
  326  beginRemoveRows( QModelIndex(), swapWithRow, swapWithRow );
 
  331  beginInsertRows( QModelIndex(), row, row );
 
 
  363  : QItemDelegate( parent )
 
 
  373  QComboBox *comboBox = 
new QComboBox( parent );
 
  375  comboBox->addItem( tr( 
"Top Left" ), 
int( Qt::AlignTop | Qt::AlignLeft ) );
 
  376  comboBox->addItem( tr( 
"Top Center" ), 
int( Qt::AlignTop | Qt::AlignHCenter ) );
 
  377  comboBox->addItem( tr( 
"Top Right" ), 
int( Qt::AlignTop | Qt::AlignRight ) );
 
  378  comboBox->addItem( tr( 
"Middle Left" ), 
int( Qt::AlignVCenter | Qt::AlignLeft ) );
 
  379  comboBox->addItem( tr( 
"Middle Center" ), 
int( Qt::AlignVCenter | Qt::AlignHCenter ) );
 
  380  comboBox->addItem( tr( 
"Middle Right" ), 
int( Qt::AlignVCenter | Qt::AlignRight ) );
 
  381  comboBox->addItem( tr( 
"Bottom Left" ), 
int( Qt::AlignBottom | Qt::AlignLeft ) );
 
  382  comboBox->addItem( tr( 
"Bottom Center" ), 
int( Qt::AlignBottom | Qt::AlignHCenter ) );
 
  383  comboBox->addItem( tr( 
"Bottom Right" ), 
int( Qt::AlignBottom | Qt::AlignRight ) );
 
  385  const Qt::AlignmentFlag alignment = ( Qt::AlignmentFlag ) index.model()->data( index, Qt::EditRole ).toInt();
 
  386  comboBox->setCurrentIndex( comboBox->findData( alignment ) );
 
 
  393  const Qt::AlignmentFlag alignment = ( Qt::AlignmentFlag ) index.model()->data( index, Qt::EditRole ).toInt();
 
  396  QComboBox *comboBox = 
static_cast<QComboBox *
>( editor );
 
  397  comboBox->setCurrentIndex( comboBox->findData( alignment ) );
 
 
  402  QComboBox *comboBox = 
static_cast<QComboBox *
>( editor );
 
  403  const Qt::AlignmentFlag alignment = ( Qt::AlignmentFlag ) comboBox->currentData().toInt();
 
  404  model->setData( index, alignment, Qt::EditRole );
 
 
  410  editor->setGeometry( option.rect );
 
 
  417  : QItemDelegate( parent )
 
  418  , mVectorLayer( vlayer )
 
  419  , mLayoutObject( layoutObject )
 
  420  , mForceExpressions( forceExpressions )
 
 
  426  if ( !mLayoutObject )
 
  443  fieldExpression->
setLayer( mVectorLayer );
 
  448  return fieldExpression;
 
 
  453  const QString field = index.model()->data( index, Qt::EditRole ).toString();
 
 
  465  model->setData( index, field, Qt::EditRole );
 
 
  471  editor->setGeometry( option.rect );
 
 
  474void QgsLayoutColumnSourceDelegate::commitAndCloseEditor()
 
  477  emit commitData( fieldExpression );
 
  484  : QItemDelegate( parent )
 
 
  493  QComboBox *comboBox = 
new QComboBox( parent );
 
  494  QStringList sortOrders;
 
  495  sortOrders << tr( 
"Ascending" ) << tr( 
"Descending" );
 
  496  comboBox->addItems( sortOrders );
 
 
  502  const Qt::SortOrder order = ( Qt::SortOrder ) index.model()->data( index, Qt::EditRole ).toInt();
 
  505  QComboBox *comboBox = 
static_cast<QComboBox *
>( editor );
 
  508    case Qt::DescendingOrder:
 
  509      comboBox->setCurrentIndex( 1 );
 
  511    case Qt::AscendingOrder:
 
  513      comboBox->setCurrentIndex( 0 );
 
 
  520  QComboBox *comboBox = 
static_cast<QComboBox *
>( editor );
 
  521  const int value = comboBox->currentIndex();
 
  526      order = Qt::DescendingOrder;
 
  530      order = Qt::AscendingOrder;
 
  534  model->setData( index, order, Qt::EditRole );
 
 
  540  editor->setGeometry( option.rect );
 
 
  549  : QItemDelegate( parent )
 
 
  558  editor->setMinimum( 0 );
 
  559  editor->setMaximum( 1000 );
 
  560  editor->setDecimals( 2 );
 
  561  editor->setSuffix( tr( 
" mm" ) );
 
 
  569  const int value = index.model()->data( index, Qt::EditRole ).toInt();
 
  572  spinBox->setValue( value );
 
 
  578  spinBox->interpretText();
 
  579  const int value = spinBox->value();
 
  581  model->setData( index, value, Qt::EditRole );
 
 
  587  editor->setGeometry( option.rect );
 
 
  594  : QDialog( parent, f )
 
  601  connect( mRemoveColumnPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mRemoveColumnPushButton_clicked );
 
  602  connect( mAddColumnPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mAddColumnPushButton_clicked );
 
  603  connect( mColumnUpPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mColumnUpPushButton_clicked );
 
  604  connect( mColumnDownPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mColumnDownPushButton_clicked );
 
  605  connect( mResetColumnsPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mResetColumnsPushButton_clicked );
 
  606  connect( mClearColumnsPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mClearColumnsPushButton_clicked );
 
  607  connect( mAddSortColumnPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mAddSortColumnPushButton_clicked );
 
  608  connect( mRemoveSortColumnPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mRemoveSortColumnPushButton_clicked );
 
  609  connect( mSortColumnUpPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mSortColumnUpPushButton_clicked );
 
  610  connect( mSortColumnDownPushButton, &QPushButton::clicked, 
this, &QgsLayoutAttributeSelectionDialog::mSortColumnDownPushButton_clicked );
 
  611  connect( buttonBox, &QDialogButtonBox::helpRequested, 
this, &QgsLayoutAttributeSelectionDialog::showHelp );
 
  617    mColumnsTableView->setModel( mColumnModel );
 
  618    mColumnsTableView->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch );
 
  620    mColumnsTableView->setItemDelegateForColumn( 0, mColumnSourceDelegate );
 
  622    mColumnsTableView->setItemDelegateForColumn( 2, mColumnAlignmentDelegate );
 
  624    mColumnsTableView->setItemDelegateForColumn( 3, mColumnWidthDelegate );
 
  627    mSortColumnTableView->setModel( mSortColumnModel );
 
  628    mSortColumnTableView->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch );
 
  630    mSortColumnTableView->setItemDelegateForColumn( 0, mSortColumnSourceDelegate );
 
  632    mSortColumnTableView->setItemDelegateForColumn( 1, mSortColumnOrderDelegate );
 
 
  636void QgsLayoutAttributeSelectionDialog::mRemoveColumnPushButton_clicked()
 
  639  const QModelIndexList indexes = mColumnsTableView->selectionModel()->selectedRows();
 
  640  const int count = indexes.count();
 
  642  for ( 
int i = count; i > 0; --i )
 
  643    mColumnModel->removeRow( indexes.at( i - 1 ).row(), QModelIndex() );
 
  646void QgsLayoutAttributeSelectionDialog::mAddColumnPushButton_clicked()
 
  649  mColumnModel->insertRow( mColumnModel->
rowCount() );
 
  652void QgsLayoutAttributeSelectionDialog::mColumnUpPushButton_clicked()
 
  656  QModelIndexList indexes = mColumnsTableView->selectionModel()->selectedRows();
 
  657  const int count = indexes.count();
 
  659  std::reverse( indexes.begin(), indexes.end() );
 
  660  for ( 
int i = count; i > 0; --i )
 
  664void QgsLayoutAttributeSelectionDialog::mColumnDownPushButton_clicked()
 
  667  const QModelIndexList indexes = mColumnsTableView->selectionModel()->selectedRows();
 
  668  const int count = indexes.count();
 
  670  for ( 
int i = count; i > 0; --i )
 
  674void QgsLayoutAttributeSelectionDialog::mResetColumnsPushButton_clicked()
 
  680void QgsLayoutAttributeSelectionDialog::mClearColumnsPushButton_clicked()
 
  686void QgsLayoutAttributeSelectionDialog::mAddSortColumnPushButton_clicked()
 
  689  mSortColumnModel->insertRow( mSortColumnModel->
rowCount() );
 
  692void QgsLayoutAttributeSelectionDialog::mRemoveSortColumnPushButton_clicked()
 
  695  const QModelIndexList indexes = mSortColumnTableView->selectionModel()->selectedRows();
 
  696  const int count = indexes.count();
 
  698  for ( 
int i = count; i > 0; --i )
 
  699    mSortColumnModel->removeRow( indexes.at( i - 1 ).row(), QModelIndex() );
 
  702void QgsLayoutAttributeSelectionDialog::showHelp()
 
  704  QgsHelp::openHelp( QStringLiteral( 
"print_composer/composer_items/composer_attribute_table.html" ) );
 
  707void QgsLayoutAttributeSelectionDialog::mSortColumnDownPushButton_clicked()
 
  710  const QModelIndexList indexes = mSortColumnTableView->selectionModel()->selectedRows();
 
  711  const int count = indexes.count();
 
  713  for ( 
int i = count; i > 0; --i )
 
  717void QgsLayoutAttributeSelectionDialog::mSortColumnUpPushButton_clicked()
 
  720  const QModelIndexList indexes = mSortColumnTableView->selectionModel()->selectedRows();
 
  721  const int count = indexes.count();
 
  723  for ( 
int i = count; i > 0; --i )
 
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
 
void setSpecialValueText(const QString &txt)
Set the special-value text to be txt If set, the spin box will display this text instead of a numeric...
 
void setShowClearButton(bool showClearButton)
Sets whether the widget will show a clear button.
 
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
 
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
 
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
 
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
 
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
 
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
 
QgsLayoutAttributeSelectionDialog(QgsLayoutItemAttributeTable *table, QgsVectorLayer *vLayer, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
constructor
 
QModelIndex index(int row, int column, const QModelIndex &parent) const override
 
Column
Available columns for the configuration table to be used by the model.
 
@ SortOrder
Defines the sort order.
 
@ Width
Defines the width of the column.
 
@ Heading
Defines the title of the column.
 
@ Attribute
Attribute for a field or an expression.
 
@ Alignment
Defines the alignment of the column.
 
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
 
bool moveRow(int row, ShiftDirection direction)
Moves the specified row up or down in the model.
 
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
virtual QVector< QgsLayoutTableColumn > & columns() const =0
To be reimplemented to provide the display or the sort columns.
 
QVariant data(const QModelIndex &index, int role) const override
 
QgsLayoutAttributeTableColumnModelBase(QgsLayoutItemAttributeTable *table, QObject *parent=nullptr)
Constructor for QgsLayoutAttributeTableColumnModel.
 
int columnCount(const QModelIndex &parent=QModelIndex()) const override
 
virtual QList< Column > displayedColumns() const =0
To be reimplemented to choose which column should be used by the model.
 
QgsLayoutItemAttributeTable * mTable
 
int rowCount(const QModelIndex &parent=QModelIndex()) const override
 
Qt::ItemFlags flags(const QModelIndex &index) const override
 
QModelIndex parent(const QModelIndex &child) const override
 
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
ShiftDirection
Controls whether a row/column is shifted up or down.
 
@ ShiftUp
Shift the row/column up.
 
@ ShiftDown
Shift the row/column down.
 
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
 
A model for displaying columns shown in a QgsLayoutAttributeTable.
 
QVector< QgsLayoutTableColumn > & columns() const override
To be reimplemented to provide the display or the sort columns.
 
void resetToLayer()
Resets the attribute table's columns to match the source layer's fields.
 
A delegate for showing column alignment as a combo box.
 
void setEditorData(QWidget *editor, const QModelIndex &index) const override
 
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
QgsLayoutColumnAlignmentDelegate(QObject *parent=nullptr)
constructor
 
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
 
A delegate for showing column sort order as a combo box.
 
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
 
void setEditorData(QWidget *editor, const QModelIndex &index) const override
 
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
QgsLayoutColumnSortOrderDelegate(QObject *parent=nullptr)
constructor
 
A delegate for showing column attribute source as a QgsFieldExpressionWidget.
 
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
 
QgsLayoutColumnSourceDelegate(QgsVectorLayer *vlayer, QObject *parent=nullptr, const QgsLayoutObject *layoutObject=nullptr, bool forceExpressions=false)
Constructor for QgsLayoutColumnSourceDelegate.
 
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void setEditorData(QWidget *editor, const QModelIndex &index) const override
 
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
A delegate for showing column width as a spin box.
 
void setEditorData(QWidget *editor, const QModelIndex &index) const override
 
QgsLayoutColumnWidthDelegate(QObject *parent=nullptr)
constructor
 
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
 
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
A layout table subclass that displays attributes from a vector layer.
 
void resetColumns()
Resets the attribute table's columns to match the vector layer's fields.
 
A base class for objects which belong to a layout.
 
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
 
Stores properties of a column for a QgsLayoutTable.
 
QString attribute() const
Returns the attribute name or expression used for the column's values.
 
void setVAlignment(Qt::AlignmentFlag alignment)
Sets the vertical alignment for a column, which controls the alignment used for drawing column values...
 
double width() const
Returns the width for the column in mm, or 0 if column width is automatically calculated.
 
Qt::AlignmentFlag vAlignment() const
Returns the vertical alignment for a column, which controls the alignment used for drawing column val...
 
QString heading() const
Returns the heading for a column, which is the value displayed in the column's header cell.
 
void setSortOrder(Qt::SortOrder order)
Sets the sort order for the column.
 
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column's values.
 
Qt::SortOrder sortOrder() const
Returns the sort order for the column.
 
void setHAlignment(Qt::AlignmentFlag alignment)
Sets the horizontal alignment for a column, which controls the alignment used for drawing column valu...
 
void setHeading(const QString &heading)
Sets the heading for a column, which is the value displayed in the column's header cell.
 
Qt::AlignmentFlag hAlignment() const
Returns the horizontal alignment for a column, which controls the alignment used for drawing column v...
 
void setWidth(const double width)
Sets the width for a column in mm.
 
Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted.
 
QVector< QgsLayoutTableColumn > & columns() const override
To be reimplemented to provide the display or the sort columns.
 
QgsLayoutTableColumns & columns()
Returns a reference to the list of QgsLayoutTableColumns shown in the table.
 
QgsLayoutTableSortColumns & sortColumns()
Returns a reference to the list of QgsLayoutTableSortColumns shown in the table.
 
Represents a vector layer which manages a vector based dataset.
 
Single variable definition for use within a QgsExpressionContextScope.