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();
215 QSizePolicy::Policy policy = QSizePolicy::Ignored;
217 policy = QSizePolicy::MinimumExpanding;
227 const int minimumTextLength = 3;
241 mOptListWidget->setRowHidden( r, text.length() >= minimumTextLength );
246 if ( rsw.first->searchHighlight( text.length() >= minimumTextLength ? text : QString() ) )
276 const auto constWidget =
mOptStackedWidget->widget( i )->findChildren<QWidget *>();
277 for ( QWidget *w : constWidget )
281 QMap<QWidget *, QgsOptionsDialogHighlightWidget *> customHighlightWidgets;
289 if ( customHighlightWidgets.contains( w ) )
291 shw = customHighlightWidgets.value( w );
300 QgsDebugMsgLevel( QStringLiteral(
"Registering: %1" ).arg( w->objectName() ), 4 );
328 QDialog::showEvent( e );
336 QDialog::paintEvent( e );
344 setWindowTitle( QStringLiteral(
"%1 | %2" ).arg(
mDialogTitle, curitem->text() ) );
363 int snapToIconWidth = iconWidth + 32;
366 mIconOnly = ( splitSizes.at( 0 ) <= snapToIconWidth );
369 int newWidth =
mOptListWidget->verticalScrollBar()->isVisible() ? iconWidth + 22 : iconWidth + 9;
377 splitSizes[1] = splitSizes.at( 1 ) - ( splitSizes.at( 0 ) - newWidth );
378 splitSizes[0] = newWidth;
405 if ( ( *it ).second == index )
414 QMessageBox::warning(
nullptr, tr(
"Missing Objects" ),
415 tr(
"Base options dialog could not be initialized.\n\n" 416 "Missing some of the .ui template objects:\n" )
417 +
" 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.
void resizeAlltabs(int index)
Resizes all tabs when the dialog is resized.
#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.