Commit bcfd7f28 authored by Ahmad Samir's avatar Ahmad Samir

[Kilpper] Port QRegExp to QRegularExpression

Test Plan:
make && ctest
klipper still seems to work

Reviewers: #plasma, davidedmundson, apol, broulik

Reviewed By: apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27914
parent 17542416
......@@ -40,7 +40,7 @@ ClipCommandProcess::ClipCommandProcess(const ClipAction& action, const ClipComma
map.insert( QLatin1Char('f'), clip );
map.insert( QLatin1Char('F'), clip );
const QStringList matches = action.regExpMatches();
const QStringList matches = action.actionCapturedTexts();
// support only %0 and the first 9 matches...
const int numMatches = qMin(10, matches.count());
for ( int i = 0; i < numMatches; ++i ) {
......
......@@ -140,7 +140,7 @@ void ActionsWidget::updateActionItem( QTreeWidgetItem* item, ClipAction* action
// clear children if any
item->takeChildren();
item->setText( 0, action->regExp() );
item->setText( 0, action->actionRegexPattern() );
item->setText( 1, action->description() );
foreach (const ClipCommand& command, action->commands()) {
......
......@@ -321,7 +321,7 @@ void EditActionDialog::updateWidgets(int commandIdxToSelect)
return;
}
m_ui->leRegExp->setText(m_action->regExp());
m_ui->leRegExp->setText(m_action->actionRegexPattern());
m_ui->automatic->setChecked(m_action->automatic());
m_ui->leDescription->setText(m_action->description());
......@@ -340,7 +340,7 @@ void EditActionDialog::saveAction()
return;
}
m_action->setRegExp( m_ui->leRegExp->text() );
m_action->setActionRegexPattern( m_ui->leRegExp->text() );
m_action->setDescription( m_ui->leDescription->text() );
m_action->setAutomatic( m_ui->automatic->isChecked() );
......
......@@ -150,8 +150,9 @@ void KlipperPopup::rebuild( const QString& filter ) {
}
// We search case insensitive until one uppercased character appears in the search term
Qt::CaseSensitivity caseSens = (filter.toLower() == filter ? Qt::CaseInsensitive : Qt::CaseSensitive);
QRegExp filterexp( filter, caseSens );
QRegularExpression filterexp( filter, filter.toLower() == filter ?
QRegularExpression::CaseInsensitiveOption
: QRegularExpression::NoPatternOption );
QPalette palette = m_filterWidget->palette();
if ( filterexp.isValid() ) {
......
......@@ -18,7 +18,6 @@
*/
#include "popupproxy.h"
#include <QRegExp>
#include <QStyle>
#include <QPixmap>
#include <QStyleOption>
......@@ -29,7 +28,6 @@
#include "history.h"
#include "klipperpopup.h"
PopupProxy::PopupProxy( KlipperPopup* parent, int menu_height, int menu_width )
: QObject( parent ),
m_proxy_for_menu( parent ),
......@@ -64,7 +62,7 @@ void PopupProxy::deleteMoreMenus() {
}
}
int PopupProxy::buildParent( int index, const QRegExp& filter ) {
int PopupProxy::buildParent( int index, const QRegularExpression &filter ) {
deleteMoreMenus();
// Start from top of history (again)
m_spill_uuid = parent()->history()->empty() ? QByteArray() : parent()->history()->first()->uuid();
......@@ -154,7 +152,7 @@ int PopupProxy::insertFromSpill( int index ) {
return count;
}
do {
if ( m_filter.indexIn( item->text() ) != -1) {
if (m_filter.match(item->text()).hasMatch()) {
tryInsertItem( item.data(), remainingHeight, index++ );
count++;
}
......
......@@ -20,7 +20,7 @@
#define POPUPPROXY_H
#include <QObject>
#include <QRegExp>
#include <QRegularExpression>
#include "history.h"
......@@ -53,7 +53,7 @@ public:
* @param filter If non-empty, only insert items that match filter as a regex
* @return number of items inserted.
*/
int buildParent( int index, const QRegExp& filter = QRegExp() );
int buildParent( int index, const QRegularExpression &filter = QRegularExpression() );
public Q_SLOTS:
void slotAboutToShow();
......@@ -81,7 +81,7 @@ private:
private:
QMenu* m_proxy_for_menu;
QByteArray m_spill_uuid;
QRegExp m_filter;
QRegularExpression m_filter;
int m_menu_height;
int m_menu_width;
};
......
......@@ -28,6 +28,7 @@
#include <QUuid>
#include <QFile>
#include <QMenu>
#include <QRegularExpression>
#include <KLocalizedString>
#include <KService>
......@@ -162,10 +163,13 @@ const ActionList& URLGrabber::matchingActions( const QString& clipData, bool aut
matchingMimeActions(clipData);
// now look for matches in custom user actions
QRegularExpression re;
foreach (ClipAction* action, m_myActions) {
if ( action->matches( clipData ) && (action->automatic() || !automatically_invoked) ) {
re.setPattern(action->actionRegexPattern());
const QRegularExpressionMatch match = re.match(clipData);
if (match.hasMatch() && (action->automatic() || !automatically_invoked)) {
action->setActionCapturedTexts(match.capturedTexts());
m_myMatches.append( action );
}
}
......@@ -402,12 +406,12 @@ ClipCommand::ClipCommand(const QString&_command, const QString& _description,
ClipAction::ClipAction( const QString& regExp, const QString& description, bool automatic )
: m_myRegExp( regExp ), m_myDescription( description ), m_automatic(automatic)
: m_regexPattern( regExp ), m_myDescription( description ), m_automatic(automatic)
{
}
ClipAction::ClipAction( KSharedConfigPtr kc, const QString& group )
: m_myRegExp( kc->group(group).readEntry("Regexp") ),
: m_regexPattern( kc->group(group).readEntry("Regexp") ),
m_myDescription (kc->group(group).readEntry("Description") ),
m_automatic(kc->group(group).readEntry("Automatic", QVariant(true)).toBool() )
{
......@@ -459,7 +463,7 @@ void ClipAction::save( KSharedConfigPtr kc, const QString& group ) const
{
KConfigGroup cg(kc, group);
cg.writeEntry( "Description", description() );
cg.writeEntry( "Regexp", regExp() );
cg.writeEntry( "Regexp", actionRegexPattern() );
cg.writeEntry( "Number of commands", m_myCommands.count() );
cg.writeEntry( "Automatic", automatic() );
......
......@@ -20,7 +20,6 @@
#define URLGRABBER_H
#include <QHash>
#include <QRegExp>
#include <QStringList>
#include <QSharedPointer>
......@@ -145,12 +144,11 @@ public:
ClipAction( KSharedConfigPtr kc, const QString& );
~ClipAction();
void setRegExp( const QString& r) { m_myRegExp = QRegExp( r ); }
QString regExp() const { return m_myRegExp.pattern(); }
QString actionRegexPattern() const { return m_regexPattern; }
void setActionRegexPattern(const QString &pattern) { m_regexPattern = pattern; }
bool matches( const QString& string ) const { return ( m_myRegExp.indexIn( string ) != -1 ); }
QStringList regExpMatches() const { return m_myRegExp.capturedTexts(); }
QStringList actionCapturedTexts() const { return m_regexCapturedTexts; }
void setActionCapturedTexts(const QStringList &captured) { m_regexCapturedTexts = captured; }
void setDescription( const QString& d) { m_myDescription = d; }
QString description() const { return m_myDescription; }
......@@ -184,7 +182,8 @@ public:
private:
QRegExp m_myRegExp;
QString m_regexPattern;
QStringList m_regexCapturedTexts;
QString m_myDescription;
QList<ClipCommand> m_myCommands;
bool m_automatic;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment