Skip to content

Commit 57e718a

Browse files
Merge branch 'feature/chapters_treeview'
2 parents 0ee51d8 + 6c5e84b commit 57e718a

40 files changed

Lines changed: 7786 additions & 151 deletions

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ endif()
2626

2727

2828
# Create a set of sanitizers
29-
string(CONCAT LIBRUM_SANITIZERS "-fsanitize=address,undefined,shift,integer-divide-by-zero,"
29+
string(CONCAT LIBRUM_SANITIZERS #[["-fsanitize=address,undefined,shift,integer-divide-by-zero,"
3030
"float-divide-by-zero,unreachable,vla-bound,null,return,leak,"
31-
"bounds,float-cast-overflow,enum")
31+
"bounds,float-cast-overflow,enum"]])
3232

3333

3434
# Dependencies

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_AUTORCC ON)
66

77

88
# Configuration
9-
set(QML_IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/presentation/modules;${CMAKE_CURRENT_BINARY_DIR}/" CACHE STRING "Qml modules")
9+
set(QML_IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/presentation/modules ${CMAKE_CURRENT_BINARY_DIR}/" CACHE STRING "Qml modules")
1010

1111

1212
# Dependencies

src/adapters/controllers/book_controller.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ using namespace dtos;
1515

1616
BookController::BookController(application::IBookService* bookService) :
1717
m_bookService(bookService),
18-
m_libraryModel(m_bookService->getBooks()),
19-
m_libraryProxyModel(static_cast<QObject*>(&m_libraryModel))
18+
m_libraryModel(m_bookService->getBooks())
2019
{
2120
// book insertion
2221
connect(m_bookService, &application::IBookService::bookInsertionStarted,

src/adapters/data_models/library_model/library_proxy_model.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ std::optional<bool> LibraryProxyModel::fuzzCompareBooks(
8989

9090
double LibraryProxyModel::fuzzCompareWithSortingString(QString str) const
9191
{
92-
// If the sorting string is a substring of str, return a high ratio
92+
// If the sorting string is a sub-string of str, return a high ratio
9393
auto leftSubstrPos = str.toLower().indexOf(m_sortString.toLower());
9494
if(leftSubstrPos != -1)
9595
{
9696
// The further at the front, the better the ratio should be
9797
double ratio = 100 - leftSubstrPos;
98-
// A difference in lentgh of the strings should reduce the score
98+
// A difference in length of the strings should reduce the score
9999
ratio -= std::abs(str.length() - m_sortString.length()) * 0.1;
100100

101101
return ratio;
@@ -188,7 +188,8 @@ bool LibraryProxyModel::stringIsLexicographicallyLess(
188188
{
189189
if(left.isEmpty())
190190
return false;
191-
else if(right.isEmpty())
191+
192+
if(right.isEmpty())
192193
return true;
193194

194195
return left.toLower() < right.toLower();
@@ -207,7 +208,8 @@ bool LibraryProxyModel::openedAfter(const QModelIndex& left,
207208

208209
if(!lhsLastOpenedDate.isValid())
209210
return false;
210-
else if(!rhsLastOpenedDate.isValid())
211+
212+
if(!rhsLastOpenedDate.isValid())
211213
return true;
212214

213215
return lhsLastOpenedDate > rhsLastOpenedDate;
@@ -226,7 +228,8 @@ bool LibraryProxyModel::addedToLibraryAfter(const QModelIndex& left,
226228

227229
if(!lhsAddedDate.isValid())
228230
return false;
229-
else if(!rhsAddedDate.isValid())
231+
232+
if(!rhsAddedDate.isValid())
230233
return true;
231234

232235
return lhsAddedDate > rhsAddedDate;

src/application/core/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,20 @@ set(okularpart_SRCS
458458
gui/pagepainter.cpp
459459
gui/signatureguiutils.cpp
460460
gui/signaturemodel.cpp
461-
gui/tocmodel.cpp)
461+
gui/filtered_tocmodel.cpp
462+
gui/tocmodel.cpp
463+
)
462464

463465

464466
kconfig_add_kcfg_files(okularpart_SRCS GENERATE_MOC conf/settings.kcfgc)
465467

466468
add_library(okularpart SHARED ${okularpart_SRCS})
469+
target_compile_options(okularpart PRIVATE -fexceptions)
467470
generate_export_header(okularpart BASE_NAME okularpart)
468471

469472
target_link_libraries(okularpart
470473
okularcore
474+
rapidfuzz::rapidfuzz
471475
${MATH_LIB}
472476
Qt5::Svg
473477
Phonon::phonon4qt5
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "filtered_tocmodel.hpp"
2+
#include <algorithm>
3+
#include <rapidfuzz/fuzz.hpp>
4+
5+
namespace Okular
6+
{
7+
8+
FilteredTOCModel::FilteredTOCModel(QObject* parent) :
9+
QSortFilterProxyModel { parent }
10+
{
11+
}
12+
13+
bool FilteredTOCModel::filterAcceptsRow(int row,
14+
const QModelIndex& parent) const
15+
{
16+
auto index = sourceModel()->index(row, 0, parent);
17+
auto name = sourceModel()->data(index, Qt::ToolTipRole);
18+
19+
auto x = sourceModel()->index(row, 0, parent);
20+
TOCItem* item = static_cast<TOCItem*>(x.internalPointer());
21+
if(item != nullptr && hasChildrenMatchingTheFilter(item))
22+
return true;
23+
24+
auto similarity = fuzzCompareWithFilterString(name.toString());
25+
double minSimilarity = 70;
26+
27+
return similarity >= minSimilarity;
28+
}
29+
30+
void FilteredTOCModel::setFilterString(QString filterString)
31+
{
32+
m_filterString = filterString;
33+
invalidateFilter();
34+
}
35+
36+
QString FilteredTOCModel::getFilterString()
37+
{
38+
return m_filterString;
39+
}
40+
41+
bool FilteredTOCModel::hasChildrenMatchingTheFilter(const TOCItem* item) const
42+
{
43+
if(itemPassesFilter(item))
44+
return true;
45+
46+
return std::any_of(item->children.begin(), item->children.end(),
47+
[this](const TOCItem* child)
48+
{
49+
return hasChildrenMatchingTheFilter(child);
50+
});
51+
}
52+
53+
bool FilteredTOCModel::itemPassesFilter(const TOCItem* item) const
54+
{
55+
auto similarity = fuzzCompareWithFilterString(item->text);
56+
double minSimilarity = 70;
57+
58+
return similarity >= minSimilarity;
59+
}
60+
61+
double FilteredTOCModel::fuzzCompareWithFilterString(QString str) const
62+
{
63+
// If the sorting string is a sub-string of str, return a high ratio
64+
auto leftSubstrPos = str.toLower().indexOf(m_filterString.toLower());
65+
if(leftSubstrPos != -1)
66+
{
67+
// The further at the front, the better the ratio should be
68+
double ratio = 100 - leftSubstrPos;
69+
// A difference in length of the strings should reduce the score
70+
ratio -= std::abs(str.length() - m_filterString.length()) * 0.1;
71+
72+
return ratio;
73+
}
74+
75+
return rapidfuzz::fuzz::ratio(m_filterString.toStdString(),
76+
str.toStdString());
77+
}
78+
79+
} // namespace Okular
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
#include <QSortFilterProxyModel>
3+
#include "tocmodel.h"
4+
#include <QString>
5+
#include <QObject>
6+
7+
namespace Okular
8+
{
9+
10+
class Q_DECL_EXPORT FilteredTOCModel : public QSortFilterProxyModel
11+
{
12+
Q_OBJECT
13+
Q_PROPERTY(QString filterString READ getFilterString WRITE setFilterString
14+
NOTIFY filterStringUpdated)
15+
16+
public:
17+
explicit FilteredTOCModel(QObject* parent = nullptr);
18+
19+
bool filterAcceptsRow(int row,
20+
const QModelIndex& parent) const override;
21+
void setFilterString(QString filterString);
22+
QString getFilterString();
23+
24+
Q_SIGNALS:
25+
void filterStringUpdated();
26+
27+
private:
28+
// Recursively check if the item or any of its children match the filter
29+
bool hasChildrenMatchingTheFilter(const TOCItem* item) const;
30+
bool itemPassesFilter(const TOCItem* item) const;
31+
double fuzzCompareWithFilterString(QString str) const;
32+
33+
QString m_filterString;
34+
};
35+
36+
} // namespace Okular

src/application/core/gui/tocmodel.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,6 @@
1515

1616
Q_DECLARE_METATYPE(QModelIndex)
1717

18-
struct TOCItem
19-
{
20-
TOCItem();
21-
TOCItem(TOCItem* parent, const QDomElement& e);
22-
~TOCItem();
23-
24-
TOCItem(const TOCItem&) = delete;
25-
TOCItem& operator=(const TOCItem&) = delete;
26-
27-
QString text;
28-
Okular::DocumentViewport viewport;
29-
QString extFileName;
30-
QString url;
31-
bool highlight : 1;
32-
TOCItem* parent;
33-
QList<TOCItem*> children;
34-
TOCModelPrivate* model;
35-
};
36-
3718
class TOCModelPrivate
3819
{
3920
public:

src/application/core/gui/tocmodel.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
/*
2-
SPDX-FileCopyrightText: 2007 Pino Toscano <pino@kde.org>
3-
4-
SPDX-License-Identifier: GPL-2.0-or-later
5-
*/
6-
71
#ifndef TOCMODEL_H
82
#define TOCMODEL_H
93

104
#include <QAbstractItemModel>
5+
#include <QDomDocument>
6+
#include <QDomElement>
117
#include <QVector>
8+
#include "core/document.h"
129

1310
namespace Okular
1411
{
@@ -83,4 +80,23 @@ class Q_DECL_EXPORT TOCModel : public QAbstractItemModel
8380
const QModelIndex& parentB = QModelIndex()) const;
8481
};
8582

83+
struct Q_DECL_EXPORT TOCItem
84+
{
85+
TOCItem();
86+
TOCItem(TOCItem* parent, const QDomElement& e);
87+
~TOCItem();
88+
89+
TOCItem(const TOCItem&) = delete;
90+
TOCItem& operator=(const TOCItem&) = delete;
91+
92+
QString text;
93+
Okular::DocumentViewport viewport;
94+
QString extFileName;
95+
QString url;
96+
bool highlight : 1;
97+
TOCItem* parent;
98+
QList<TOCItem*> children;
99+
TOCModelPrivate* model;
100+
};
101+
86102
#endif

src/infrastructure/data/endpoints.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace infrastructure::data
66
// clang-format off
77

88

9-
inline const QString baseUrl { "https://localhost:7084" };
9+
inline const QString baseUrl { "https://librum-dev.azurewebsites.net" };
1010

1111
// Authentication
1212
inline const QString authenticationEndpoint { baseUrl + "/api/login" };

0 commit comments

Comments
 (0)