Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Cantor
Commits
e1b80b8e
Commit
e1b80b8e
authored
Jul 12, 2020
by
Shubham .
Browse files
Add searching through index functionality
parent
23acd6ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/panelplugins/documentationpanel/documentationpanelwidget.cpp
View file @
e1b80b8e
...
...
@@ -25,7 +25,6 @@
#include <KLocalizedString>
#include <QComboBox>
#include <QCompleter>
#include <QDebug>
#include <QFrame>
#include <QGridLayout>
...
...
@@ -44,7 +43,7 @@
DocumentationPanelWidget
::
DocumentationPanelWidget
(
Cantor
::
Session
*
session
,
QWidget
*
parent
)
:
QWidget
(
parent
),
m_backend
(
QString
())
{
m_backend
=
session
->
backend
()
->
name
();
const
QString
fileName
=
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QLatin1String
(
"documentation/"
)
+
m_backend
+
QLatin1String
(
"/help.qhc"
));
const
QString
&
fileName
=
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QLatin1String
(
"documentation/"
)
+
m_backend
+
QLatin1String
(
"/help.qhc"
));
m_engine
=
new
QHelpEngine
(
fileName
,
this
);
...
...
@@ -71,11 +70,9 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
documentationSelector
->
addItem
(
QIcon
::
fromTheme
(
session
->
backend
()
->
icon
()),
m_backend
);
// real time searcher
QLineEdit
*
search
=
new
QLineEdit
(
this
);
search
->
setPlaceholderText
(
i18nc
(
"@info:placeholder"
,
"Search through keywords..."
));
search
->
setClearButtonEnabled
(
true
);
search
->
setCompleter
(
new
QCompleter
(
search
));
search
->
completer
()
->
setCaseSensitivity
(
Qt
::
CaseInsensitive
);
m_search
=
new
QLineEdit
(
this
);
m_search
->
setPlaceholderText
(
i18nc
(
"@info:placeholder"
,
"Search through keywords..."
));
m_search
->
setClearButtonEnabled
(
true
);
// Add a seperator
QFrame
*
seperator
=
new
QFrame
(
this
);
...
...
@@ -124,7 +121,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
QGridLayout
*
layout
=
new
QGridLayout
(
this
);
layout
->
addWidget
(
home
,
0
,
0
);
layout
->
addWidget
(
documentationSelector
,
0
,
1
);
layout
->
addWidget
(
search
,
0
,
2
);
layout
->
addWidget
(
m_
search
,
0
,
2
);
layout
->
addWidget
(
seperator
,
0
,
3
);
layout
->
addWidget
(
findPage
,
0
,
4
);
layout
->
addWidget
(
m_displayArea
,
1
,
0
,
2
,
0
);
...
...
@@ -161,6 +158,8 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
connect
(
m_engine
->
contentWidget
(),
&
QHelpContentWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
connect
(
m_index
,
&
QHelpIndexWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
//connect(m_search->completer(), QOverload<const QModelIndex&>::of(&QCompleter::activated), this, &DocumentationPanelWidget::changedSelection);
connect
(
m_search
,
&
QLineEdit
::
returnPressed
,
this
,
&
DocumentationPanelWidget
::
returnPressed
);
setSession
(
session
);
}
...
...
@@ -171,6 +170,7 @@ DocumentationPanelWidget::~DocumentationPanelWidget()
delete
m_textBrowser
;
delete
m_displayArea
;
delete
m_index
;
delete
m_search
;
}
void
DocumentationPanelWidget
::
setSession
(
Cantor
::
Session
*
session
)
...
...
@@ -182,9 +182,16 @@ void DocumentationPanelWidget::displayHelp(const QUrl& url)
{
m_textBrowser
->
load
(
url
);
m_textBrowser
->
show
();
}
void
DocumentationPanelWidget
::
returnPressed
()
{
const
QString
&
input
=
m_search
->
text
();
if
(
input
.
isEmpty
()
/*| input is not in indexwidget*/
)
return
;
const
QModelIndex
index
=
m_engine
->
indexWidget
()
->
currentIndex
();
const
QString
indexText
=
index
.
data
(
Qt
::
DisplayRole
).
toString
();
contextSensitiveHelp
(
input
);
}
void
DocumentationPanelWidget
::
contextSensitiveHelp
(
const
QString
&
keyword
)
...
...
@@ -200,9 +207,9 @@ void DocumentationPanelWidget::contextSensitiveHelp(const QString& keyword)
void
DocumentationPanelWidget
::
loadDocumentation
()
{
const
QString
backend
=
backendName
();
const
QString
fileName
=
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QLatin1String
(
"documentation/"
)
+
backend
+
QLatin1String
(
"/help.qch"
));
const
QString
nameSpace
=
QHelpEngineCore
::
namespaceName
(
fileName
);
const
QString
&
backend
=
backendName
();
const
QString
&
fileName
=
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QLatin1String
(
"documentation/"
)
+
backend
+
QLatin1String
(
"/help.qch"
));
const
QString
&
nameSpace
=
QHelpEngineCore
::
namespaceName
(
fileName
);
if
(
nameSpace
.
isEmpty
()
||
!
m_engine
->
registeredDocumentations
().
contains
(
nameSpace
))
{
...
...
src/panelplugins/documentationpanel/documentationpanelwidget.h
View file @
e1b80b8e
...
...
@@ -34,6 +34,7 @@ namespace Cantor
class
QHelpEngine
;
class
QHelpIndexWidget
;
class
QLineEdit
;
class
QStackedWidget
;
class
QUrl
;
class
QWebEngineView
;
...
...
@@ -62,12 +63,14 @@ class DocumentationPanelWidget : public QWidget
private
Q_SLOTS
:
void
displayHelp
(
const
QUrl
&
);
void
contextSensitiveHelp
(
const
QString
&
);
void
returnPressed
();
private:
QHelpEngine
*
m_engine
=
nullptr
;
QWebEngineView
*
m_textBrowser
=
nullptr
;
QStackedWidget
*
m_displayArea
=
nullptr
;
QHelpIndexWidget
*
m_index
=
nullptr
;
QLineEdit
*
m_search
=
nullptr
;
QString
m_backend
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment