Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
KDE PIM Add-ons
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PIM
KDE PIM Add-ons
Commits
3b70f2c3
Commit
3b70f2c3
authored
May 29, 2017
by
Laurent Montel
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use QToolButton. Optimization don't check all the time if we have kregexpeditor installed
parent
f4058bde
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
35 deletions
+64
-35
sieveeditor/regexeditorlineedit/autotests/regexpeditorlineedittest.cpp
...egexeditorlineedit/autotests/regexpeditorlineedittest.cpp
+8
-2
sieveeditor/regexeditorlineedit/regexpeditorlineedit.cpp
sieveeditor/regexeditorlineedit/regexpeditorlineedit.cpp
+46
-20
sieveeditor/regexeditorlineedit/regexpeditorlineedit.h
sieveeditor/regexeditorlineedit/regexpeditorlineedit.h
+3
-3
sieveeditor/regexeditorlineedit/tests/regexpeditorwidget.cpp
sieveeditor/regexeditorlineedit/tests/regexpeditorwidget.cpp
+7
-7
sieveeditor/regexeditorlineedit/tests/regexpeditorwidget.h
sieveeditor/regexeditorlineedit/tests/regexpeditorwidget.h
+0
-3
No files found.
sieveeditor/regexeditorlineedit/autotests/regexpeditorlineedittest.cpp
View file @
3b70f2c3
...
...
@@ -20,8 +20,9 @@
#include "regexpeditorlineedittest.h"
#include "../regexpeditorlineedit.h"
#include <QLineEdit>
#include <Q
Push
Button>
#include <Q
Tool
Button>
#include <QTest>
#include <QHBoxLayout>
RegexpEditorLineEditTest
::
RegexpEditorLineEditTest
(
QObject
*
parent
)
:
QObject
(
parent
)
...
...
@@ -32,11 +33,16 @@ RegexpEditorLineEditTest::RegexpEditorLineEditTest(QObject *parent)
void
RegexpEditorLineEditTest
::
shouldHaveDefaultValue
()
{
RegexpEditorLineEdit
w
;
QHBoxLayout
*
mainLayout
=
w
.
findChild
<
QHBoxLayout
*>
(
QStringLiteral
(
"mainlayout"
));
QVERIFY
(
mainLayout
);
QCOMPARE
(
mainLayout
->
margin
(),
0
);
QLineEdit
*
mLineEdit
=
w
.
findChild
<
QLineEdit
*>
(
QStringLiteral
(
"lineedit"
));
QVERIFY
(
mLineEdit
);
QVERIFY
(
mLineEdit
->
text
().
isEmpty
());
Q
PushButton
*
mRegExpEditorButton
=
w
.
findChild
<
QPush
Button
*>
(
QStringLiteral
(
"regexpbutton"
));
Q
ToolButton
*
mRegExpEditorButton
=
w
.
findChild
<
QTool
Button
*>
(
QStringLiteral
(
"regexpbutton"
));
QVERIFY
(
mRegExpEditorButton
);
QVERIFY
(
!
mRegExpEditorButton
->
text
().
isEmpty
());
QVERIFY
(
!
mRegExpEditorButton
->
toolTip
().
isEmpty
());
...
...
sieveeditor/regexeditorlineedit/regexpeditorlineedit.cpp
View file @
3b70f2c3
...
...
@@ -24,7 +24,7 @@
#include <QStackedWidget>
#include <QHBoxLayout>
#include <QLineEdit>
#include <Q
Push
Button>
#include <Q
Tool
Button>
#include <KLocalizedString>
#include <KServiceTypeTrader>
#include <QDialog>
...
...
@@ -36,27 +36,52 @@
K_PLUGIN_FACTORY_WITH_JSON
(
RegexpEditorLineEditFactory
,
"regexepeditorlineedit.json"
,
registerPlugin
<
RegexpEditorLineEdit
>
();
)
struct
InfoRegExp
{
InfoRegExp
()
:
status
(
Unknown
)
{
}
enum
RegexpEditorStatus
{
Unknown
=
0
,
Installed
,
NotInstalled
};
RegexpEditorStatus
status
;
};
Q_GLOBAL_STATIC
(
InfoRegExp
,
s_regexpeditorinstalled
)
RegexpEditorLineEdit
::
RegexpEditorLineEdit
(
QWidget
*
parent
,
const
QList
<
QVariant
>
&
)
:
KSieveUi
::
AbstractRegexpEditorLineEdit
(
parent
)
,
mEditorDialog
(
nullptr
)
,
mIsRegExpMode
(
false
)
,
mRegexEditorInstalled
(
false
)
{
QHBoxLayout
*
mainLayout
=
new
QHBoxLayout
(
this
);
mainLayout
->
setObjectName
(
QStringLiteral
(
"mainlayout"
));
mainLayout
->
setMargin
(
0
);
mLineEdit
=
new
QLineEdit
(
this
);
connect
(
mLineEdit
,
&
QLineEdit
::
textChanged
,
this
,
&
RegexpEditorLineEdit
::
textChanged
);
mLineEdit
->
setObjectName
(
QStringLiteral
(
"lineedit"
));
mainLayout
->
addWidget
(
mLineEdit
);
mRegExpEditorButton
=
new
QPushButton
(
i18n
(
"..."
),
this
);
mRegExpEditorButton
=
new
QToolButton
(
this
);
mRegExpEditorButton
->
setText
(
i18n
(
"..."
));
mRegExpEditorButton
->
setObjectName
(
QStringLiteral
(
"regexpbutton"
));
mRegExpEditorButton
->
setToolTip
(
i18n
(
"Create Regular Expression"
));
mainLayout
->
addWidget
(
mRegExpEditorButton
);
mRegexEditorInstalled
=
!
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"KRegExpEditor/KRegExpEditor"
)).
isEmpty
();
if
(
mRegexEditorInstalled
)
{
connect
(
mRegExpEditorButton
,
&
QPushButton
::
clicked
,
this
,
&
RegexpEditorLineEdit
::
slotOpenRegexpEditor
);
if
(
s_regexpeditorinstalled
->
status
==
InfoRegExp
::
Unknown
)
{
if
(
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"KRegExpEditor/KRegExpEditor"
)).
isEmpty
())
{
s_regexpeditorinstalled
->
status
=
InfoRegExp
::
NotInstalled
;
}
else
{
s_regexpeditorinstalled
->
status
=
InfoRegExp
::
Installed
;
}
}
if
(
s_regexpeditorinstalled
->
status
==
InfoRegExp
::
Installed
)
{
connect
(
mRegExpEditorButton
,
&
QToolButton
::
clicked
,
this
,
&
RegexpEditorLineEdit
::
slotOpenRegexpEditor
);
}
else
{
qCWarning
(
REGEXPEDITORLINEEDITPLUGIN_LOG
)
<<
"KRegExpEditor is not installed on system."
;
}
...
...
@@ -70,29 +95,30 @@ RegexpEditorLineEdit::~RegexpEditorLineEdit()
void
RegexpEditorLineEdit
::
slotOpenRegexpEditor
()
{
QString
error
;
if
(
!
mEditorDialog
)
{
QString
error
;
QDialog
*
editorDialog
=
KServiceTypeTrader
::
createInstanceFromQuery
<
QDialog
>
(
QStringLiteral
(
"KRegExpEditor/KRegExpEditor"
),
this
,
this
,
{},
{},
&
error
);
qDebug
()
<<
" editorDialog"
<<
editorDialog
;
if
(
editorDialog
)
{
KRegExpEditorInterface
*
iface
=
qobject_cast
<
KRegExpEditorInterface
*>
(
editorDialog
);
Q_ASSERT
(
iface
);
// This should not fail!
mEditorDialog
=
KServiceTypeTrader
::
createInstanceFromQuery
<
QDialog
>
(
QStringLiteral
(
"KRegExpEditor/KRegExpEditor"
),
this
,
this
,
{},
{},
&
error
);
if
(
!
mEditorDialog
)
{
qCWarning
(
REGEXPEDITORLINEEDITPLUGIN_LOG
)
<<
" Impossible to create regexpeditor "
<<
error
;
return
;
}
}
KRegExpEditorInterface
*
iface
=
qobject_cast
<
KRegExpEditorInterface
*>
(
mEditorDialog
);
Q_ASSERT
(
iface
);
// This should not fail!
// now use the editor.
iface
->
setRegExp
(
mLineEdit
->
text
());
// now use the editor.
iface
->
setRegExp
(
mLineEdit
->
text
());
if
(
editorDialog
->
exec
()
==
QDialog
::
Accepted
)
{
mLineEdit
->
setText
(
iface
->
regExp
());
}
}
else
{
qCWarning
(
REGEXPEDITORLINEEDITPLUGIN_LOG
)
<<
" Impossible to create regexpeditor "
<<
error
;
if
(
mEditorDialog
->
exec
()
==
QDialog
::
Accepted
)
{
mLineEdit
->
setText
(
iface
->
regExp
());
}
}
void
RegexpEditorLineEdit
::
switchToRegexpEditorLineEdit
(
bool
regexpEditor
)
{
mIsRegExpMode
=
regexpEditor
;
if
(
mRegexEditor
Installed
)
{
if
(
s_regexpeditorinstalled
->
status
==
InfoRegExp
::
Installed
)
{
mRegExpEditorButton
->
setVisible
(
mIsRegExpMode
);
}
}
...
...
sieveeditor/regexeditorlineedit/regexpeditorlineedit.h
View file @
3b70f2c3
...
...
@@ -23,7 +23,7 @@
#include <QWidget>
#include <KSieveUi/AbstractRegexpEditorLineEdit>
class
QLineEdit
;
class
Q
Push
Button
;
class
Q
Tool
Button
;
class
RegexpEditorLineEdit
:
public
KSieveUi
::
AbstractRegexpEditorLineEdit
{
Q_OBJECT
...
...
@@ -38,9 +38,9 @@ public:
private:
void
slotOpenRegexpEditor
();
QLineEdit
*
mLineEdit
;
QPushButton
*
mRegExpEditorButton
;
QToolButton
*
mRegExpEditorButton
;
QDialog
*
mEditorDialog
;
bool
mIsRegExpMode
;
bool
mRegexEditorInstalled
;
};
#endif // REGEXPEDITORLINEEDIT_H
sieveeditor/regexeditorlineedit/tests/regexpeditorwidget.cpp
View file @
3b70f2c3
...
...
@@ -27,13 +27,13 @@ RegExpEditorWidget::RegExpEditorWidget(QWidget *parent)
:
QWidget
(
parent
)
{
QVBoxLayout
*
layout
=
new
QVBoxLayout
(
this
);
QCheckBox
*
switchToRegexp
=
new
QCheckBox
(
QStringLiteral
(
"Switch to regexp line edit"
),
this
);
layout
->
addWidget
(
switchToRegexp
);
mLineEdit
=
new
RegexpEditorLineEdit
(
this
);
layout
->
addWidget
(
mLineEdit
);
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
QCheckBox
*
switchToRegexp
=
new
QCheckBox
(
QStringLiteral
(
"Switch to regexp line edit"
),
this
);
layout
->
addWidget
(
switchToRegexp
);
RegexpEditorLineEdit
*
lineEdit
=
new
RegexpEditorLineEdit
(
this
);
layout
->
addWidget
(
lineEdit
);
connect
(
switchToRegexp
,
&
QCheckBox
::
toggled
,
lineEdit
,
&
RegexpEditorLineEdit
::
switchToRegexpEditorLineEdit
);
}
layout
->
addStretch
(
1
);
connect
(
switchToRegexp
,
&
QCheckBox
::
toggled
,
mLineEdit
,
&
RegexpEditorLineEdit
::
switchToRegexpEditorLineEdit
);
}
sieveeditor/regexeditorlineedit/tests/regexpeditorwidget.h
View file @
3b70f2c3
...
...
@@ -21,15 +21,12 @@
#define REGEXPEDITORWIDGET_H
#include <QWidget>
class
RegexpEditorLineEdit
;
class
RegExpEditorWidget
:
public
QWidget
{
Q_OBJECT
public:
explicit
RegExpEditorWidget
(
QWidget
*
parent
=
nullptr
);
~
RegExpEditorWidget
()
=
default
;
private:
RegexpEditorLineEdit
*
mLineEdit
;
};
#endif // REGEXPEDITORWIDGET_H
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