Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit bf4faa2f authored by Burkhard Lück's avatar Burkhard Lück

Remove dead code (src/naturalqueryparser/) in baloo-widgets

dead code excluded from build 3 years ago with
https://cgit.kde.org/baloo-widgets.git/commit/src/CMakeLists.txt?id=99336acb306ec5cc2faaff376c10f6a9292fdd09
Commit log:
Do not build the NaturalQueryParser
It relies on Baloo::Term which Baloo is no longer exporting

Do not bother translators with obsolete translations since 04-2015

Differential Revision: https://phabricator.kde.org/D11530
parent 507cb3f6
#add_subdirectory(naturalqueryparser)
add_definitions(-DTRANSLATION_DOMAIN=\"baloowidgets5\")
add_subdirectory(filepropertiesplugin)
......@@ -16,9 +15,6 @@ set(widgets_SRCS
keditcommentdialog.cpp
metadatafilter.cpp
widgetfactory.cpp
#groupedlineedit.cpp
#querybuilder.cpp
#querybuildercompleter.cpp
filefetchjob.cpp
)
......@@ -38,7 +34,6 @@ target_link_libraries(KF5BalooWidgets
KF5::FileMetaData
KF5::WidgetsAddons
KF5::Baloo
#KF5::BalooNaturalQueryParser
KF5::CoreAddons
KF5::ConfigGui
)
......@@ -60,8 +55,6 @@ ecm_generate_headers(KF5BalooWidgets_CamelCase_HEADERS
TagWidget
FileMetaDataWidget
FileMetaDataConfigWidget
#QueryBuilder
#GroupedLineEdit
PREFIX baloo
REQUIRED_HEADERS KF5BalooWidgets_HEADERS
......
/* This file is part of the Baloo widgets collection
Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2.1 as published by the Free Software Foundation,
or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "groupedlineedit.h"
#include <QStyleOptionFrameV3>
#include <QFontMetrics>
#include <QApplication>
#include <QScrollBar>
#include <QTextDocument>
#include <QTextBlock>
#include <QTextLayout>
#include <QTextLine>
#include <QPainter>
#include <QPainterPath>
#include <QBrush>
#include <QColor>
#include <QPalette>
using namespace Baloo;
struct GroupedLineEdit::Private
{
struct Block {
int start;
int end;
};
QVector<Block> blocks;
QBrush base;
};
GroupedLineEdit::GroupedLineEdit(QWidget* parent)
: QPlainTextEdit(parent),
d(new Private)
{
setWordWrapMode(QTextOption::NoWrap);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
document()->setMaximumBlockCount(1);
// Use a transparent base, to make the rectangle visible
QPalette pal = palette();
d->base = pal.base();
pal.setBrush(QPalette::Base, Qt::transparent);
setPalette(pal);
}
GroupedLineEdit::~GroupedLineEdit()
{
delete d;
}
QString GroupedLineEdit::text() const
{
// Remove the block crosses from the text
return toPlainText();
}
int GroupedLineEdit::cursorPosition() const
{
return textCursor().positionInBlock();
}
void GroupedLineEdit::addBlock(int start, int end)
{
Private::Block block;
block.start = start;
block.end = end;
d->blocks.append(block);
viewport()->update();
}
void GroupedLineEdit::setCursorPosition(int position)
{
QTextCursor c = textCursor();
c.setPosition(position, QTextCursor::MoveAnchor);
setTextCursor(c);
}
void GroupedLineEdit::setText(const QString &text)
{
setPlainText(text);
}
void GroupedLineEdit::clear()
{
QPlainTextEdit::clear();
removeAllBlocks();
}
void GroupedLineEdit::selectAll()
{
QTextCursor c = textCursor();
c.select(QTextCursor::LineUnderCursor);
setTextCursor(c);
}
void GroupedLineEdit::removeAllBlocks()
{
d->blocks.clear();
viewport()->update();
}
QSize GroupedLineEdit::sizeHint() const
{
QSize rs(
40,
document()->findBlock(0).layout()->lineAt(0).height() +
document()->documentMargin() * 2 +
frameWidth() * 2
);
return rs;
}
QSize GroupedLineEdit::minimumSizeHint() const
{
return sizeHint();
}
void GroupedLineEdit::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
emit editingFinished();
return;
}
QPlainTextEdit::keyPressEvent(e);
}
void GroupedLineEdit::paintEvent(QPaintEvent *e)
{
static const unsigned char colors[] = {
0 , 87 , 174,
243, 195, 0 ,
0 , 179, 119,
235, 115, 49 ,
139, 179, 0 ,
85 , 87 , 83 ,
0 , 140, 0 ,
117, 81 , 26
};
QTextLine line = document()->findBlock(0).layout()->lineAt(0);
QPainter painter(viewport());
int color_index = 0;
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.fillRect(0, 0, viewport()->width(), viewport()->height(), d->base);
Q_FOREACH(const Private::Block &block, d->blocks) {
qreal start_x = line.cursorToX(block.start, QTextLine::Leading);
qreal end_x = line.cursorToX(block.end + 1, QTextLine::Leading);
QPainterPath path;
QRectF rectangle(
start_x - 1.0 - double(horizontalScrollBar()->value()),
1.0,
end_x - start_x + 2.0,
double(viewport()->height() - 2)
);
const unsigned char *c = colors + (color_index * 3);
QColor color(c[0], c[1], c[2]);
path.addRoundedRect(rectangle, 5.0, 5.0);
painter.setPen(color);
painter.setBrush(color.lighter(180));
painter.drawPath(path);
color_index = (color_index + 1) & 0x7; // Increment color_index, modulo 8 so that it does not overflow colors
}
QPlainTextEdit::paintEvent(e);
}
/* This file is part of the Baloo widgets collection
Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2.1 as published by the Free Software Foundation,
or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __GROUPEDLINEEDIT_H__
#define __GROUPEDLINEEDIT_H__
#include <QPlainTextEdit>
#include "widgets_export.h"
namespace Baloo {
/**
* \class GroupedLineEdit groupedlineedit.h baloo/groupedlineedit.h
* \brief Single-line text editor with grouped terms support
*
* This widget looks like a QLineEdit, but terms can be grouped in it. A group
* consists of terms drawn inside a rounded rectangle. Rectangles have different
* colors, that allow the user to recognize parts of the input. They can be
* nested.
*
* This widget can be used to show how a line can be tokenized or parsed. For
* instance, the QueryBuilder widget uses this widget to show the filters of a
* query, but a mail client can also use the control to highlight e-mail
* addresses.
*/
class BALOO_WIDGETS_EXPORT GroupedLineEdit : public QPlainTextEdit
{
Q_OBJECT
public:
explicit GroupedLineEdit(QWidget *parent = 0);
virtual ~GroupedLineEdit();
/**
* Text displayed in this control. Use this method instead of
* toPlainText() as it is garanteed that this method will return exactly
* what the user sees.
*/
QString text() const;
/**
* Current cursor position. The cursor position starts at 0 when the
* cursor is completely at the left of the control (for right-to-left
* languages) and goes to text().length() when the cursor is completely
* at the right of the control.
*/
int cursorPosition() const;
/**
* Set the cursor position
*
* \sa cursorPosition
*/
void setCursorPosition(int position);
/**
* Set the text dislayed by the control. Calling this method removes all
* the blocks.
*
* \sa text
* \sa removeAllBlocks
*/
void setText(const QString &text);
/**
* Clear the text and the blocks contained in the widget.
*/
void clear();
/**
* Select all the text present in the control.
*/
void selectAll();
/**
* Remove all the blocks that were present in the control. The text is
* not changed, but no block will be drawn any more.
*/
void removeAllBlocks();
/**
* Add a block to the control. A block represents a group and is
* identified by the indexes of the first and the last characters in it.
* These limits are inclusive.
*
* The control maintains a list of block colors, that are cycled through
* at each block insertion. If you want the blocks to always have the
* same color even if they are removed and then re-added, always add
* them in the same order.
*/
void addBlock(int start, int end);
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
Q_SIGNALS:
/**
* Signal triggered when the user presses Enter or Return in the control
*/
void editingFinished();
protected:
virtual void paintEvent(QPaintEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
private:
struct Private;
Private *d;
};
}
#endif
remove_definitions(-DTRANSLATION_DOMAIN)
add_definitions(-DTRANSLATION_DOMAIN=\"baloo_naturalqueryparser\")
set(QUERYPARSER_SRCS
completionproposal.cpp
pass_comparators.cpp
pass_dateperiods.cpp
pass_datevalues.cpp
pass_decimalvalues.cpp
pass_filenames.cpp
pass_filesize.cpp
pass_numbers.cpp
pass_periodnames.cpp
pass_properties.cpp
pass_propertyinfo.cpp
pass_splitunits.cpp
pass_subqueries.cpp
pass_typehints.cpp
patternmatcher.cpp
naturalqueryparser.cpp
naturalfilequeryparser.cpp
utils.cpp
)
add_library(KF5BalooNaturalQueryParser ${QUERYPARSER_SRCS})
add_library(KF5::BalooNaturalQueryParser ALIAS KF5BalooNaturalQueryParser)
target_link_libraries(KF5BalooNaturalQueryParser
KF5::Baloo
KF5::KDELibs4Support
KF5::FileMetaData
)
set_target_properties(KF5BalooNaturalQueryParser PROPERTIES
VERSION ${BALOO_WIDGETS_VERSION}
SOVERSION ${BALOO_WIDGETS_VERSION}
EXPORT_NAME BalooNaturalQueryParser
)
target_include_directories(KF5BalooNaturalQueryParser INTERFACE "$<INSTALL_INTERFACE:${KF5_INCLUDE_INSTALL_DIR}/BalooWidgets>")
generate_export_header(KF5BalooNaturalQueryParser BASE_NAME BALOO_NATURALQUERYPARSER EXPORT_FILE_NAME naturalqueryparser_export.h)
ecm_generate_headers(KF5BalooNaturalQueryParser_CamelCase_HEADERS
HEADER_NAMES
CompletionProposal
NaturalQueryParser
NaturalFileQueryParser
PREFIX baloo
REQUIRED_HEADERS KF5BalooNaturalQueryParser_HEADERS
)
install(TARGETS KF5BalooNaturalQueryParser EXPORT KF5BalooWidgetsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/naturalqueryparser_export.h
${KF5BalooNaturalQueryParser_HEADERS}
DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/BalooWidgets/baloo
COMPONENT Devel
)
install(FILES
${KF5BalooNaturalQueryParser_CamelCase_HEADERS}
DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/BalooWidgets/Baloo
COMPONENT Devel
)
add_subdirectory(autotests)
#! /usr/bin/env bash
$XGETTEXT `find . -name "*.cpp" | grep -v "/autotests/"` -o $podir/baloo_naturalqueryparser.pot
#
# Query Parser
#
set(queryParser_SRC naturalqueryparsertest.cpp)
ecm_add_test(naturalqueryparsertest.cpp
TEST_NAME "naturalqueryparsertest"
LINK_LIBRARIES Qt5::Test KF5::Baloo KF5BalooNaturalQueryParser
)
/*
* This file is part of the Baloo Query Parser
* Copyright (C) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "naturalqueryparsertest.h"
#include <Baloo/Query>
#include <Baloo/Term>
#include "../naturalfilequeryparser.h"
#include <qtest_kde.h>
#include <QtCore/QDateTime>
using namespace Baloo;
namespace QTest {
template<>
char *toString(const Query &query)
{
Query *q = const_cast<Query *>(&query); // query.toJSON does not modify query but is not marked const
return qstrdup(q->toJSON().constData());
}
}
void NaturalQueryParserTest::testSearchString()
{
QString search_string(QLatin1String("correct horse battery staple "));
QCOMPARE(
NaturalFileQueryParser::parseQuery(search_string).searchString(),
search_string
);
}
void NaturalQueryParserTest::testNumbers()
{
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("size > 1024")),
Query(Term(QLatin1String("size"), 1024LL, Term::Greater))
);
}
void NaturalQueryParserTest::testDecimal()
{
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("size > 1024.38")),
Query(Term(QLatin1String("size"), 1024.38, Term::Greater))
);
}
void NaturalQueryParserTest::testFilesize()
{
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("size > 2K")),
Query(Term(QLatin1String("size"), 2048, Term::Greater))
);
}
void NaturalQueryParserTest::testDatetime()
{
Query expected;
QDateTime now = QDateTime::currentDateTime();
// Today
expected.setDateFilter(now.date().year(), now.date().month(), now.date().day());
expected.setTerm(Term());
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("today")),
expected
);
// Yesterday
now = now.addDays(-1);
expected.setDateFilter(now.date().year(), now.date().month(), now.date().day());
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("yesterday")),
expected
);
// A specific date
expected.setDateFilter(2011, 1, 2);
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("January 2, 2011")),
expected
);
}
void NaturalQueryParserTest::testFilename()
{
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("\"*.txt\""), NaturalQueryParser::DetectFilenamePattern),
Query(Term(QLatin1String("filename"), QRegExp(QLatin1String("^.*\\\\.txt$")), Term::Contains))
);
}
void NaturalQueryParserTest::testTypehints()
{
Query expected;
expected.setType(QLatin1String("Email"));
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("emails")),
expected
);
}
void NaturalQueryParserTest::testReduction()
{
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("size > 2K and size < 3K")),
Query(Term(QLatin1String("size"), 2048, Term::Greater) && Term(QLatin1String("size"), 3072, Term::Less))
);
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("size > 2K or size < 3K")),
Query(Term(QLatin1String("size"), 2048, Term::Greater) || Term(QLatin1String("size"), 3072, Term::Less))
);
}
void NaturalQueryParserTest::testTags()
{
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("tagged as Important")),
Query(Term(QLatin1String("tags"), QLatin1String("Important"), Term::Contains))
);
}
void NaturalQueryParserTest::testPropertyInfo()
{
QCOMPARE(
NaturalFileQueryParser::parseQuery(QLatin1String("bitRate > 44000")),
Query(Term(QLatin1String("bitRate"), 44000, Term::Greater))
);
}
QTEST_KDEMAIN_CORE(NaturalQueryParserTest)
/*
* This file is part of the Baloo Query Parser
* Copyright (C) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef BALOO_NATURALQUERYPARSERTEST_H
#define BALOO_NATURALQUERYPARSERTEST_H
#include <QObject>
namespace Baloo {
class NaturalQueryParserTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testSearchString();
void testNumbers();
void testDecimal();
void testFilesize();
void testDatetime();
void testFilename();
void testTypehints();
void testReduction();
void testTags();
void testPropertyInfo();
};
}
#endif
/* This file is part of the Baloo query parser
Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2.1 as published by the Free Software Foundation,
or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.