20 #include <QDialogButtonBox>
22 #include <QListWidget>
23 #include <QListWidgetItem>
24 #include <QMessageBox>
28 #include <QStackedWidget>
39 : QDialog( parent, fl )
40 , mOptsKey( settingsKey )
43 , mSettings( settings )
44 , mDelSettings( false )
79 if ( title.isEmpty() )
86 if (
auto *lLayout = layout() )
88 lLayout->setContentsMargins( 0, 0, 0, 0 );
92 mOptListWidget = findChild<QListWidget *>( QStringLiteral(
"mOptionsListWidget" ) );
93 QFrame *optionsFrame = findChild<QFrame *>( QStringLiteral(
"mOptionsFrame" ) );
94 mOptStackedWidget = findChild<QStackedWidget *>( QStringLiteral(
"mOptionsStackedWidget" ) );
95 mOptSplitter = findChild<QSplitter *>( QStringLiteral(
"mOptionsSplitter" ) );
96 mOptButtonBox = findChild<QDialogButtonBox *>( QStringLiteral(
"buttonBox" ) );
97 QFrame *buttonBoxFrame = findChild<QFrame *>( QStringLiteral(
"mButtonBoxFrame" ) );
98 mSearchLineEdit = findChild<QgsFilterLineEdit *>( QStringLiteral(
"mSearchLineEdit" ) );
109 mOptListWidget->setIconSize( QSize( size + iconBuffer, size + iconBuffer ) );
113 optionsFrame->layout()->setContentsMargins( 0, frameMargin, frameMargin, frameMargin );
114 QVBoxLayout *layout =
static_cast<QVBoxLayout *
>( optionsFrame->layout() );
116 if ( buttonBoxFrame )
118 buttonBoxFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
119 layout->insertWidget( layout->count(), buttonBoxFrame );
129 disconnect(
mOptButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
130 connect(
mOptButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
131 disconnect(
mOptButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
132 connect(
mOptButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
168 if ( !title.isEmpty() )
183 mSettings->value( QStringLiteral(
"/Windows/%1/splitState" ).arg(
mOptsKey ) ).isNull() ? 150 : 16777215 );
196 l->setContentsMargins( 0, 0, 0, 0 );
203 int curIndx =
mSettings->value( QStringLiteral(
"/Windows/%1/tab" ).arg(
mOptsKey ), 0 ).toInt();
234 QSizePolicy::Policy policy = QSizePolicy::Ignored;
237 policy = QSizePolicy::MinimumExpanding;
257 if ( currentPage->objectName() == page )
268 QListWidgetItem *item =
new QListWidgetItem();
269 item->setIcon( icon );
270 item->setText( title );
271 item->setToolTip( tooltip );
283 if ( currentPage->objectName() == before )
287 QListWidgetItem *item =
new QListWidgetItem();
288 item->setIcon( icon );
289 item->setText( title );
290 item->setToolTip( tooltip );
299 addPage( title, tooltip, icon, widget );
304 const int minimumTextLength = 3;
318 mOptListWidget->setRowHidden( r, text.length() >= minimumTextLength );
323 if ( rsw.first->searchHighlight( text.length() >= minimumTextLength ? text : QString() ) )
353 const auto constWidget =
mOptStackedWidget->widget( i )->findChildren<QWidget *>();
354 for ( QWidget *w : constWidget )
358 QHash<QWidget *, QgsOptionsDialogHighlightWidget *> customHighlightWidgets;
366 if ( customHighlightWidgets.contains( w ) )
368 shw = customHighlightWidgets.value( w );
377 QgsDebugMsgLevel( QStringLiteral(
"Registering: %1" ).arg( w->objectName() ), 4 );
405 QDialog::showEvent( e );
413 QDialog::paintEvent( e );
421 setWindowTitle( QStringLiteral(
"%1 %2 %3" )
423 .arg( QChar( 0x2014 ) )
424 .arg( curitem->text() ) );
443 int snapToIconWidth = iconWidth + 32;
446 mIconOnly = ( splitSizes.at( 0 ) <= snapToIconWidth );
449 int newWidth =
mOptListWidget->verticalScrollBar()->isVisible() ? iconWidth + 22 : iconWidth + 9;
457 splitSizes[1] = splitSizes.at( 1 ) - ( splitSizes.at( 0 ) - newWidth );
458 splitSizes[0] = newWidth;
485 if ( ( *it ).second == index )
494 QMessageBox::warning(
nullptr, tr(
"Missing Objects" ),
495 tr(
"Base options dialog could not be initialized.\n\n"
496 "Missing some of the .ui template objects:\n" )
497 +
" mOptionsListWidget,\n mOptionsStackedWidget,\n mOptionsSplitter,\n mOptionsListFrame",
void setShowSearchIcon(bool visible)
Define if a search icon shall be shown on the left of the image when no text is entered.
virtual void updateWindowTitle()
QPointer< QgsSettings > mSettings
void warnAboutMissingObjects()
void resizeAlltabs(int index)
Resizes all tabs when the dialog is resized.
void insertPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QString &before)
Inserts a new page into the dialog pages.
void paintEvent(QPaintEvent *e) override
void restoreLastPage()
Refocus the active tab from the last time the dialog was shown.
void searchText(const QString &text)
searchText searches for a text in all the pages of the stacked widget and highlight the results
void registerTextSearchWidgets()
register widgets in the dialog to search for text in it it is automatically called if a line edit has...
virtual void optionsStackedWidget_CurrentChanged(int index)
Select relevant tab on current page change.
QList< QPair< QgsOptionsDialogHighlightWidget *, int > > mRegisteredSearchWidgets
~QgsOptionsDialogBase() override
QgsOptionsDialogBase(const QString &settingsKey, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags(), QgsSettings *settings=nullptr)
Constructor.
QgsFilterLineEdit * mSearchLineEdit
void addPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget)
Adds a new page to the dialog pages.
void setSettings(QgsSettings *settings)
virtual void optionsStackedWidget_WidgetRemoved(int index)
Remove tab and unregister widgets on page remove.
QDialogButtonBox * mOptButtonBox
virtual void updateOptionsListVerticalTabs()
Update tabs on the splitter move.
QListWidget * mOptListWidget
void restoreOptionsBaseUi(const QString &title=QString())
Restore the base ui.
QStackedWidget * mOptStackedWidget
void initOptionsBase(bool restoreUi=true, const QString &title=QString())
Set up the base ui connections for vertical tabs.
void showEvent(QShowEvent *e) override
void setCurrentPage(const QString &page)
Sets the dialog page (by object name) to show.
Base class for widgets for pages included in the options dialog.
QHash< QWidget *, QgsOptionsDialogHighlightWidget * > registeredHighlightWidgets()
Returns the registered highlight widgets used to search and highlight text in options dialogs.
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings.
#define QgsDebugMsgLevel(str, level)