mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add QgsExpressionStoreDialog
This commit is contained in:
parent
2ab794bcc5
commit
09345b5130
60
python/gui/auto_generated/qgsexpressionstoredialog.sip.in
Normal file
60
python/gui/auto_generated/qgsexpressionstoredialog.sip.in
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* This file has been generated automatically from *
|
||||||
|
* *
|
||||||
|
* src/gui/qgsexpressionstoredialog.h *
|
||||||
|
* *
|
||||||
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class QgsExpressionStoreDialog : QDialog
|
||||||
|
{
|
||||||
|
%Docstring
|
||||||
|
A generic dialog for editing expression text, label and help text.
|
||||||
|
|
||||||
|
.. versionadded:: 3.12
|
||||||
|
%End
|
||||||
|
|
||||||
|
%TypeHeaderCode
|
||||||
|
#include "qgsexpressionstoredialog.h"
|
||||||
|
%End
|
||||||
|
public:
|
||||||
|
|
||||||
|
QgsExpressionStoreDialog( const QString &label,
|
||||||
|
const QString &expression,
|
||||||
|
const QString &helpText,
|
||||||
|
const QStringList &existingLabels,
|
||||||
|
QWidget *parent = 0 );
|
||||||
|
%Docstring
|
||||||
|
Creates a QgsExpressionStoreDialog with given ``label``, ``expression`` and ``helpText``.
|
||||||
|
|
||||||
|
:param existingLabels: list of existing labels for unique label validation
|
||||||
|
:param parent: optional parent widget
|
||||||
|
%End
|
||||||
|
|
||||||
|
QString expression( );
|
||||||
|
%Docstring
|
||||||
|
Returns the expression text
|
||||||
|
%End
|
||||||
|
|
||||||
|
QString label();
|
||||||
|
%Docstring
|
||||||
|
Returns the label text
|
||||||
|
%End
|
||||||
|
|
||||||
|
QString helpText();
|
||||||
|
%Docstring
|
||||||
|
Returns the help text
|
||||||
|
%End
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* This file has been generated automatically from *
|
||||||
|
* *
|
||||||
|
* src/gui/qgsexpressionstoredialog.h *
|
||||||
|
* *
|
||||||
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||||
|
************************************************************************/
|
@ -65,6 +65,7 @@
|
|||||||
%Include auto_generated/qgsencodingfiledialog.sip
|
%Include auto_generated/qgsencodingfiledialog.sip
|
||||||
%Include auto_generated/qgserrordialog.sip
|
%Include auto_generated/qgserrordialog.sip
|
||||||
%Include auto_generated/qgsexpressionbuilderdialog.sip
|
%Include auto_generated/qgsexpressionbuilderdialog.sip
|
||||||
|
%Include auto_generated/qgsexpressionstoredialog.sip
|
||||||
%Include auto_generated/qgsexpressionbuilderwidget.sip
|
%Include auto_generated/qgsexpressionbuilderwidget.sip
|
||||||
%Include auto_generated/qgsexpressionhighlighter.sip
|
%Include auto_generated/qgsexpressionhighlighter.sip
|
||||||
%Include auto_generated/qgsexpressionlineedit.sip
|
%Include auto_generated/qgsexpressionlineedit.sip
|
||||||
|
@ -153,6 +153,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer *vl, QWidget *parent )
|
|||||||
mOnlyUpdateSelectedCheckBox->setText( tr( "Only update %1 selected features" ).arg( vl->selectedFeatureCount() ) );
|
mOnlyUpdateSelectedCheckBox->setText( tr( "Only update %1 selected features" ).arg( vl->selectedFeatureCount() ) );
|
||||||
|
|
||||||
builder->loadRecent( QStringLiteral( "fieldcalc" ) );
|
builder->loadRecent( QStringLiteral( "fieldcalc" ) );
|
||||||
|
builder->loadStored( QStringLiteral( "fieldcalc" ) );
|
||||||
|
|
||||||
mInfoIcon->setPixmap( style()->standardPixmap( QStyle::SP_MessageBoxInformation ) );
|
mInfoIcon->setPixmap( style()->standardPixmap( QStyle::SP_MessageBoxInformation ) );
|
||||||
|
|
||||||
|
@ -292,6 +292,7 @@ SET(QGIS_GUI_SRCS
|
|||||||
qgsexpressionhighlighter.cpp
|
qgsexpressionhighlighter.cpp
|
||||||
qgsexpressionlineedit.cpp
|
qgsexpressionlineedit.cpp
|
||||||
qgsexpressionselectiondialog.cpp
|
qgsexpressionselectiondialog.cpp
|
||||||
|
qgsexpressionstoredialog.cpp
|
||||||
qgsextentgroupbox.cpp
|
qgsextentgroupbox.cpp
|
||||||
qgsexternalresourcewidget.cpp
|
qgsexternalresourcewidget.cpp
|
||||||
qgsfeatureselectiondlg.cpp
|
qgsfeatureselectiondlg.cpp
|
||||||
@ -487,6 +488,7 @@ SET(QGIS_GUI_HDRS
|
|||||||
qgsencodingfiledialog.h
|
qgsencodingfiledialog.h
|
||||||
qgserrordialog.h
|
qgserrordialog.h
|
||||||
qgsexpressionbuilderdialog.h
|
qgsexpressionbuilderdialog.h
|
||||||
|
qgsexpressionstoredialog.h
|
||||||
qgsexpressionbuilderwidget.h
|
qgsexpressionbuilderwidget.h
|
||||||
qgsexpressionhighlighter.h
|
qgsexpressionhighlighter.h
|
||||||
qgsexpressionlineedit.h
|
qgsexpressionlineedit.h
|
||||||
@ -919,6 +921,7 @@ SET(QGIS_GUI_UI_HDRS
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgscredentialdialog.h
|
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgscredentialdialog.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h
|
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilderdialogbase.h
|
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilderdialogbase.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionstoredialogbase.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilder.h
|
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilder.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionselectiondialogbase.h
|
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionselectiondialogbase.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsfeaturefilterwidget.h
|
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsfeaturefilterwidget.h
|
||||||
|
@ -861,6 +861,7 @@ void QgsDualView::modifySort()
|
|||||||
expressionBuilder->setLayer( mLayer );
|
expressionBuilder->setLayer( mLayer );
|
||||||
expressionBuilder->loadFieldNames();
|
expressionBuilder->loadFieldNames();
|
||||||
expressionBuilder->loadRecent( QStringLiteral( "generic" ) );
|
expressionBuilder->loadRecent( QStringLiteral( "generic" ) );
|
||||||
|
expressionBuilder->loadStored( QStringLiteral( "generic" ) );
|
||||||
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() );
|
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() );
|
||||||
|
|
||||||
sortingGroupBox->layout()->addWidget( expressionBuilder );
|
sortingGroupBox->layout()->addWidget( expressionBuilder );
|
||||||
|
@ -33,6 +33,7 @@ QgsExpressionBuilderDialog::QgsExpressionBuilderDialog( QgsVectorLayer *layer, c
|
|||||||
builder->setExpressionText( startText );
|
builder->setExpressionText( startText );
|
||||||
builder->loadFieldNames();
|
builder->loadFieldNames();
|
||||||
builder->loadRecent( mRecentKey );
|
builder->loadRecent( mRecentKey );
|
||||||
|
builder->loadStored( mRecentKey );
|
||||||
|
|
||||||
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsExpressionBuilderDialog::showHelp );
|
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsExpressionBuilderDialog::showHelp );
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "qgsexpressioncontextutils.h"
|
#include "qgsexpressioncontextutils.h"
|
||||||
#include "qgsfieldformatterregistry.h"
|
#include "qgsfieldformatterregistry.h"
|
||||||
#include "qgsfieldformatter.h"
|
#include "qgsfieldformatter.h"
|
||||||
|
#include "qgsexpressionstoredialog.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -41,7 +42,7 @@
|
|||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QGraphicsOpacityEffect>
|
#include <QGraphicsOpacityEffect>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
|
QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
@ -61,6 +62,8 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
|
|||||||
connect( mValuesListView, &QListView::doubleClicked, this, &QgsExpressionBuilderWidget::mValuesListView_doubleClicked );
|
connect( mValuesListView, &QListView::doubleClicked, this, &QgsExpressionBuilderWidget::mValuesListView_doubleClicked );
|
||||||
connect( btnSaveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::storeCurrentExpression );
|
connect( btnSaveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::storeCurrentExpression );
|
||||||
connect( btnRemoveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::removeSelectedExpression );
|
connect( btnRemoveExpression, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::removeSelectedExpression );
|
||||||
|
connect( btnClearEditor, &QPushButton::pressed, txtExpressionString, &QgsCodeEditorExpression::clear );
|
||||||
|
|
||||||
txtHelpText->setOpenExternalLinks( true );
|
txtHelpText->setOpenExternalLinks( true );
|
||||||
|
|
||||||
mValueGroupBox->hide();
|
mValueGroupBox->hide();
|
||||||
@ -74,6 +77,13 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
|
|||||||
expressionTree->setSortingEnabled( true );
|
expressionTree->setSortingEnabled( true );
|
||||||
expressionTree->sortByColumn( 0, Qt::AscendingOrder );
|
expressionTree->sortByColumn( 0, Qt::AscendingOrder );
|
||||||
|
|
||||||
|
expressionTree->setSelectionMode( QAbstractItemView::SelectionMode::SingleSelection );
|
||||||
|
|
||||||
|
// Set icons for tool buttons
|
||||||
|
btnSaveExpression->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionFileSave.svg" ) ) );
|
||||||
|
btnRemoveExpression->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionDeleteSelected.svg" ) ) );
|
||||||
|
btnClearEditor->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionFileNew.svg" ) ) );
|
||||||
|
|
||||||
expressionTree->setContextMenuPolicy( Qt::CustomContextMenu );
|
expressionTree->setContextMenuPolicy( Qt::CustomContextMenu );
|
||||||
connect( this, &QgsExpressionBuilderWidget::expressionParsed, this, &QgsExpressionBuilderWidget::setExpressionState );
|
connect( this, &QgsExpressionBuilderWidget::expressionParsed, this, &QgsExpressionBuilderWidget::setExpressionState );
|
||||||
connect( expressionTree, &QWidget::customContextMenuRequested, this, &QgsExpressionBuilderWidget::showContextMenu );
|
connect( expressionTree, &QWidget::customContextMenuRequested, this, &QgsExpressionBuilderWidget::showContextMenu );
|
||||||
@ -250,6 +260,10 @@ void QgsExpressionBuilderWidget::currentChanged( const QModelIndex &index, const
|
|||||||
// Show the help for the current item.
|
// Show the help for the current item.
|
||||||
QString help = loadFunctionHelp( item );
|
QString help = loadFunctionHelp( item );
|
||||||
txtHelpText->setText( help );
|
txtHelpText->setText( help );
|
||||||
|
|
||||||
|
btnRemoveExpression->setEnabled( item->parent() &&
|
||||||
|
item->parent()->text() == mStoredGroupName );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsExpressionBuilderWidget::btnRun_pressed()
|
void QgsExpressionBuilderWidget::btnRun_pressed()
|
||||||
@ -594,12 +608,12 @@ void QgsExpressionBuilderWidget::loadRecent( const QString &collection )
|
|||||||
void QgsExpressionBuilderWidget::loadStored( const QString &collection )
|
void QgsExpressionBuilderWidget::loadStored( const QString &collection )
|
||||||
{
|
{
|
||||||
mRecentKey = collection;
|
mRecentKey = collection;
|
||||||
const QString groupName = tr( "Stored (%1)" ).arg( collection );
|
mStoredGroupName = tr( "Stored (%1)" ).arg( collection );
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
if ( mExpressionGroups.contains( groupName ) )
|
if ( mExpressionGroups.contains( mStoredGroupName ) )
|
||||||
{
|
{
|
||||||
QgsExpressionItem *node = mExpressionGroups.value( groupName );
|
QgsExpressionItem *node = mExpressionGroups.value( mStoredGroupName );
|
||||||
node->removeRows( 0, node->rowCount() );
|
node->removeRows( 0, node->rowCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,12 +624,13 @@ void QgsExpressionBuilderWidget::loadStored( const QString &collection )
|
|||||||
QString helpText;
|
QString helpText;
|
||||||
QString expression;
|
QString expression;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for ( const auto &label : settings.childGroups() )
|
mStoredLabels = settings.childGroups();
|
||||||
|
for ( const auto &label : qgis::as_const( mStoredLabels ) )
|
||||||
{
|
{
|
||||||
settings.beginGroup( label );
|
settings.beginGroup( label );
|
||||||
expression = settings.value( QStringLiteral( "expression" ) ).toString();
|
expression = settings.value( QStringLiteral( "expression" ) ).toString();
|
||||||
helpText = settings.value( QStringLiteral( "helpText" ) ).toString();
|
helpText = settings.value( QStringLiteral( "helpText" ) ).toString();
|
||||||
this->registerItem( groupName, label, expression, helpText, QgsExpressionItem::ExpressionNode, false, i++ );
|
this->registerItem( mStoredGroupName, label, expression, helpText, QgsExpressionItem::ExpressionNode, false, i++ );
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -629,6 +644,14 @@ void QgsExpressionBuilderWidget::saveToStored( const QString &label, const QStri
|
|||||||
settings.setValue( QStringLiteral( "expression" ), expression );
|
settings.setValue( QStringLiteral( "expression" ), expression );
|
||||||
settings.setValue( QStringLiteral( "helpText" ), helpText );
|
settings.setValue( QStringLiteral( "helpText" ), helpText );
|
||||||
this->loadStored( collection );
|
this->loadStored( collection );
|
||||||
|
// Scroll
|
||||||
|
const QModelIndexList idxs { expressionTree->model()->match( expressionTree->model()->index( 0, 0 ),
|
||||||
|
Qt::DisplayRole, label, 1,
|
||||||
|
Qt::MatchFlag::MatchRecursive ) };
|
||||||
|
if ( ! idxs.isEmpty() )
|
||||||
|
{
|
||||||
|
expressionTree->scrollTo( idxs.first() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsExpressionBuilderWidget::removeFromStored( const QString &name, const QString &collection )
|
void QgsExpressionBuilderWidget::removeFromStored( const QString &name, const QString &collection )
|
||||||
@ -771,6 +794,9 @@ void QgsExpressionBuilderWidget::txtExpressionString_textChanged()
|
|||||||
QString text = expressionText();
|
QString text = expressionText();
|
||||||
clearErrors();
|
clearErrors();
|
||||||
|
|
||||||
|
btnClearEditor->setEnabled( ! txtExpressionString->text().isEmpty() );
|
||||||
|
btnSaveExpression->setEnabled( false );
|
||||||
|
|
||||||
// If the string is empty the expression will still "fail" although
|
// If the string is empty the expression will still "fail" although
|
||||||
// we don't show the user an error as it will be confusing.
|
// we don't show the user an error as it will be confusing.
|
||||||
if ( text.isEmpty() )
|
if ( text.isEmpty() )
|
||||||
@ -838,6 +864,7 @@ void QgsExpressionBuilderWidget::txtExpressionString_textChanged()
|
|||||||
setParserError( false );
|
setParserError( false );
|
||||||
setEvalError( false );
|
setEvalError( false );
|
||||||
createMarkers( exp.rootNode() );
|
createMarkers( exp.rootNode() );
|
||||||
|
btnSaveExpression->setEnabled( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1201,21 +1228,34 @@ void QgsExpressionBuilderWidget::autosave()
|
|||||||
void QgsExpressionBuilderWidget::storeCurrentExpression()
|
void QgsExpressionBuilderWidget::storeCurrentExpression()
|
||||||
{
|
{
|
||||||
const QString expression { this->expressionText() };
|
const QString expression { this->expressionText() };
|
||||||
saveToStored( expression, expression, expression, mRecentKey );
|
QgsExpressionStoreDialog dlg { expression, expression, QString( ), mStoredLabels };
|
||||||
|
if ( dlg.exec() == QDialog::DialogCode::Accepted )
|
||||||
|
{
|
||||||
|
saveToStored( dlg.label(), dlg.expression(), dlg.helpText(), mRecentKey );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsExpressionBuilderWidget::removeSelectedExpression()
|
void QgsExpressionBuilderWidget::removeSelectedExpression()
|
||||||
{
|
{
|
||||||
QModelIndex idx { expressionTree->currentIndex() };
|
|
||||||
|
// Get the item
|
||||||
|
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
|
||||||
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
|
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
|
||||||
if ( !item )
|
if ( !item )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Don't handle the double-click if we are on a header node.
|
// Don't handle remove if we are on a header node or the parent
|
||||||
if ( item->getItemType() == QgsExpressionItem::Header )
|
// is not the stored group
|
||||||
|
if ( item->getItemType() == QgsExpressionItem::Header ||
|
||||||
|
( item->parent() && item->parent()->text() != mStoredGroupName ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
removeFromStored( item->text(), mRecentKey );
|
if ( QMessageBox::Yes == QMessageBox::question( this, tr( "Remove Stored Expression" ),
|
||||||
|
tr( "Do you really want to remove stored expressions '%1'?" ).arg( item->text() ),
|
||||||
|
QMessageBox::Yes | QMessageBox::No ) )
|
||||||
|
{
|
||||||
|
removeFromStored( item->text(), mRecentKey );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1281,10 +1321,6 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem *express
|
|||||||
return "<head><style>" + helpStylesheet() + "</style></head><body>" + helpContents + "</body>";
|
return "<head><style>" + helpStylesheet() + "</style></head><body>" + helpContents + "</body>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QgsExpressionItemSearchProxy::QgsExpressionItemSearchProxy()
|
QgsExpressionItemSearchProxy::QgsExpressionItemSearchProxy()
|
||||||
{
|
{
|
||||||
setFilterCaseSensitivity( Qt::CaseInsensitive );
|
setFilterCaseSensitivity( Qt::CaseInsensitive );
|
||||||
|
@ -497,6 +497,8 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
|
|||||||
QPointer< QgsProject > mProject;
|
QPointer< QgsProject > mProject;
|
||||||
bool mEvalError = true;
|
bool mEvalError = true;
|
||||||
bool mParserError = true;
|
bool mParserError = true;
|
||||||
|
QString mStoredGroupName;
|
||||||
|
QStringList mStoredLabels;
|
||||||
};
|
};
|
||||||
|
|
||||||
// clazy:excludeall=qstring-allocations
|
// clazy:excludeall=qstring-allocations
|
||||||
|
@ -59,6 +59,7 @@ QgsExpressionSelectionDialog::QgsExpressionSelectionDialog( QgsVectorLayer *laye
|
|||||||
mExpressionBuilder->setExpressionText( startText );
|
mExpressionBuilder->setExpressionText( startText );
|
||||||
mExpressionBuilder->loadFieldNames();
|
mExpressionBuilder->loadFieldNames();
|
||||||
mExpressionBuilder->loadRecent( QStringLiteral( "Selection" ) );
|
mExpressionBuilder->loadRecent( QStringLiteral( "Selection" ) );
|
||||||
|
mExpressionBuilder->loadStored( QStringLiteral( "Selection" ) );
|
||||||
|
|
||||||
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
|
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
|
||||||
mExpressionBuilder->setExpressionContext( context );
|
mExpressionBuilder->setExpressionContext( context );
|
||||||
|
33
src/gui/qgsexpressionstoredialog.cpp
Normal file
33
src/gui/qgsexpressionstoredialog.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "qgsexpressionstoredialog.h"
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QStyle>
|
||||||
|
|
||||||
|
QgsExpressionStoreDialog::QgsExpressionStoreDialog( const QString &label, const QString &expression, const QString &helpText, const QStringList &existingLabels, QWidget *parent )
|
||||||
|
: QDialog( parent )
|
||||||
|
, mExistingLabels( existingLabels )
|
||||||
|
{
|
||||||
|
setupUi( this );
|
||||||
|
mExpression->setText( expression );
|
||||||
|
mHelpText->setText( helpText );
|
||||||
|
connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsExpressionStoreDialog::accept );
|
||||||
|
connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsExpressionStoreDialog::reject );
|
||||||
|
mValidationError->hide();
|
||||||
|
mValidationError->setStyleSheet( QStringLiteral( "QLabel { color : red; }" ) );
|
||||||
|
QPushButton *saveBtn { buttonBox->button( QDialogButtonBox::StandardButton::Save ) };
|
||||||
|
saveBtn->setEnabled( false );
|
||||||
|
connect( mLabel, &QLineEdit::textChanged, this, [ = ]( const QString & text )
|
||||||
|
{
|
||||||
|
if ( mExistingLabels.contains( text ) )
|
||||||
|
{
|
||||||
|
mValidationError->show();
|
||||||
|
saveBtn->setEnabled( false );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mValidationError->hide();
|
||||||
|
saveBtn->setEnabled( true );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
mLabel->setText( label );
|
||||||
|
}
|
||||||
|
|
51
src/gui/qgsexpressionstoredialog.h
Normal file
51
src/gui/qgsexpressionstoredialog.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef QGSEXPRESSIONSTOREDIALOG_H
|
||||||
|
#define QGSEXPRESSIONSTOREDIALOG_H
|
||||||
|
|
||||||
|
#include "qgis_gui.h"
|
||||||
|
#include <QDialog>
|
||||||
|
#include "ui_qgsexpressionstoredialogbase.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \ingroup gui
|
||||||
|
* A generic dialog for editing expression text, label and help text.
|
||||||
|
* \since QGIS 3.12
|
||||||
|
*/
|
||||||
|
class GUI_EXPORT QgsExpressionStoreDialog : public QDialog, private Ui::QgsExpressionStoreDialogBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a QgsExpressionStoreDialog with given \a label, \a expression and \a helpText.
|
||||||
|
* \param existingLabels list of existing labels for unique label validation
|
||||||
|
* \param parent optional parent widget
|
||||||
|
*/
|
||||||
|
QgsExpressionStoreDialog( const QString &label,
|
||||||
|
const QString &expression,
|
||||||
|
const QString &helpText,
|
||||||
|
const QStringList &existingLabels,
|
||||||
|
QWidget *parent = nullptr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the expression text
|
||||||
|
*/
|
||||||
|
QString expression( ) { return mExpression->text( ); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the label text
|
||||||
|
*/
|
||||||
|
QString label() { return mLabel->text(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the help text
|
||||||
|
*/
|
||||||
|
QString helpText() { return mHelpText->toHtml(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QStringList mExistingLabels;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QGSEXPRESSIONSTOREDIALOG_H
|
@ -325,9 +325,25 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="btnSaveExpression">
|
<widget class="QToolButton" name="btnClearEditor">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Add the selected expression to the stored expressions</string>
|
<string>Clear the expression editor</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="btnSaveExpression">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Add current expression to stored expressions</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
@ -336,6 +352,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="btnRemoveExpression">
|
<widget class="QToolButton" name="btnRemoveExpression">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Removes selected expression from the stored expressions</string>
|
<string>Removes selected expression from the stored expressions</string>
|
||||||
</property>
|
</property>
|
||||||
|
82
src/ui/qgsexpressionstoredialogbase.ui
Normal file
82
src/ui/qgsexpressionstoredialogbase.ui
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>QgsExpressionStoreDialogBase</class>
|
||||||
|
<widget class="QDialog" name="QgsExpressionStoreDialogBase">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>395</width>
|
||||||
|
<height>211</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Store expression</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="lblLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Label</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="mLabel"/>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QTextEdit" name="mHelpText"/>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="lblHelpText">
|
||||||
|
<property name="text">
|
||||||
|
<string>Help text</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QgsCodeEditorExpression" name="mExpression" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="lblExpression">
|
||||||
|
<property name="text">
|
||||||
|
<string>Expression</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLabel" name="mValidationError">
|
||||||
|
<property name="text">
|
||||||
|
<string>A stored expression with this name already exists!</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsCodeEditorExpression</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qgscodeeditorexpression.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
x
Reference in New Issue
Block a user