Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Utilities
KTrip
Commits
76e159a3
Commit
76e159a3
authored
Aug 07, 2019
by
Nicolas Fella
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use LocationQueryModel from KPT
parent
5a474fc7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
27 additions
and
151 deletions
+27
-151
src/CMakeLists.txt
src/CMakeLists.txt
+0
-1
src/locationquerymodel.cpp
src/locationquerymodel.cpp
+0
-86
src/locationquerymodel.h
src/locationquerymodel.h
+0
-57
src/main.cpp
src/main.cpp
+2
-2
src/qml/ConnectionDetailsPage.qml
src/qml/ConnectionDetailsPage.qml
+2
-0
src/qml/LocationQueryPage.qml
src/qml/LocationQueryPage.qml
+12
-5
src/querycontroller.cpp
src/querycontroller.cpp
+8
-0
src/querycontroller.h
src/querycontroller.h
+3
-0
No files found.
src/CMakeLists.txt
View file @
76e159a3
...
...
@@ -3,7 +3,6 @@ add_subdirectory(dateandtime)
set
(
ktrip_SRCS
main.cpp
querycontroller.cpp
locationquerymodel.cpp
locationcache.cpp
formatter.cpp
)
...
...
src/locationquerymodel.cpp
deleted
100644 → 0
View file @
5a474fc7
/**
* Copyright 2019 Nicolas Fella <nicolas.fella@gmx.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "locationquerymodel.h"
#include <KPublicTransport/LocationRequest>
#include <KPublicTransport/LocationReply>
LocationQueryModel
::
LocationQueryModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
),
m_manager
()
{
connect
(
this
,
&
LocationQueryModel
::
queryChanged
,
this
,
&
LocationQueryModel
::
triggerQuery
);
}
void
LocationQueryModel
::
triggerQuery
()
{
KPublicTransport
::
LocationRequest
request
;
request
.
setName
(
m_query
);
const
KPublicTransport
::
LocationReply
*
reply
=
m_manager
.
queryLocation
(
request
);
connect
(
reply
,
&
KPublicTransport
::
LocationReply
::
finished
,
this
,
[
this
,
reply
]
{
beginResetModel
();
m_locations
=
reply
->
result
();
endResetModel
();
});
}
QVariant
LocationQueryModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
!
index
.
isValid
()
||
index
.
row
()
<
0
||
index
.
row
()
>=
rowCount
())
{
return
QVariant
();
}
switch
(
role
)
{
case
NameRole
:
return
m_locations
[
index
.
row
()].
name
();
case
ObjectRole
:
return
QVariant
::
fromValue
(
m_locations
[
index
.
row
()]);
default:
return
QVariant
(
QStringLiteral
(
"deadbeef"
));
}
}
QString
LocationQueryModel
::
query
()
const
{
return
m_query
;
}
int
LocationQueryModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
return
m_locations
.
size
();
}
void
LocationQueryModel
::
setQuery
(
const
QString
query
)
{
if
(
m_query
!=
query
)
{
m_query
=
query
;
Q_EMIT
queryChanged
();
}
}
QHash
<
int
,
QByteArray
>
LocationQueryModel
::
roleNames
()
const
{
QHash
<
int
,
QByteArray
>
names
=
QAbstractItemModel
::
roleNames
();
names
.
insert
(
NameRole
,
"name"
);
names
.
insert
(
ObjectRole
,
"object"
);
return
names
;
}
src/locationquerymodel.h
deleted
100644 → 0
View file @
5a474fc7
/**
* Copyright 2019 Nicolas Fella <nicolas.fella@gmx.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QObject>
#include <QAbstractListModel>
#include <QVariant>
#include <KPublicTransport/Manager>
#include <KPublicTransport/Location>
class
LocationQueryModel
:
public
QAbstractListModel
{
Q_OBJECT
Q_PROPERTY
(
QString
query
READ
query
WRITE
setQuery
NOTIFY
queryChanged
)
public:
enum
Roles
{
NameRole
=
Qt
::
DisplayRole
,
ObjectRole
=
Qt
::
UserRole
+
1
};
explicit
LocationQueryModel
(
QObject
*
parent
=
nullptr
);
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
QHash
<
int
,
QByteArray
>
roleNames
()
const
override
;
QString
query
()
const
;
void
setQuery
(
const
QString
query
);
Q_SIGNALS:
void
queryChanged
();
private
Q_SLOTS
:
void
triggerQuery
();
private:
KPublicTransport
::
Manager
m_manager
;
QString
m_query
;
std
::
vector
<
KPublicTransport
::
Location
>
m_locations
;
};
src/main.cpp
View file @
76e159a3
...
...
@@ -19,7 +19,6 @@
*/
#include "androidutils.h"
#include "locationquerymodel.h"
#include "querycontroller.h"
#include "locationcache.h"
#include "formatter.h"
...
...
@@ -34,6 +33,7 @@
#endif
#include <KPublicTransport/Manager>
#include <KPublicTransport/LocationRequest>
#include <KLocalizedContext>
#ifdef Q_OS_ANDROID
...
...
@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
QQmlApplicationEngine
engine
(
QUrl
(
QStringLiteral
(
"qrc:/qml/main.qml"
)));
engine
.
rootContext
()
->
setContextObject
(
new
KLocalizedContext
(
&
engine
));
q
ml
RegisterType
<
LocationQueryModel
>
(
"org.kde.ktrip"
,
0
,
1
,
"LocationQueryModel"
);
qRegister
Meta
Type
<
KPublicTransport
::
LocationRequest
>
(
);
QueryController
queryController
;
engine
.
rootContext
()
->
setContextProperty
(
QStringLiteral
(
"_queryController"
),
&
queryController
);
...
...
src/qml/ConnectionDetailsPage.qml
View file @
76e159a3
...
...
@@ -109,6 +109,7 @@ Kirigami.Page
}
RowLayout
{
width
:
parent
.
width
Label
{
text
:
theData
.
scheduledArrivalTime
.
toLocaleTimeString
(
Locale
.
ShortFormat
)
}
...
...
@@ -126,6 +127,7 @@ Kirigami.Page
Label
{
text
:
theData
.
scheduledArrivalPlatform
}
}
...
...
src/qml/LocationQueryPage.qml
View file @
76e159a3
...
...
@@ -23,6 +23,7 @@ import QtQuick.Layouts 1.1
import
QtQuick
.
Controls
2.4
import
org
.
kde
.
kirigami
2.8
as
Kirigami
import
org
.
kde
.
ktrip
0.1
import
org
.
kde
.
kpublictransport
1.0
as
KPT
Kirigami.Page
{
...
...
@@ -32,7 +33,7 @@ Kirigami.Page
header
:
Kirigami.SearchField
{
id
:
queryTextField
onAccepted
:
{
queryModel
.
que
ry
=
text
queryModel
.
re
que
st
=
_queryController
.
createLocationRequest
(
text
)
showCached
=
false
}
}
...
...
@@ -53,8 +54,9 @@ Kirigami.Page
}
}
LocationQueryModel
{
KPT.
LocationQueryModel
{
id
:
queryModel
manager
:
_manager
}
ListView
{
...
...
@@ -63,14 +65,19 @@ Kirigami.Page
model
:
queryModel
delegate
:
Kirigami.BasicListItem
{
text
:
name
text
:
location
.
name
reserveSpaceForIcon
:
false
onClicked
:
{
_locationCache
.
addCachedLocation
(
object
)
callback
(
object
)
_locationCache
.
addCachedLocation
(
location
)
callback
(
location
)
pageStack
.
pop
()
}
}
}
BusyIndicator
{
running
:
queryModel
.
loading
anchors.centerIn
:
parent
}
}
src/querycontroller.cpp
View file @
76e159a3
...
...
@@ -93,3 +93,11 @@ void QueryController::setDepartureTime(const QString &time)
Q_EMIT
departureTimeChanged
();
}
}
KPublicTransport
::
LocationRequest
QueryController
::
createLocationRequest
(
const
QString
name
)
{
KPublicTransport
::
LocationRequest
req
;
req
.
setName
(
name
);
return
req
;
}
src/querycontroller.h
View file @
76e159a3
...
...
@@ -21,8 +21,10 @@
#pragma once
#include <QObject>
#include <QVariant>
#include <KPublicTransport/Location>
#include <KPublicTransport/LocationRequest>
#include <KPublicTransport/JourneyRequest>
class
QueryController
:
public
QObject
...
...
@@ -50,6 +52,7 @@ public:
void
setDepartureTime
(
const
QString
&
time
);
Q_INVOKABLE
KPublicTransport
::
JourneyRequest
createJourneyRequest
();
Q_INVOKABLE
KPublicTransport
::
LocationRequest
createLocationRequest
(
const
QString
name
);
Q_SIGNALS:
void
startChanged
();
...
...
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