Skip to content

Commit

Permalink
Merge pull request #37973 from nyalldawson/table_editor_fixes
Browse files Browse the repository at this point in the history
Misc layout table editor fixes and related text formatting widget fixes
  • Loading branch information
nyalldawson committed Jul 27, 2020
2 parents 6e2d102 + 066965c commit 0bb9174
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 169 deletions.
1 change: 1 addition & 0 deletions python/gui/auto_generated/qgsfontbutton.sip.in
Expand Up @@ -9,6 +9,7 @@




class QgsFontButton : QToolButton
{
%Docstring
Expand Down
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgstextformatwidget.sip.in
Expand Up @@ -277,6 +277,13 @@ Constructor for QgsTextFormatPanelWidget.
QgsTextFormat format() const;
%Docstring
Returns the current formatting settings defined by the widget.
%End

void setFormat( const QgsTextFormat &format );
%Docstring
Sets the ``format`` to show in the widget.

.. versionadded:: 3.16
%End

void setContext( const QgsSymbolWidgetContext &context );
Expand Down
Expand Up @@ -138,6 +138,11 @@ Emitted whenever the table contents are changed.
Emitted whenever the "include table header" setting is changed.
%End

protected:

virtual void closeEvent( QCloseEvent * );


};

/************************************************************************
Expand Down
1 change: 1 addition & 0 deletions src/core/labeling/qgspallabeling.cpp
Expand Up @@ -1301,6 +1301,7 @@ QPixmap QgsPalLayerSettings::labelSettingsPreviewPixmap( const QgsPalLayerSettin
QgsMapToPixel newCoordXForm;
newCoordXForm.setParameters( 1, 0, 0, 0, 0, 0 );
context.setMapToPixel( newCoordXForm );
context.setFlag( QgsRenderContext::Antialiasing, true );

context.setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
context.setUseAdvancedEffects( true );
Expand Down
16 changes: 11 additions & 5 deletions src/gui/qgsfontbutton.cpp
Expand Up @@ -94,12 +94,12 @@ void QgsFontButton::showSettingsDialog()
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsTextFormatPanelWidget *formatWidget = new QgsTextFormatPanelWidget( mFormat, mMapCanvas, this, mLayer.data() );
formatWidget->setPanelTitle( mDialogTitle );
formatWidget->setContext( symbolContext );
mActivePanel = new QgsTextFormatPanelWidget( mFormat, mMapCanvas, this, mLayer.data() );
mActivePanel->setPanelTitle( mDialogTitle );
mActivePanel->setContext( symbolContext );

connect( formatWidget, &QgsTextFormatPanelWidget::widgetChanged, this, [ this, formatWidget ] { this->setTextFormat( formatWidget->format() ); } );
panel->openPanel( formatWidget );
connect( mActivePanel, &QgsTextFormatPanelWidget::widgetChanged, this, [ this ] { setTextFormat( mActivePanel->format() ); } );
panel->openPanel( mActivePanel );
return;
}

Expand Down Expand Up @@ -154,8 +154,14 @@ QgsMessageBar *QgsFontButton::messageBar() const

void QgsFontButton::setTextFormat( const QgsTextFormat &format )
{
if ( mActivePanel && !format.isValid() )
mActivePanel->acceptPanel();

mFormat = format;
updatePreview();

if ( mActivePanel && format.isValid() )
mActivePanel->setFormat( format );
emit changed();
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsfontbutton.h
Expand Up @@ -24,6 +24,8 @@
class QgsExpressionContextGenerator;
class QgsMapCanvas;
class QgsMessageBar;
class QgsTextFormatPanelWidget;


/**
* \ingroup gui
Expand Down Expand Up @@ -329,6 +331,7 @@ class GUI_EXPORT QgsFontButton : public QToolButton
bool mShowNoFormat = false;
QString mNullFormatString;
QPointer< QAction > mNullFormatAction;
QPointer< QgsTextFormatPanelWidget > mActivePanel;

/**
* Attempts to parse \a mimeData as a text format.
Expand Down
67 changes: 63 additions & 4 deletions src/gui/qgstextformatwidget.cpp
Expand Up @@ -542,6 +542,8 @@ void QgsTextFormatWidget::setWidgetMode( QgsTextFormatWidget::Mode mode )
break;

case Text:
{
const int prevIndex = mOptionsTab->currentIndex();
toggleDDButtons( true );
delete mLabelingOptionsListWidget->takeItem( 8 ); // rendering
delete mLabelingOptionsListWidget->takeItem( 7 ); // placement
Expand All @@ -555,16 +557,49 @@ void QgsTextFormatWidget::setWidgetMode( QgsTextFormatWidget::Mode mode )
mLabelStackedWidget->removeWidget( mLabelPage_Callouts );
mLabelStackedWidget->removeWidget( mLabelPage_Mask );
mLabelStackedWidget->removeWidget( mLabelPage_Placement );
mLabelStackedWidget->setCurrentIndex( 0 );
switch ( prevIndex )
{
case 0:
case 1:
case 2:
break;

case 4: // background - account for removed mask tab
case 5: // shadow
mLabelStackedWidget->setCurrentIndex( prevIndex - 1 );
mOptionsTab->setCurrentIndex( prevIndex - 1 );
break;

case 3: // mask
case 6: // callouts
case 7: // placement
case 8: // rendering
mLabelStackedWidget->setCurrentIndex( 0 );
mOptionsTab->setCurrentIndex( 0 );
break;
}

frameLabelWith->hide();
mDirectSymbolsFrame->hide();
mFormatNumFrame->hide();
mFormatNumChkBx->hide();
mFormatNumDDBtn->hide();
mSubstitutionsFrame->hide();
mCheckBoxSubstituteText->hide();
mToolButtonConfigureSubstitutes->hide();
mLabelWrapOnCharacter->hide();
wrapCharacterEdit->hide();
mWrapCharDDBtn->hide();
mLabelWrapLinesTo->hide();
mAutoWrapLengthSpinBox->hide();
mAutoWrapLengthDDBtn->hide();
mAutoWrapTypeComboBox->hide();
mFontMultiLineLabel->hide();
mFontMultiLineAlignComboBox->hide();
mFontMultiLineAlignDDBtn->hide();

mTextOrientationComboBox->removeItem( mTextOrientationComboBox->findData( QgsTextFormat::RotationBasedOrientation ) );
break;
}
}
}

Expand Down Expand Up @@ -993,7 +1028,20 @@ QgsTextFormatWidget::~QgsTextFormatWidget()
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/Labeling/FontPreviewSplitState" ), mFontPreviewSplitter->saveState() );
settings.setValue( QStringLiteral( "Windows/Labeling/OptionsSplitState" ), mLabelingOptionsSplitter->saveState() );
settings.setValue( QStringLiteral( "Windows/Labeling/Tab" ), mLabelingOptionsListWidget->currentRow() );

int prevIndex = mLabelingOptionsListWidget->currentRow();
if ( mWidgetMode == Text )
{
switch ( prevIndex )
{
case 3: // background - account for removed mask tab
case 4: // shadow - account for removed mask tab
prevIndex++;
break;
}
}

settings.setValue( QStringLiteral( "Windows/Labeling/Tab" ), prevIndex );
}

QgsTextFormat QgsTextFormatWidget::format( bool includeDataDefinedProperties ) const
Expand Down Expand Up @@ -2036,14 +2084,25 @@ QgsTextFormatPanelWidget::QgsTextFormatPanelWidget( const QgsTextFormat &format,
: QgsPanelWidgetWrapper( new QgsTextFormatWidget( format, mapCanvas, nullptr, layer ), parent )
{
mFormatWidget = qobject_cast< QgsTextFormatWidget * >( widget() );
connect( mFormatWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
connect( mFormatWidget, &QgsTextFormatWidget::widgetChanged, this, [ = ]
{
if ( !mBlockSignals )
emit widgetChanged();
} );
}

QgsTextFormat QgsTextFormatPanelWidget::format() const
{
return mFormatWidget->format();
}

void QgsTextFormatPanelWidget::setFormat( const QgsTextFormat &format )
{
mBlockSignals = true;
mFormatWidget->setFormat( format );
mBlockSignals = false;
}

void QgsTextFormatPanelWidget::setContext( const QgsSymbolWidgetContext &context )
{
mFormatWidget->setContext( context );
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgstextformatwidget.h
Expand Up @@ -395,6 +395,13 @@ class GUI_EXPORT QgsTextFormatPanelWidget : public QgsPanelWidgetWrapper
*/
QgsTextFormat format() const;

/**
* Sets the \a format to show in the widget.
*
* \since QGIS 3.16
*/
void setFormat( const QgsTextFormat &format );

/**
* Sets the \a context in which the widget is shown, e.g., the associated map canvas and expression contexts.
* \since QGIS 3.10
Expand All @@ -406,6 +413,7 @@ class GUI_EXPORT QgsTextFormatPanelWidget : public QgsPanelWidgetWrapper
private:

QgsTextFormatWidget *mFormatWidget = nullptr;
bool mBlockSignals = false;
};

#endif //QGSTEXTFORMATWIDGET_H
Expand Down
17 changes: 17 additions & 0 deletions src/gui/tableeditor/qgstableeditordialog.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsdockwidget.h"
#include "qgspanelwidgetstack.h"
#include "qgstableeditorformattingwidget.h"
#include "qgssettings.h"

#include <QClipboard>
#include <QMessageBox>
Expand Down Expand Up @@ -135,6 +136,22 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )
mTableWidget->setIncludeTableHeader( checked );
emit includeHeaderChanged( checked );
} );

// restore the toolbar and dock widgets positions using Qt settings API
QgsSettings settings;

const QByteArray state = settings.value( QStringLiteral( "LayoutDesigner/tableEditorState" ), QByteArray(), QgsSettings::App ).toByteArray();
if ( !state.isEmpty() && !restoreState( state ) )
{
QgsDebugMsg( QStringLiteral( "restore of table editor dialog UI state failed" ) );
}
}

void QgsTableEditorDialog::closeEvent( QCloseEvent * )
{
QgsSettings settings;
// store the toolbar/dock widget settings using Qt settings API
settings.setValue( QStringLiteral( "LayoutDesigner/tableEditorState" ), saveState(), QgsSettings::App );
}

bool QgsTableEditorDialog::setTableContentsFromClipboard()
Expand Down
4 changes: 4 additions & 0 deletions src/gui/tableeditor/qgstableeditordialog.h
Expand Up @@ -154,6 +154,10 @@ class GUI_EXPORT QgsTableEditorDialog : public QMainWindow, private Ui::QgsTable
*/
void includeHeaderChanged( bool included );

protected:

void closeEvent( QCloseEvent * ) override;

private:
QgsTableEditorWidget *mTableWidget = nullptr;
QgsMessageBar *mMessageBar = nullptr;
Expand Down
16 changes: 16 additions & 0 deletions src/gui/tableeditor/qgstableeditorwidget.cpp
Expand Up @@ -1306,6 +1306,22 @@ void QgsTableEditorTextEdit::keyPressEvent( QKeyEvent *event )
break;
}

case Qt::Key_Tab:
{
if ( event->modifiers() & Qt::ControlModifier )
{
// if tab is pressed then defer to table, unless ctrl modifier is also held
// (emulate spreadsheet behavior)
insertPlainText( QString( '\t' ) );
resizeToContents();
}
else
{
event->ignore();
}
break;
}

default:
QPlainTextEdit::keyPressEvent( event );
}
Expand Down

0 comments on commit 0bb9174

Please sign in to comment.