Skip to content
Permalink
Browse files

Add interactive editor dialog for layout manual table items

  • Loading branch information
nyalldawson committed Jan 10, 2020
1 parent 49d56f6 commit 387787b539d00dfc220e7c60977f8e0dbdb6e4d3
@@ -150,6 +150,7 @@ IF (WITH_GUI)
${CMAKE_SOURCE_DIR}/src/gui/locator
${CMAKE_SOURCE_DIR}/src/gui/numericformats
${CMAKE_SOURCE_DIR}/src/gui/processing
${CMAKE_SOURCE_DIR}/src/gui/tableeditor

${CMAKE_BINARY_DIR}/src/gui
)
@@ -0,0 +1,50 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/tableeditor/qgstableeditordialog.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsTableEditorDialog : QMainWindow
{
%Docstring
*************************************************************************
qgstableeditordialog.h
---------------------
begin : January 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
**************************************************************************

This program is free software; you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by *
the Free Software Foundation; either version 2 of the License, or *
(at your option) any later version. *

**************************************************************************
%End

%TypeHeaderCode
#include "qgstableeditordialog.h"
%End
public:
QgsTableEditorDialog( QWidget *parent = 0 );
void setTableData( const QgsTableContents &contents );
QgsTableContents tableData() const;

signals:

void tableChanged();

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/tableeditor/qgstableeditordialog.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,71 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/tableeditor/qgstableeditorwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsTableEditorWidget : QTableWidget
{

%TypeHeaderCode
#include "qgstableeditorwidget.h"
%End
public:

enum Roles
{
PresetBackgroundColorRole,

};

QgsTableEditorWidget( QWidget *parent = 0 );
~QgsTableEditorWidget();

void setTableData( const QgsTableContents &contents );
QgsTableContents tableData() const;

void setCellNumericFormat( QgsNumericFormat *format /Transfer/ );

QColor selectedCellForegroundColor();

QColor selectedCellBackgroundColor();

public slots:

void insertRowsBelow();
void insertRowsAbove();
void insertColumnsBefore();
void insertColumnsAfter();
void deleteRows();
void deleteColumns();

void selectRows();
void selectColumns();
void clearSelectedCells();

void setCellForegroundColor( const QColor &color );
void setCellBackgroundColor( const QColor &color );


protected:
virtual void keyPressEvent( QKeyEvent *event );


signals:

void tableChanged();
void activeCellChanged();

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/tableeditor/qgstableeditorwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -357,5 +357,7 @@
%Include auto_generated/symbology/qgssymbolslistwidget.sip
%Include auto_generated/symbology/qgssymbolwidgetcontext.sip
%Include auto_generated/symbology/qgsvectorfieldsymbollayerwidget.sip
%Include auto_generated/tableeditor/qgstableeditordialog.sip
%Include auto_generated/tableeditor/qgstableeditorwidget.sip
%Include auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip
%Include auto_generated/qgsadvanceddigitizingcanvasitem.sip
@@ -529,6 +529,7 @@ INCLUDE_DIRECTORIES(
../gui/editorwidgets/core
../gui/layertree
../gui/layout
../gui/tableeditor
../plugins
../python
gps
@@ -32,7 +32,7 @@ QgsLayoutManualTableWidget::QgsLayoutManualTableWidget( QgsLayoutFrame *frame )
{
setupUi( this );
connect( mRefreshPushButton, &QPushButton::clicked, this, &QgsLayoutManualTableWidget::mRefreshPushButton_clicked );
connect( mAttributesPushButton, &QPushButton::clicked, this, &QgsLayoutManualTableWidget::mAttributesPushButton_clicked );
connect( mSetContentsButton, &QPushButton::clicked, this, &QgsLayoutManualTableWidget::setTableContents );
connect( mMarginSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged );
connect( mGridStrokeWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged );
connect( mGridColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutManualTableWidget::mGridColorButton_colorChanged );
@@ -43,7 +43,6 @@ QgsLayoutManualTableWidget::QgsLayoutManualTableWidget( QgsLayoutFrame *frame )
connect( mDrawVerticalGrid, &QCheckBox::toggled, this, &QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled );
connect( mShowGridGroupCheckBox, &QgsCollapsibleGroupBoxBasic::toggled, this, &QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled );
connect( mHeaderHAlignmentComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged );
connect( mHeaderModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged );
connect( mAddFramePushButton, &QPushButton::clicked, this, &QgsLayoutManualTableWidget::mAddFramePushButton_clicked );
connect( mResizeModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged );
connect( mDrawEmptyCheckBox, &QCheckBox::toggled, this, &QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled );
@@ -123,6 +122,10 @@ bool QgsLayoutManualTableWidget::setNewItem( QgsLayoutItem *item )
{
disconnect( mTable, &QgsLayoutObject::changed, this, &QgsLayoutManualTableWidget::updateGuiElements );
}
if ( mEditorDialog )
{
mEditorDialog->close();
}

mTable = qobject_cast< QgsLayoutItemManualTable * >( multiFrame );
mFrame = frame;
@@ -149,13 +152,38 @@ void QgsLayoutManualTableWidget::mRefreshPushButton_clicked()
mTable->refreshAttributes();
}

void QgsLayoutManualTableWidget::mAttributesPushButton_clicked()
void QgsLayoutManualTableWidget::setTableContents()
{
if ( !mTable )
{
return;
}

if ( mEditorDialog )
{
// the unholy quadfecta
mEditorDialog->show();
mEditorDialog->raise();
mEditorDialog->setWindowState( windowState() & ~Qt::WindowMinimized );
mEditorDialog->activateWindow();
}
else
{
mEditorDialog = new QgsTableEditorDialog( this );
connect( this, &QWidget::destroyed, mEditorDialog, &QMainWindow::close );

mEditorDialog->setTableData( mTable->tableContents() );
connect( mEditorDialog, &QgsTableEditorDialog::tableChanged, this, [ = ]
{
if ( mTable )
{
mTable->beginCommand( tr( "Change Table Contents" ) );
mTable->setTableContents( mEditorDialog->tableData() );
mTable->endCommand();
}
} );
mEditorDialog->show();
}
}

void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged( double d )
@@ -318,7 +346,6 @@ void QgsLayoutManualTableWidget::updateGuiElements()
mContentFontToolButton->setCurrentFont( mTable->contentFont() );

mHeaderHAlignmentComboBox->setCurrentIndex( static_cast<int>( mTable->headerHAlignment() ) );
mHeaderModeComboBox->setCurrentIndex( static_cast<int>( mTable->headerMode() ) );

mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
@@ -342,7 +369,6 @@ void QgsLayoutManualTableWidget::blockAllSignals( bool b )
mDrawVerticalGrid->blockSignals( b );
mShowGridGroupCheckBox->blockSignals( b );
mHeaderHAlignmentComboBox->blockSignals( b );
mHeaderModeComboBox->blockSignals( b );
mHeaderFontColorButton->blockSignals( b );
mContentFontColorButton->blockSignals( b );
mResizeModeComboBox->blockSignals( b );
@@ -390,18 +416,6 @@ void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
mTable->endCommand();
}

void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged( int index )
{
if ( !mTable )
{
return;
}

mTable->beginCommand( tr( "Change Table Header Mode" ) );
mTable->setHeaderMode( ( QgsLayoutTable::HeaderMode )index );
mTable->endCommand();
}

void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
{
if ( !mTable || !mFrame )
@@ -458,6 +472,7 @@ void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
}

QgsLayoutTableBackgroundColorsDialog d( mTable, this );

d.exec();
}

@@ -20,6 +20,8 @@

#include "ui_qgslayoutmanualtablewidgetbase.h"
#include "qgslayoutitemwidget.h"
#include "qgstableeditordialog.h"
#include <QPointer>

class QgsLayoutItemManualTable;
class QgsLayoutFrame;
@@ -41,12 +43,14 @@ class QgsLayoutManualTableWidget: public QgsLayoutItemBaseWidget, private Ui::Qg
QPointer< QgsLayoutFrame > mFrame;
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;

QPointer< QgsTableEditorDialog > mEditorDialog;

//! Blocks / unblocks the signals of all GUI elements
void blockAllSignals( bool b );

private slots:
void mRefreshPushButton_clicked();
void mAttributesPushButton_clicked();
void setTableContents();
void mMarginSpinBox_valueChanged( double d );
void mGridStrokeWidthSpinBox_valueChanged( double d );
void mGridColorButton_colorChanged( const QColor &newColor );
@@ -59,7 +63,6 @@ class QgsLayoutManualTableWidget: public QgsLayoutItemBaseWidget, private Ui::Qg
void mDrawVerticalGrid_toggled( bool state );
void mShowGridGroupCheckBox_toggled( bool state );
void mHeaderHAlignmentComboBox_currentIndexChanged( int index );
void mHeaderModeComboBox_currentIndexChanged( int index );
void mAddFramePushButton_clicked();
void mResizeModeComboBox_currentIndexChanged( int index );
void mDrawEmptyCheckBox_toggled( bool checked );
@@ -29,6 +29,7 @@
QgsLayoutItemManualTable::QgsLayoutItemManualTable( QgsLayout *layout )
: QgsLayoutTable( layout )
{
setHeaderMode( NoHeaders );
refreshAttributes();
}

@@ -237,6 +237,10 @@ SET(QGIS_GUI_SRCS
providers/ogr/qgsogritemguiprovider.cpp
providers/ogr/qgsgeopackageprojectstorageguiprovider.cpp

tableeditor/qgstableeditordialog.cpp
tableeditor/qgstableeditorformattingwidget.cpp
tableeditor/qgstableeditorwidget.cpp

qgisinterface.cpp
qgsactionmenu.cpp
qgsadvanceddigitizingcanvasitem.cpp
@@ -880,6 +884,10 @@ SET(QGIS_GUI_HDRS
symbology/qgssymbolwidgetcontext.h
symbology/qgsvectorfieldsymbollayerwidget.h

tableeditor/qgstableeditordialog.h
tableeditor/qgstableeditorformattingwidget.h
tableeditor/qgstableeditorwidget.h

qgsbrowserdockwidget_p.h
)

@@ -978,6 +986,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/gui/providers/gdal
${CMAKE_SOURCE_DIR}/src/gui/providers/ogr
${CMAKE_SOURCE_DIR}/src/gui/raster
${CMAKE_SOURCE_DIR}/src/gui/tableeditor
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/annotations
${CMAKE_SOURCE_DIR}/src/core/auth

0 comments on commit 387787b

Please sign in to comment.
You can’t perform that action at this time.