Skip to content
Permalink
Browse files

Merge pull request #37973 from nyalldawson/table_editor_fixes

Misc layout table editor fixes and related text formatting widget fixes
  • Loading branch information
nyalldawson committed Jul 27, 2020
2 parents 6e2d102 + 066965c commit 0bb9174c2aa6796981f4d1a7865bb4818ccd258f
@@ -9,6 +9,7 @@




class QgsFontButton : QToolButton
{
%Docstring
@@ -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 );
@@ -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 * );


};

/************************************************************************
@@ -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 );
@@ -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;
}

@@ -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();
}

@@ -24,6 +24,8 @@
class QgsExpressionContextGenerator;
class QgsMapCanvas;
class QgsMessageBar;
class QgsTextFormatPanelWidget;


/**
* \ingroup gui
@@ -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.
@@ -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
@@ -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;
}
}
}

@@ -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
@@ -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 );
@@ -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
@@ -406,6 +413,7 @@ class GUI_EXPORT QgsTextFormatPanelWidget : public QgsPanelWidgetWrapper
private:

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

#endif //QGSTEXTFORMATWIDGET_H
@@ -20,6 +20,7 @@
#include "qgsdockwidget.h"
#include "qgspanelwidgetstack.h"
#include "qgstableeditorformattingwidget.h"
#include "qgssettings.h"

#include <QClipboard>
#include <QMessageBox>
@@ -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()
@@ -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;
@@ -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 );
}

0 comments on commit 0bb9174

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