QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsoptionsdialoghighlightwidget.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsoptionsdialoghighlightwidget.cpp
3
-------------------------------
4
Date : February 2018
5
Copyright : (C) 2018 Denis Rouzaud
6
Email : denis.rouzaud@gmail.com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgsoptionsdialoghighlightwidget.h
"
17
18
#include "
qgsfilterlineedit.h
"
19
#include "
qgsmessagebaritem.h
"
20
#include "
qgsoptionsdialoghighlightwidgetsimpl.h
"
21
22
#include <QCheckBox>
23
#include <QEvent>
24
#include <QGroupBox>
25
#include <QLabel>
26
#include <QLayout>
27
#include <QTableView>
28
#include <QTimer>
29
#include <QTreeView>
30
#include <QTreeWidget>
31
32
#include "moc_qgsoptionsdialoghighlightwidget.cpp"
33
34
QgsOptionsDialogHighlightWidget::QgsOptionsDialogHighlightWidget
( QWidget *
widget
)
35
:
mWidget
(
widget
)
36
{}
37
38
QgsOptionsDialogHighlightWidget
*
QgsOptionsDialogHighlightWidget::createWidget
( QWidget *
widget
)
39
{
40
QWidget *parent =
widget
;
41
while
( ( parent = parent->parentWidget() ) )
42
{
43
// do not register message bar content, items disappear and causes QGIS to crash
44
// do not register QgsFilterLineEdit's child widgets, the clear button might be deleted
45
if
( qobject_cast<QgsMessageBarItem *>( parent ) || qobject_cast<QgsFilterLineEdit *>( parent ) )
46
{
47
// return invalid widget
48
return
nullptr
;
49
}
50
}
51
52
if
(
dynamic_cast<
QgsOptionsDialogHighlightWidget
*
>
(
widget
) )
53
{
54
return
dynamic_cast<
QgsOptionsDialogHighlightWidget
*
>
(
widget
);
55
}
56
57
if
( qobject_cast<QLabel *>(
widget
) )
58
{
59
return
new
QgsOptionsDialogHighlightLabel
( qobject_cast<QLabel *>(
widget
) );
60
}
61
else
if
( qobject_cast<QCheckBox *>(
widget
) )
62
{
63
return
new
QgsOptionsDialogHighlightCheckBox
( qobject_cast<QCheckBox *>(
widget
) );
64
}
65
else
if
( qobject_cast<QAbstractButton *>(
widget
) )
66
{
67
return
new
QgsOptionsDialogHighlightButton
( qobject_cast<QAbstractButton *>(
widget
) );
68
}
69
else
if
( qobject_cast<QGroupBox *>(
widget
) )
70
{
71
return
new
QgsOptionsDialogHighlightGroupBox
( qobject_cast<QGroupBox *>(
widget
) );
72
}
73
else
if
( qobject_cast<QTreeView *>(
widget
) )
74
{
75
return
new
QgsOptionsDialogHighlightTree
( qobject_cast<QTreeView *>(
widget
) );
76
}
77
else
if
( qobject_cast<QTableView *>(
widget
) )
78
{
79
return
new
QgsOptionsDialogHighlightTable
( qobject_cast<QTableView *>(
widget
) );
80
}
81
else
82
{
83
// return invalid widget
84
return
nullptr
;
85
}
86
}
87
88
bool
QgsOptionsDialogHighlightWidget::searchHighlight
(
const
QString &text )
89
{
90
mSearchText = text;
91
bool
found =
false
;
92
93
if
( !
mWidget
)
94
return
found;
95
96
if
( mEventFilter )
97
{
98
mWidget
->removeEventFilter( mEventFilter );
99
delete
mEventFilter;
100
mEventFilter =
nullptr
;
101
}
102
103
if
( !text.isEmpty() )
104
{
105
found =
searchText
( mSearchText );
106
}
107
else
108
{
109
reset
();
110
mChangedStyle =
false
;
111
}
112
113
if
( mChangedStyle )
114
{
115
reset
();
116
mChangedStyle =
false
;
117
}
118
119
if
( found )
120
{
121
if
( !
mWidget
->isVisible() )
122
{
123
mEventFilter =
new
QgsOptionsDialogHighlightWidgetEventFilter
(
this
);
124
mWidget
->installEventFilter( mEventFilter );
125
}
126
else
127
{
128
mChangedStyle =
highlightText
( mSearchText );
129
}
130
}
131
132
return
found;
133
}
134
135
137
138
QgsOptionsDialogHighlightWidgetEventFilter::QgsOptionsDialogHighlightWidgetEventFilter(
QgsOptionsDialogHighlightWidget
*highlightWidget )
139
: QObject( highlightWidget->widget() )
140
, mHighlightWidget( highlightWidget )
141
{}
142
143
bool
QgsOptionsDialogHighlightWidgetEventFilter::eventFilter( QObject *obj, QEvent *event )
144
{
145
if
( event->type() == QEvent::Show && obj == mHighlightWidget->widget() )
146
{
147
mHighlightWidget->widget()->removeEventFilter(
this
);
148
// instead of catching the event and calling show again
149
// it might be better to use a timer to change the style
150
// after the widget is shown
151
#if 1
152
mHighlightWidget->widget()->show();
153
mHighlightWidget->mChangedStyle = mHighlightWidget->highlightText( mHighlightWidget->mSearchText );
154
return
true
;
155
#else
156
QTimer::singleShot( 500,
this
, [] { mChangedStyle = highlightText( mSearchText ); } );
157
#endif
158
}
159
return
QObject::eventFilter( obj, event );
160
}
161
QgsOptionsDialogHighlightButton
A highlight widget for buttons.
Definition
qgsoptionsdialoghighlightwidgetsimpl.h:86
QgsOptionsDialogHighlightCheckBox
A highlight widget for checkboxes.
Definition
qgsoptionsdialoghighlightwidgetsimpl.h:65
QgsOptionsDialogHighlightGroupBox
A highlight widget for group boxes.
Definition
qgsoptionsdialoghighlightwidgetsimpl.h:107
QgsOptionsDialogHighlightLabel
A highlight widget for labels.
Definition
qgsoptionsdialoghighlightwidgetsimpl.h:44
QgsOptionsDialogHighlightTable
A highlight widget for table widgets.
Definition
qgsoptionsdialoghighlightwidgetsimpl.h:154
QgsOptionsDialogHighlightTree
A highlight widget for trees.
Definition
qgsoptionsdialoghighlightwidgetsimpl.h:130
QgsOptionsDialogHighlightWidget
Container for a widget to be used to search text in the option dialog.
Definition
qgsoptionsdialoghighlightwidget.h:65
QgsOptionsDialogHighlightWidget::QgsOptionsDialogHighlightWidgetEventFilter
friend class QgsOptionsDialogHighlightWidgetEventFilter
Definition
qgsoptionsdialoghighlightwidget.h:120
QgsOptionsDialogHighlightWidget::reset
virtual void reset()=0
reset the style of the widgets to its original state
QgsOptionsDialogHighlightWidget::searchHighlight
bool searchHighlight(const QString &text)
search for a text pattern and highlight the widget if the text is found
Definition
qgsoptionsdialoghighlightwidget.cpp:88
QgsOptionsDialogHighlightWidget::mWidget
QPointer< QWidget > mWidget
Pointer to the widget.
Definition
qgsoptionsdialoghighlightwidget.h:117
QgsOptionsDialogHighlightWidget::searchText
virtual bool searchText(const QString &text)=0
Search for the text in the widget and return true if it was found.
QgsOptionsDialogHighlightWidget::highlightText
virtual bool highlightText(const QString &text)=0
Highlight the text in the widget.
QgsOptionsDialogHighlightWidget::createWidget
static QgsOptionsDialogHighlightWidget * createWidget(QWidget *widget)
create a highlight widget implementation for the proper widget type.
Definition
qgsoptionsdialoghighlightwidget.cpp:38
QgsOptionsDialogHighlightWidget::widget
QWidget * widget()
Returns the widget.
Definition
qgsoptionsdialoghighlightwidget.h:91
QgsOptionsDialogHighlightWidget::QgsOptionsDialogHighlightWidget
QgsOptionsDialogHighlightWidget(QWidget *widget=nullptr)
Constructor.
Definition
qgsoptionsdialoghighlightwidget.cpp:34
qgsfilterlineedit.h
qgsmessagebaritem.h
qgsoptionsdialoghighlightwidget.h
qgsoptionsdialoghighlightwidgetsimpl.h
Generated on
for QGIS API Documentation by
1.17.0