20 #include <QDialogButtonBox> 22 #include <QListWidget> 23 #include <QListWidgetItem> 24 #include <QMessageBox> 28 #include <QStackedWidget> 38 : QDialog( parent, fl )
39 , mOptsKey( settingsKey )
42 , mSettings( settings )
43 , mDelSettings( false )
78 if ( title.isEmpty() )
87 layout()->setContentsMargins( 0, 0, 0, 0 );
91 mOptListWidget = findChild<QListWidget *>( QStringLiteral(
"mOptionsListWidget" ) );
92 QFrame *optionsFrame = findChild<QFrame *>( QStringLiteral(
"mOptionsFrame" ) );
93 mOptStackedWidget = findChild<QStackedWidget *>( QStringLiteral(
"mOptionsStackedWidget" ) );
94 mOptSplitter = findChild<QSplitter *>( QStringLiteral(
"mOptionsSplitter" ) );
95 mOptButtonBox = findChild<QDialogButtonBox *>( QStringLiteral(
"buttonBox" ) );
96 QFrame *buttonBoxFrame = findChild<QFrame *>( QStringLiteral(
"mButtonBoxFrame" ) );
97 mSearchLineEdit = findChild<QgsFilterLineEdit *>( QStringLiteral(
"mSearchLineEdit" ) );
99 if ( !
mOptListWidget || !mOptStackedWidget || !mOptSplitter || !optionsFrame )
104 int size =
mSettings->value( QStringLiteral(
"/IconSize" ), 24 ).toInt();
108 mOptListWidget->setIconSize( QSize( size + iconBuffer, size + iconBuffer ) );
111 optionsFrame->layout()->setContentsMargins( 0, 3, 3, 3 );
112 QVBoxLayout *layout =
static_cast<QVBoxLayout *
>( optionsFrame->layout() );
114 if ( buttonBoxFrame )
116 buttonBoxFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
117 layout->insertWidget( layout->count() + 1, buttonBoxFrame );
119 else if ( mOptButtonBox )
127 disconnect( mOptButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
128 connect( mOptButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
129 disconnect( mOptButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
130 connect( mOptButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
136 if ( mSearchLineEdit )
138 mSearchLineEdit->setShowSearchIcon(
true );
166 if ( !title.isEmpty() )
179 mSettings->value( QStringLiteral(
"/Windows/%1/splitState" ).arg(
mOptsKey ) ).isNull() ? 150 : 16777215 );
181 int curIndx =
mSettings->value( QStringLiteral(
"/Windows/%1/tab" ).arg(
mOptsKey ), 0 ).toInt();
210 const int minimumTextLength = 3;
224 mOptListWidget->setRowHidden( r, text.length() >= minimumTextLength );
229 if ( rsw.first->searchHighlight( text.length() >= minimumTextLength ? text : QString() ) )
259 const auto constWidget =
mOptStackedWidget->widget( i )->findChildren<QWidget *>();
260 for ( QWidget *w : constWidget )
264 QMap<QWidget *, QgsOptionsDialogHighlightWidget *> customHighlightWidgets;
272 if ( customHighlightWidgets.contains( w ) )
274 shw = customHighlightWidgets.value( w );
283 QgsDebugMsgLevel( QStringLiteral(
"Registering: %1" ).arg( w->objectName() ), 4 );
311 QDialog::showEvent( e );
319 QDialog::paintEvent( e );
327 setWindowTitle( QStringLiteral(
"%1 | %2" ).arg(
mDialogTitle, curitem->text() ) );
346 int snapToIconWidth = iconWidth + 32;
349 mIconOnly = ( splitSizes.at( 0 ) <= snapToIconWidth );
352 int newWidth =
mOptListWidget->verticalScrollBar()->isVisible() ? iconWidth + 22 : iconWidth + 9;
360 splitSizes[1] = splitSizes.at( 1 ) - ( splitSizes.at( 0 ) - newWidth );
361 splitSizes[0] = newWidth;
388 if ( ( *it ).second == index )
397 QMessageBox::warning(
nullptr, tr(
"Missing Objects" ),
398 tr(
"Base options dialog could not be initialized.\n\n" 399 "Missing some of the .ui template objects:\n" )
400 +
" mOptionsListWidget,\n mOptionsStackedWidget,\n mOptionsSplitter,\n mOptionsListFrame",
void warnAboutMissingObjects()
Base class for widgets for pages included in the options dialog.
This class is a composition of two QSettings instances:
QList< QPair< QgsOptionsDialogHighlightWidget *, int > > mRegisteredSearchWidgets
QMap< QWidget *, QgsOptionsDialogHighlightWidget * > registeredHighlightWidgets()
Returns the registered highlight widgets used to search and highlight text in options dialogs...
void initOptionsBase(bool restoreUi=true, const QString &title=QString())
Set up the base ui connections for vertical tabs.
void paintEvent(QPaintEvent *e) override
void restoreOptionsBaseUi(const QString &title=QString())
Restore the base ui.
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings.
QgsFilterLineEdit * mSearchLineEdit
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings.
#define QgsDebugMsgLevel(str, level)
void searchText(const QString &text)
searchText searches for a text in all the pages of the stacked widget and highlight the results ...
virtual void optionsStackedWidget_WidgetRemoved(int index)
Remove tab and unregister widgets on page remove.
void showEvent(QShowEvent *e) override
void registerTextSearchWidgets()
register widgets in the dialog to search for text in it it is automatically called if a line edit has...
QDialogButtonBox * mOptButtonBox
void setSettings(QgsSettings *settings)
QPointer< QgsSettings > mSettings
QListWidget * mOptListWidget
QgsOptionsDialogBase(const QString &settingsKey, QWidget *parent=nullptr, Qt::WindowFlags fl=nullptr, QgsSettings *settings=nullptr)
Constructor.
virtual void updateOptionsListVerticalTabs()
Update tabs on the splitter move.
virtual void updateWindowTitle()
QStackedWidget * mOptStackedWidget
~QgsOptionsDialogBase() override
virtual void optionsStackedWidget_CurrentChanged(int index)
Select relevant tab on current page change.