Skip to content

Commit

Permalink
New functionality: country search in location
Browse files Browse the repository at this point in the history
  • Loading branch information
chengxinlun committed Jul 29, 2017
1 parent 9433413 commit f468e79
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding='utf-8'?>
<manifest package="com.noctuasoftware.stellarium" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.24.2" android:versionCode="24" android:installLocation="auto">
<manifest package="com.noctuasoftware.stellarium" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.24.3" android:versionCode="24" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="@string/app_name" android:launchMode="singleTop">
<intent-filter>
Expand Down
44 changes: 40 additions & 4 deletions data/qml/LocationCityPicker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import QtQuick 2.2
import QtQuick.Controls 1.4

StelDialog {
id: root
Expand All @@ -27,9 +28,23 @@ StelDialog {
property string country
property string city

TextField{
id: citySearchField
anchors.left: parent.left
width: root.country ? root.width / 2 : root.width
onTextChanged: {
if (text.length > 0 ) {
root.applyFilter(text);
} else {
root.reload();
}
}
}

ListView {
id: countriesList
anchors.left: parent.left
anchors.top: citySearchField.bottom
width: root.country ? root.width / 2 : root.width
Behavior on width {
NumberAnimation { easing.type: Easing.InOutQuad }
Expand All @@ -41,20 +56,22 @@ StelDialog {
selected: root.country === modelData
onClicked: root.country = modelData
}
model: stellarium.getCountryNames()
clip: true
model: stellarium.getCountryNames()
clip: true
}
ListView {
id: citiesList
anchors.top: citySearchField.bottom
anchors.left: countriesList.right
anchors.right: parent.right
height: root.height
height: root.height
delegate: StelListItem {
withArrow: false
text: qsTr(modelData)
selected: root.city === modelData
onClicked: root.city = modelData
}
model: stellarium.getCityNames(root.country)
model: stellarium.getCityNames(root.country, "")
clip: true
}

Expand All @@ -63,4 +80,23 @@ StelDialog {
stellarium.location = "%1, %2".arg(city).arg(country)
close();
}

function reload() {
var cList = stellarium.getCountryNames();
var temp = [];
for (var i = 0; i < cList.length; i++){
temp.push(cList[i])
}
countriesList.model = temp;
}
function applyFilter(cName){
var cList = stellarium.getCountryNames();
var temp = [];
for (var i = 0; i < cList.length; i++)
{
if (cList[i].includes(cName))
temp.push(cList[i])
}
countriesList.model = temp;
}
}
32 changes: 29 additions & 3 deletions src/StelQuickStelItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,46 @@ QStringList StelQuickStelItem::getCountryNames() const
return ret;
}

QStringList StelQuickStelItem::getCityNames(const QString& country) const
QStringList StelQuickStelItem::getCityNames(const QString& country, const QString& search) const
{
QStringList ret;
if (country.isEmpty()) return ret;
QList<StelLocation> allLocations = StelApp::getInstance().getLocationMgr().getAll();
foreach(const StelLocation& loc, allLocations)
{
if (loc.country == country)
ret << loc.name;
if (loc.country == country)
{
if (search.isEmpty())
{
ret << loc.name;
}
else
{
if (loc.name.contains(search))
ret << loc.name;
}
}
}
ret.sort();
return ret;
}

bool StelQuickStelItem::testCityNames(const QString& country, const QString& search) const
{
if (country.isEmpty()) return false;
if (search.isEmpty()) return true;
QList<StelLocation> allLocations = StelApp::getInstance().getLocationMgr().getAll();
foreach(const StelLocation& loc, allLocations)
{
if (loc.country == country)
{
if (loc.name.contains(search))
return true;
}
}
return false;
}

QString StelQuickStelItem::getLocation() const
{
StelCore* core = StelApp::getInstance().getCore();
Expand Down
3 changes: 2 additions & 1 deletion src/StelQuickStelItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class StelQuickStelItem : public QQuickItem
QString getCurrentSkyCultureHtmlDescription() const;
QString getCurrentSkyCultureBaseUrl() const;
Q_INVOKABLE QStringList getCountryNames() const;
Q_INVOKABLE QStringList getCityNames(const QString& country) const;
Q_INVOKABLE QStringList getCityNames(const QString& country, const QString& search) const;
Q_INVOKABLE bool testCityNames(const QString& country, const QString& search) const;
QString getLocation() const;
void setLocation(const QString locationId);
double getLatitude() const;
Expand Down
2 changes: 1 addition & 1 deletion stellarium.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

TARGET = stellarium
VERSION = 0.12.3
MOBILE_VERSION = 1.24.2
MOBILE_VERSION = 1.24.3
INCLUDEPATH += \
. src/ src/core src/core/modules src/core/external \
src/core/external/glues_stel/source src/core/external/kfilter \
Expand Down

0 comments on commit f468e79

Please sign in to comment.