17#include "moc_qgstableeditordialog.cpp" 
   35  : QMainWindow( parent )
 
   38  setWindowTitle( tr( 
"Table Designer" ) );
 
   40  setAttribute( Qt::WA_DeleteOnClose );
 
   41  setDockOptions( dockOptions() | QMainWindow::GroupedDragging );
 
   45  QGridLayout *viewLayout = 
new QGridLayout();
 
   46  viewLayout->setSpacing( 0 );
 
   47  viewLayout->setContentsMargins( 0, 0, 0, 0 );
 
   48  centralWidget()->layout()->setSpacing( 0 );
 
   49  centralWidget()->layout()->setContentsMargins( 0, 0, 0, 0 );
 
   52  mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
 
   53  static_cast<QGridLayout *
>( centralWidget()->layout() )->addWidget( mMessageBar, 0, 0, 1, 1, Qt::AlignTop );
 
   56  mTableWidget->setContentsMargins( 0, 0, 0, 0 );
 
   57  viewLayout->addWidget( mTableWidget, 0, 0 );
 
   58  mViewFrame->setLayout( viewLayout );
 
   59  mViewFrame->setContentsMargins( 0, 0, 0, 0 );
 
   61  mTableWidget->setFocus();
 
   69  const int minDockWidth( fontMetrics().boundingRect( QStringLiteral( 
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) ).width() );
 
   71  mPropertiesDock = 
new QgsDockWidget( tr( 
"Cell Contents" ), 
this );
 
   72  mPropertiesDock->setObjectName( QStringLiteral( 
"FormattingDock" ) );
 
   74  mPropertiesDock->setWidget( mPropertiesStack );
 
   75  mPropertiesDock->setMinimumWidth( minDockWidth );
 
   81  mPropertiesDock->setFeatures( QDockWidget::NoDockWidgetFeatures );
 
  109    updateActionsFromSelection();
 
  113  updateActionsFromSelection();
 
  115  addDockWidget( Qt::RightDockWidgetArea, mPropertiesDock );
 
  117  mActionImportFromClipboard->setEnabled( !QApplication::clipboard()->text().isEmpty() );
 
  118  connect( QApplication::clipboard(), &QClipboard::dataChanged, 
this, [
this]() { mActionImportFromClipboard->setEnabled( !QApplication::clipboard()->text().isEmpty() ); } );
 
  121  connect( mActionClose, &QAction::triggered, 
this, &QMainWindow::close );
 
  132  connect( mActionSelectAll, &QAction::triggered, mTableWidget, &QgsTableEditorWidget::selectAll );
 
  134  connect( mActionIncludeHeader, &QAction::toggled, 
this, [
this]( 
bool checked ) {
 
  142  const QByteArray state = settings.
value( QStringLiteral( 
"LayoutDesigner/tableEditorState" ), QByteArray(), 
QgsSettings::App ).toByteArray();
 
  143  if ( !state.isEmpty() && !restoreState( state ) )
 
  145    QgsDebugError( QStringLiteral( 
"restore of table editor dialog UI state failed" ) );
 
 
  158  return mLayer.data();
 
 
  163  if ( 
layer != mLayer )
 
 
  177  if ( mTable == 
table )
 
  184    setLayer( layout->reportContext().layer() );
 
  193  for ( 
const double height : rowHeights )
 
  200  QVariantList headers;
 
  201  headers.reserve( columnWidths.size() );
 
  202  for ( 
const double width : columnWidths )
 
 
  214  if ( QApplication::clipboard()->text().isEmpty() )
 
  217  if ( QMessageBox::question( 
this, tr( 
"Import Content From Clipboard" ), tr( 
"Importing content from clipboard will overwrite current table content. Are you sure?" ) ) != QMessageBox::Yes )
 
  221  const QStringList lines = QApplication::clipboard()->text().split( 
'\n' );
 
  222  for ( 
const QString &line : lines )
 
  224    if ( !line.isEmpty() )
 
  227      const QStringList cells = line.split( 
'\t' );
 
  228      for ( 
const QString &text : cells )
 
  237  if ( !contents.isEmpty() )
 
 
  249  mBlockSignals = 
true;
 
  251  mTableWidget->resizeRowsToContents();
 
  252  mTableWidget->resizeColumnsToContents();
 
  253  mBlockSignals = 
false;
 
 
  283  return mActionIncludeHeader->isChecked();
 
 
  288  mActionIncludeHeader->setChecked( included );
 
 
  306void QgsTableEditorDialog::updateActionsFromSelection()
 
  311  mActionInsertRowsAbove->setEnabled( rowCount > 0 );
 
  312  mActionInsertRowsBelow->setEnabled( rowCount > 0 );
 
  313  mActionDeleteRows->setEnabled( rowCount > 0 );
 
  314  mActionSelectRow->setEnabled( rowCount > 0 );
 
  317    mActionInsertRowsAbove->setText( tr( 
"Rows Above" ) );
 
  318    mActionInsertRowsBelow->setText( tr( 
"Rows Below" ) );
 
  319    mActionDeleteRows->setText( tr( 
"Delete Rows" ) );
 
  320    mActionSelectRow->setText( tr( 
"Select Rows" ) );
 
  322  else if ( rowCount == 1 )
 
  324    mActionInsertRowsAbove->setText( tr( 
"Row Above" ) );
 
  325    mActionInsertRowsBelow->setText( tr( 
"Row Below" ) );
 
  326    mActionDeleteRows->setText( tr( 
"Delete Row" ) );
 
  327    mActionSelectRow->setText( tr( 
"Select Row" ) );
 
  331    mActionInsertRowsAbove->setText( tr( 
"%n Row(s) Above", 
nullptr, rowCount ) );
 
  332    mActionInsertRowsBelow->setText( tr( 
"%n Row(s) Below", 
nullptr, rowCount ) );
 
  333    mActionDeleteRows->setText( tr( 
"Delete %n Row(s)", 
nullptr, rowCount ) );
 
  334    mActionSelectRow->setText( tr( 
"Select %n Row(s)", 
nullptr, rowCount ) );
 
  337  mActionInsertColumnsBefore->setEnabled( columnCount > 0 );
 
  338  mActionInsertColumnsAfter->setEnabled( columnCount > 0 );
 
  339  mActionDeleteColumns->setEnabled( columnCount > 0 );
 
  340  mActionSelectColumn->setEnabled( columnCount > 0 );
 
  341  if ( columnCount == 0 )
 
  343    mActionInsertColumnsBefore->setText( tr( 
"Columns Before" ) );
 
  344    mActionInsertColumnsAfter->setText( tr( 
"Columns After" ) );
 
  345    mActionDeleteColumns->setText( tr( 
"Delete Columns" ) );
 
  346    mActionSelectColumn->setText( tr( 
"Select Columns" ) );
 
  348  else if ( columnCount == 1 )
 
  350    mActionInsertColumnsBefore->setText( tr( 
"Column Before" ) );
 
  351    mActionInsertColumnsAfter->setText( tr( 
"Column After" ) );
 
  352    mActionDeleteColumns->setText( tr( 
"Delete Column" ) );
 
  353    mActionSelectColumn->setText( tr( 
"Select Column" ) );
 
  357    mActionInsertColumnsBefore->setText( tr( 
"%n Column(s) Before", 
nullptr, columnCount ) );
 
  358    mActionInsertColumnsAfter->setText( tr( 
"%n Column(s) After", 
nullptr, columnCount ) );
 
  359    mActionDeleteColumns->setText( tr( 
"Delete %n Column(s)", 
nullptr, columnCount ) );
 
  360    mActionSelectColumn->setText( tr( 
"Select %n Column(s)", 
nullptr, columnCount ) );
 
Abstract interface for generating an expression context.
 
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...
 
A layout table subclass that displays manually entered (and formatted) content.
 
QList< double > rowHeights() const
Returns the list of row heights (in millimeters) to use when rendering the table.
 
bool includeTableHeader() const
Returns true if the table includes a header row.
 
QgsLayoutTableColumns & headers()
Returns a reference to the list of headers shown in the table.
 
QList< double > columnWidths() const
Returns the list of column widths (in millimeters) to use when rendering the table.
 
QgsTableContents tableContents() const
Returns the contents of the table.
 
const QgsLayout * layout() const
Returns the layout the object is attached to.
 
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
 
Base class for all map layer types.
 
A bar for displaying non-blocking messages to the user.
 
Stores settings for use within QGIS.
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
 
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
 
Encapsulates the contents and formatting of a single table cell.
 
void setIncludeTableHeader(bool included)
Sets whether the table includes a header row.
 
void setTable(QgsLayoutItemManualTable *table)
Sets the table associated with the editor.
 
QgsTableContents tableContents() const
Returns the current contents of the editor widget table.
 
void setTableHeaders(const QVariantList &headers)
Sets the table headers.
 
bool includeTableHeader() const
Returns true if the table includes a header row.
 
QgsTableEditorDialog(QWidget *parent=nullptr)
Constructor for QgsTableEditorDialog with the specified parent widget.
 
void includeHeaderChanged(bool included)
Emitted whenever the "include table header" setting is changed.
 
void setTableColumnWidth(int column, double width)
Sets the configured column width for the specified column.
 
void tableChanged()
Emitted whenever the table contents are changed.
 
void setTableRowHeight(int row, double height)
Sets the configured row height for the specified row.
 
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
 
bool setTableContentsFromClipboard()
Parses the clipboard text into contents to show in the editor widget.
 
QVariantList tableHeaders() const
Returns the table header values.
 
void closeEvent(QCloseEvent *) override
 
QgsMapLayer * layer() const
Returns the (possibly nullptr) layer associated with the expression editor context.
 
double tableRowHeight(int row)
Returns the configured row height for the specified row, or 0 if an automatic height should be used f...
 
double tableColumnWidth(int column)
Returns the configured column width for the specified column, or 0 if an automatic width should be us...
 
QgsLayoutItemManualTable * table() const
Returns the manual table associated with the editor.
 
void setLayer(QgsMapLayer *layer)
Sets the layer to be used associated with the expression editor context.
 
void setTableContents(const QgsTableContents &contents)
Sets the contents to show in the editor widget.
 
#define QgsDebugError(str)
 
QVector< QgsTableRow > QgsTableContents
A set of table rows.
 
QVector< QgsTableCell > QgsTableRow
A row of table cells.