Skip to content

Commit

Permalink
Add interactive editor dialog for layout manual table items
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 14, 2020
1 parent 49d56f6 commit 387787b
Show file tree
Hide file tree
Showing 20 changed files with 2,061 additions and 55 deletions.
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Expand Up @@ -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
)
Expand Down
50 changes: 50 additions & 0 deletions python/gui/auto_generated/tableeditor/qgstableeditordialog.sip.in
@@ -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 *
************************************************************************/
71 changes: 71 additions & 0 deletions python/gui/auto_generated/tableeditor/qgstableeditorwidget.sip.in
@@ -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 *
************************************************************************/
2 changes: 2 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -529,6 +529,7 @@ INCLUDE_DIRECTORIES(
../gui/editorwidgets/core
../gui/layertree
../gui/layout
../gui/tableeditor
../plugins
../python
gps
Expand Down
49 changes: 32 additions & 17 deletions src/app/layout/qgslayoutmanualtablewidget.cpp
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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 )
Expand Down Expand Up @@ -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() ) );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -458,6 +472,7 @@ void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
}

QgsLayoutTableBackgroundColorsDialog d( mTable, this );

d.exec();
}

Expand Down
7 changes: 5 additions & 2 deletions src/app/layout/qgslayoutmanualtablewidget.h
Expand Up @@ -20,6 +20,8 @@

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

class QgsLayoutItemManualTable;
class QgsLayoutFrame;
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitemmanualtable.cpp
Expand Up @@ -29,6 +29,7 @@
QgsLayoutItemManualTable::QgsLayoutItemManualTable( QgsLayout *layout )
: QgsLayoutTable( layout )
{
setHeaderMode( NoHeaders );
refreshAttributes();
}

Expand Down
9 changes: 9 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 387787b

Please sign in to comment.