fix(xc): 信创代码合入

This commit is contained in:
zxx 2022-11-30 15:09:46 +08:00
parent 7694847d61
commit d3e685a43f
274 changed files with 8149 additions and 4582 deletions

View File

@ -145,6 +145,15 @@ signals:
*/
void showInCenter();
/*
* /,+<2
* /
*
* int
* item的个数
*/
void sigShowBottomList(int itemSize);
public:
/*
* UI层实例化接口对象
@ -183,6 +192,15 @@ public:
* QTabelView
*/
virtual QStandardItemModel *getCityModel() = 0; //获取搜索model指针
/*
* model指针
*
*
* QListView
*/
virtual QStandardItemModel *getTitleModel() = 0; //获取搜索model指针
/*
* model指针
*
@ -191,6 +209,14 @@ public:
*/
virtual QStandardItemModel *getCollectModel() = 0; //获取收藏model指针
/*
* model指针
*
*
* QTabelView
*/
virtual QStandardItemModel *getBottomCollectModel() = 0; //获取收藏model指针
/*
*
*
@ -272,7 +298,32 @@ public:
*
*/
virtual void refresh() = 0;
/*
*
*
*
*
*
*/
virtual void addCollectCityFromWidget(QString cityId) = 0;
/*
*
*
*
* QListView
*/
virtual void delCollectCityFromWidget(QString cityId) = 0;
/*
*
*
*
* QListView
*/
virtual void changeCityFromTitleSearch(QString cityId) = 0; //获取搜索model指针
private:
static Interaction *m_interaction; //单例指针
};

View File

@ -1,13 +1,18 @@
#include "core.h"
#include "global/corevar.h"
Core::Core() {}
void Core::initCore()
{
qDebug() << " ##### Function Positioning ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//初始化各部分
// model/view
m_model = new QStandardItemModel();
m_titleModel = new TitleSearchModel();
m_collectModel = new QStandardItemModel();
m_bottomCollectModel = new TitleSearchModel();
// dbus接口用-暂时不用
// m_canProcess = new QTimer(this);
// m_canProcess->setSingleShot(true);
@ -38,25 +43,30 @@ void Core::initCore()
initConnect();
//检查网络
m_network->checkNetWork();
m_getBottomModle = true;
m_getLocationToModel = true;
}
//信号槽
void Core::initConnect()
{
connect(m_network, &Network::effectiveNetwork, this, &Core::networkState); //检查网络状态
connect(m_network, &Network::haveNet, this, &Core::refreshCity); //网络从无到有,开始重新请求
connect(m_network, &Network::effectiveNetwork, this, &Core::networkState); //检查网络状态
connect(m_network, &Network::haveNet, this, &Core::refreshCity); //网络从无到有,开始重新请求
connect(m_dataRequest, &DataRequest::sendData, m_dataParser, &DataParser::dataReply); //数据reply
connect(m_dataRequest, &DataRequest::sendCollData, m_dataParser, &DataParser::dataReplyColl); //收藏城市数据reply
connect(m_dataParser, &DataParser::showCurrent, this, &Core::showCurrent); //发送信号,显示生活指数信息
connect(m_dataParser, &DataParser::showForcast, this, &Core::showForcast); //发送信号,显示当前城市信息
connect(m_dataParser, &DataParser::showLifeStyle, this, &Core::showLifeStyle); //发送信号,显示城市预测信息
connect(m_dataParser, &DataParser::showCollectCode, this, &Core::updateCollect); //更新收藏城市信息
connect(m_dataParser, &DataParser::showHourly, this, &Core::showHourly); //增加逐小时临时调试接口
connect(m_refreshweather, &QTimer::timeout, this, &Core::refreshCity); //设置定时器,每隔半小时刷新
m_refreshweather->start((60 * 60) * 1000); //定时器开启-60mim
connect(m_dataParser, &DataParser::showCurrent, this, &Core::showCurrent); //发送信号,显示生活指数信息
connect(m_dataParser, &DataParser::showForcast, this, &Core::showForcast); //发送信号,显示当前城市信息
connect(m_dataParser, &DataParser::showLifeStyle, this, &Core::showLifeStyle); //发送信号,显示城市预测信息
connect(m_dataParser, &DataParser::showCollectCode, this, &Core::updateCollect); //更新收藏城市信息
connect(m_dataParser, &DataParser::showHourly, this, &Core::showHourly); //增加逐小时临时调试接口
connect(m_refreshweather, &QTimer::timeout, this, &Core::refreshCity); //设置定时器,每隔半小时刷新
m_refreshweather->start((60 * 60) * 1000); //定时器开启-60mim
}
//城市切换--收藏,搜索,热门
void Core::changeCity(QString cityId)
{
CoreVar::CURRENT_CITY_ID = cityId; // 更新 全局变量 当前城市ID
if (cityId == "") {
ErrorReact::getInstance()->collectAddError("切换城市为空");
return;
@ -69,7 +79,9 @@ void Core::changeCity(QString cityId)
};
//获取城市数据
m_dataRequest->dataRequest(cityId);
qDebug() << " ===== INFO ===== " <<__FILE__<< "," <<__FUNCTION__<< "," <<__LINE__<< " ===== current city type:" << CoreVar::CURRENT_CITY_TYPE ;
}
//从搜索列表改变当前城市
void Core::changeCityFromSearch(QModelIndex index)
{
@ -78,7 +90,9 @@ void Core::changeCityFromSearch(QModelIndex index)
return;
}
changeCity(itemda.cityId);
CoreVar::CURRENT_CITY_TYPE = CityType::Other; // 通过搜索列表切换城市 更换 全局变量 当前城市类别 : 其他类别
}
//加载收藏城市
void Core::loadCollectCity()
{
@ -98,19 +112,30 @@ void Core::loadCollectCity()
if (m_searchResultList.length() != 0) {
LocationData m_locationdata = (LocationData)m_searchResultList.at(0);
initCollectModel(listCollectCity.at(i), m_locationdata.city);
if (m_getBottomModle == true) {
initBottomCollectModel(listCollectCity.at(i), m_locationdata.city);
}
} else {
collectCity.remove(m_fullCityList.at(i) + ",");
m_fullCityList.removeAt(i);
}
}
}
// 加载收藏城市列表 更新 全局变量 当前收藏城市列表
qDebug() << " ===== INFO ===== " <<__FILE__<< "," <<__FUNCTION__<< "," <<__LINE__<< " ===== current collect list size:" << CoreVar::CURRENT_COLLECT_LIST.size();
CoreVar::CURRENT_COLLECT_LIST = m_fullCityList;
qDebug() << " ===== INFO ===== " <<__FILE__<< "," <<__FUNCTION__<< "," <<__LINE__<< " ===== current collect list size:" << CoreVar::CURRENT_COLLECT_LIST.size();
m_getBottomModle = false;
requestDataColl(collectCity);
}
//显示在屏幕中间
void Core::showInCenter()
{
emit showCenter();
}
//添加收藏城市
void Core::addCollectCity(QModelIndex index)
{
@ -141,8 +166,68 @@ void Core::addCollectCity(QModelIndex index)
m_open = true;
m_updateList = true;
//设置itemmodel--用于界面显示
// 更新列表
m_fullCityList.clear();
QString collectCity = CoreVar::getSettings("collect-city").toString();
QStringList listCollectCity = collectCity.split(",");
m_fullCityList = listCollectCity;
// 收藏城市 更新收藏列表 更新 全局变量 当前收藏列表
qDebug() << " ===== INFO ===== " <<__FILE__<< "," <<__FUNCTION__<< "," <<__LINE__<< " ===== current collect list size:" << CoreVar::CURRENT_COLLECT_LIST.size();
CoreVar::CURRENT_COLLECT_LIST = m_fullCityList;
qDebug() << " ===== INFO ===== " <<__FILE__<< "," <<__FUNCTION__<< "," <<__LINE__<< " ===== current collect list size:" << CoreVar::CURRENT_COLLECT_LIST.size();
initBottomCollectModel(itemdata.cityId, itemdata.cityName);
initCollectModel(itemdata.cityId, itemdata.cityName);
}
// 主界面点击图标添加收藏城市
void Core::addCollectCityFromWidget(QString cityId)
{
// 更新 全局变量 当前城市类别
CoreVar::CURRENT_CITY_TYPE = CityType::Collection;
// 添加收藏的城市名称 = 当前城市名字
QString cityName = CoreVar::CURRENT_CITY_NAME;
//遍历收藏城市列表,不可重复添加
if (!m_fullCityList.isEmpty()) {
for (QStringList::iterator it = m_fullCityList.begin(); it != m_fullCityList.end(); ++it) {
if (*it == cityId) { //若收藏城市列表中已有需要添加的城市,则返回
ErrorReact::getInstance()->collectAddError("收藏城市列表中已有需要添加的城市");
return;
}
}
}
//设置将城市加入配置文件
QString fullCityID = cityId;
m_fullCityList.append(fullCityID);
//更新配置文件
//重新将收藏城市列表写入配置文件
setCollectGsettings();
//更改状态
m_open = true;
m_updateList = true;
//设置itemmodel--用于界面显示
if (cityName == "" ) {
cityName = m_searchMarch->matchCityName(cityId);
}
initBottomCollectModel(cityId, cityName);
initCollectModel(cityId, cityName);
// 更新列表
m_fullCityList.clear();
QString collectCity = CoreVar::getSettings("collect-city").toString();
QStringList listCollectCity = collectCity.split(",");
m_fullCityList = listCollectCity;
// 收藏城市 更新收藏列表 更新 全局变量 当前收藏列表
CoreVar::CURRENT_COLLECT_LIST = m_fullCityList;
return;
}
//从收藏城市切换城市
void Core::changeCityFromCollect(QModelIndex index)
{
@ -153,7 +238,13 @@ void Core::changeCityFromCollect(QModelIndex index)
}
//切换城市
changeCity(itemda.cityId);
// 收藏城市列表切换城市 更新 全局变量 当前城市名称 和 当前城市ID 当前城市类别
CoreVar::CURRENT_CITY_ID = itemda.cityId;
CoreVar::CURRENT_CITY_NAME = itemda.cityName;
CoreVar::CURRENT_CITY_TYPE = CityType::Collection;
}
//删除收藏列表中的城市
void Core::delCollectCity(QModelIndex index)
{
@ -205,6 +296,94 @@ void Core::delCollectCity(QModelIndex index)
}
setCollectGsettings();
}
delBottomCollectCity(sign);
// 收藏城市 更新收藏列表 更新 全局变量 当前收藏列表 当前城市类型
CoreVar::CURRENT_COLLECT_LIST = m_fullCityList;
}
//删除主界面底部收藏列表中的城市
void Core::delBottomCollectCity(QString cityId)
{
// 对取消收藏的城市ID进行查找对应的某一行将其删去
for (int i = 0; i < m_bottomCollectModel->rowCount(); i++) {
QModelIndex index = m_bottomCollectModel->index(i,0);
QString indexCityId = index.data(TitleSearchModel::CityId).toString();
if (indexCityId == cityId) {
// 判断拥有城市ID的某一行的类别类别是收藏城市还是定位城市
if (TitleSearchModel::CityType::Collection == index.data(TitleSearchModel::CityStyle).toInt()) {
m_bottomCollectModel->removeRow(i);
}
}
}
// 判断当前的model数量数量小于2时界面最底部的图标进行隐藏
emit sigShowBottomList(m_bottomCollectModel->rowCount());
}
// 主界面点击取消收藏
void Core::delCollectCityFromWidget(QString cityId)
{
// 主界面 -> 取消cityID收藏 -> 更改收藏model -> 更改配置文件 -> 更改界面底部图标model
//遍历model拿到需要删除的id对应的item值 -更新配置文件
//删除选中项--设置一个list存其余各项
QList<QStandardItem *> itemList;
itemList.clear();
//遍历当前整个model
for (int i = 0; i < m_collectModel->rowCount(); i++) {
for (int j = 0; j < m_collectModel->columnCount(); j++) {
//遍历到最后一行时对于空itemcontinue--不然会发生闪退
if ((i == (m_collectModel->rowCount() - 1))
&& ((i * m_collectModel->columnCount() + (j + 1)) > (m_fullCityList.length() - 1))) {
continue;
}
QString id = m_collectModel->item(i, j)->data(Qt::UserRole).value<CollectItemData>().cityId;
//判断为删除项,跳出此次,继续遍历
if (cityId == id){
//判断到最后一个item的时候可以直接跳出循环。
if (m_collectModel->item(i, j)->data(Qt::UserRole).value<CollectItemData>().cityId
== m_fullCityList.at(m_fullCityList.length() - 1)) {
break;
} else {
continue;
}
}
//将有效项加入qlist
itemList.append(m_collectModel->item(i, j)->clone());
}
}
//清空model重排整个model
m_collectModel->clear();
//遍历qlist将有效item重新排列
for (int i = 0; i < itemList.length(); i++) {
m_collectModel->setItem(i / 3, i % 3, itemList.at(i));
}
//更新配置文件
if (!m_fullCityList.empty()) {
int cityIndex = m_fullCityList.indexOf(cityId);
m_fullCityList.removeAt(cityIndex);
//判断配置文件为空,发送信号给前端
if (m_fullCityList.length() == 1) {
emit collectNull();
}
setCollectGsettings();
}
delBottomCollectCity(cityId);
// 收藏城市 更新收藏列表 更新 全局变量 当前收藏列表 当前城市类别
CoreVar::CURRENT_COLLECT_LIST = m_fullCityList;
if (CoreVar::CURRENT_CITY_ID == CoreVar::LOCATION_CITY_ID) {
CoreVar::CURRENT_CITY_TYPE = CityType::Location;
} else {
CoreVar::CURRENT_CITY_TYPE = CityType::Other;
}
return;
}
void Core::allowLocationYes()
@ -216,13 +395,53 @@ void Core::allowLocationYes()
void Core::allowLocationNo()
{
CoreVar::setSettings("allow-locate", "0"); //不允许定位
// 将主界面最底部的列表中的定位item进行更改数据
if (m_locationItem == nullptr) {
m_locationItem = new QStandardItem;
//设置item不可拖拽
m_locationItem->setDragEnabled(false);
///整体存取
m_locationItem->setData("", TitleSearchModel::CityId);
m_locationItem->setData("", TitleSearchModel::CityName);
m_locationItem->setData(TitleSearchModel::CityType::Location, TitleSearchModel::CityStyle);
//插入model
m_bottomCollectModel->appendRow(m_locationItem);
} else {
///整体存取
m_locationItem->setData("", TitleSearchModel::CityId);
m_locationItem->setData("", TitleSearchModel::CityName);
}
//不允许定位时显示城市:北京
m_dataRequest->dataRequest(CoreVar::DEFAULT_CITYID);
m_currentCityId = CoreVar::DEFAULT_CITYID;
CoreVar::CURRENT_CITY_ID = m_currentCityId;
CoreVar::CURRENT_CITY_NAME = m_searchMarch->matchCityName(m_currentCityId);
CoreVar::LOCATION_CITY_ID = "";
// 更新获取收藏列表
m_fullCityList.clear();
QString collectCity = CoreVar::getSettings("collect-city").toString();
QStringList listCollectCity = collectCity.split(",");
m_fullCityList = listCollectCity;
// 收藏城市 更新收藏列表 更新 全局变量 当前收藏列表
CoreVar::CURRENT_COLLECT_LIST = m_fullCityList;
if (m_fullCityList.contains(m_currentCityId)) {
CoreVar::CURRENT_CITY_TYPE = CityType::Collection;
} else {
CoreVar::CURRENT_CITY_TYPE = CityType::Other;
}
}
//定位
void Core::location()
{
qDebug() << " ##### Function Positioning ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//判断是否允许定位----默认不允许定位
if ("1" == CoreVar::getSettings("allow-locate").toString()) {
qDebug() << " ##### Function Positioning ##### getSettings ##### allow-locate=1 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//定位--地区名
QString cityName = m_ipLocation->gotoLocation();
//发现ipip定位偶尔会出现返回乱码--包含http字段
@ -232,6 +451,7 @@ void Core::location()
}
//定位失败
if (cityName == "" || cityName.contains("http")) {
qDebug() << " ##### Function Positioning ##### 定位失败 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
ErrorReact::getInstance()->geoFail(tr("Seek failed!"));
m_currentCityId = "";
refreshCity();
@ -241,11 +461,58 @@ void Core::location()
QString cityId = m_searchMarch->setAutomaticCity(cityName);
m_dataRequest->dataRequest(cityId);
m_currentCityId = cityId;
// 允许定位(定位成功)/ 不允许定位 更新 全局变量 当前城市名称 和 ID 定位当前城市ID
CoreVar::CURRENT_CITY_ID = m_currentCityId;
CoreVar::CURRENT_CITY_NAME = m_searchMarch->matchCityName(m_currentCityId);
CoreVar::CURRENT_CITY_TYPE = CityType::Location;
CoreVar::LOCATION_CITY_ID = m_currentCityId;
if (m_locationItem == nullptr) {
m_locationItem = new QStandardItem;
//设置item不可拖拽
m_locationItem->setDragEnabled(false);
///整体存取
m_locationItem->setData(CoreVar::CURRENT_CITY_ID, TitleSearchModel::CityId);
m_locationItem->setData(CoreVar::CURRENT_CITY_NAME, TitleSearchModel::CityName);
m_locationItem->setData(TitleSearchModel::CityType::Location, TitleSearchModel::CityStyle);
//设置悬浮提示
m_locationItem->setToolTip(CoreVar::CURRENT_CITY_NAME);
//插入model
m_bottomCollectModel->appendRow(m_locationItem);
} else {
///整体存取
m_locationItem->setData(CoreVar::CURRENT_CITY_ID, TitleSearchModel::CityId);
m_locationItem->setData(CoreVar::CURRENT_CITY_NAME, TitleSearchModel::CityName);
//设置悬浮提示
m_locationItem->setToolTip(CoreVar::CURRENT_CITY_NAME);
}
} else if ("0" == CoreVar::getSettings("allow-locate").toString()) {
qDebug() << " ##### Function Positioning ##### getSettings ##### allow-locate=0 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//不允许定位时
m_dataRequest->dataRequest(CoreVar::DEFAULT_CITYID);
m_currentCityId = CoreVar::DEFAULT_CITYID;
CoreVar::CURRENT_CITY_ID = m_currentCityId;
CoreVar::CURRENT_CITY_NAME = m_searchMarch->matchCityName(m_currentCityId);
CoreVar::LOCATION_CITY_ID = "";
// 更新列表
m_fullCityList.clear();
QString collectCity = CoreVar::getSettings("collect-city").toString();
QStringList listCollectCity = collectCity.split(",");
m_fullCityList = listCollectCity;
// 收藏城市 更新收藏列表 更新 全局变量 当前收藏列表
CoreVar::CURRENT_COLLECT_LIST = m_fullCityList;
if (m_fullCityList.contains(m_currentCityId)) {
CoreVar::CURRENT_CITY_TYPE = CityType::Collection;
} else {
CoreVar::CURRENT_CITY_TYPE = CityType::Other;
}
return;
}
qDebug() << " ===== INFO ===== " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__ << " ===== location city id:" << CoreVar::LOCATION_CITY_ID;
}
//搜索城市
@ -253,25 +520,33 @@ void Core::searchCity(QString inputText)
{
//清空模型-清空上次搜索结果
m_model->clear();
//去搜索模块获得搜索结果list
m_searchResultList = m_searchMarch->exactMatchCity(inputText);
m_titleModel->clear();
if (inputText == "") {
//输入为空,发信号给前端进行处理
emit searchUiShow(false);
} else if (m_searchResultList.isEmpty()) {
return;
}
//去搜索模块获得搜索结果list
m_searchResultList = m_searchMarch->exactMatchCity(inputText);
if (m_searchResultList.isEmpty()) {
CoreVar::TITLE_SEARCH_LIST_NUM = 1;
//搜索为空,发信号给前端进行处理
emit searchNull();
} else {
emit searchUiShow(true);
//设置搜索模型
setModel();
if (CoreVar::CURRENT_TITLE_SEARCH) {
setTitleModel(); //设置标题栏搜索模型
} else {
setModel();//设置搜索模型
}
}
}
//请求收藏数据
void Core::requestDataColl(QString cityIdList)
{
m_dataRequest->dataRequestCollect(cityIdList);
}
//刷新城市
void Core::refreshCity()
{
@ -285,29 +560,87 @@ void Core::refreshCity()
} else {
m_currentCityId = CoreVar::DEFAULT_CITYID;
}
// 定位失败 更新 全局变量 当前城市ID 和 名称 定位城市ID
CoreVar::CURRENT_CITY_ID = m_currentCityId;
CoreVar::CURRENT_CITY_NAME = m_searchMarch->matchCityName(m_currentCityId);
if (CoreVar::CURRENT_COLLECT_LIST.contains(m_currentCityId)) {
CoreVar::CURRENT_CITY_TYPE = CityType::Collection;
} else {
CoreVar::CURRENT_CITY_TYPE = CityType::Other;
}
}
m_dataRequest->dataRequest(m_currentCityId);
// 更改定位后的城市信息
if (m_locationItem == nullptr) {
QString name = m_searchMarch->matchCityName(CoreVar::DEFAULT_CITYID);
m_locationItem = new QStandardItem;
//设置item不可拖拽
m_locationItem->setDragEnabled(false);
///整体存取
m_locationItem->setData(CoreVar::DEFAULT_CITYID, TitleSearchModel::CityId);
m_locationItem->setData(name, TitleSearchModel::CityName);
m_locationItem->setData(TitleSearchModel::CityType::Location, TitleSearchModel::CityStyle);
//设置悬浮提示
m_locationItem->setToolTip(name);
//插入model
m_bottomCollectModel->appendRow(m_locationItem);
}
qDebug() << " ===== INFO ===== " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__ << "LOCATION_CITY_ID ===== " << CoreVar::LOCATION_CITY_ID;
}
//搜索model
QStandardItemModel *Core::getCityModel()
{
return m_model;
}
//标题栏搜索搜索model
QStandardItemModel *Core::getCityTitleModel()
{
return m_titleModel;
}
//收藏model
QStandardItemModel *Core::getCollectModel()
{
return m_collectModel;
}
//收藏model
QStandardItemModel *Core::getBottomCollectModel()
{
return m_bottomCollectModel;
}
//设置搜索model数据
void Core::setModel()
{
//遍历整个搜索结果列表
for (int i = 0; i < m_searchResultList.size(); ++i) {
LocationData m_locationdata = (LocationData)m_searchResultList.at(i);
//设置模型item-构造搜索model
initModel(m_locationdata, i);
for (int i = 0; i < m_searchResultList.size(); i++) {
// model数据
ItemData m_itemData;
//城市id
m_itemData.cityId = m_searchResultList.at(i).id;
//城市名
m_itemData.cityName = m_searchResultList.at(i).city;
//初始化item
QStandardItem *item = new QStandardItem;
//设置不可拖拽
item->setDragEnabled(false);
//整体存取
item->setData(QVariant::fromValue(m_itemData), Qt::UserRole);
//设置悬浮提示
item->setToolTip(m_itemData.cityName);
//插入model
m_model->setItem(i / 3, i % 3, item);
}
emit searchUiShow(true);
}
//构造搜索model
void Core::initModel(LocationData m_locationdata, int i)
{
@ -327,6 +660,32 @@ void Core::initModel(LocationData m_locationdata, int i)
m_model->setItem(i / 3, i % 3, item);
}
void Core::setTitleModel()
{
m_titleModel->clear();
CoreVar::TITLE_SEARCH_LIST_NUM = m_searchResultList.size();
//遍历整个搜索结果列表
for (int i = 0; i < m_searchResultList.size(); i++) {
initTitleModel(m_searchResultList.at(i), i);
}
emit sigTitleSearchUiShow(true);
}
//构造搜索model
void Core::initTitleModel(LocationData m_locationdata, int i)
{
QStandardItem *item = new QStandardItem;
//设置不可拖拽
item->setDragEnabled(false);
//整体存取
//城市id
item->setData(m_locationdata.id, TitleSearchModel::CityId);
//城市名
item->setData(m_locationdata.city, TitleSearchModel::CityName);
//插入model
m_titleModel->setItem(i, 0, item);
}
//构造搜索model
void Core::initCollectModel(QString cityId, QString cityName)
{
@ -334,6 +693,7 @@ void Core::initCollectModel(QString cityId, QString cityName)
if (m_open) {
m_itemIndex = m_fullCityList.length() - 2;
}
m_hashIdItems.clear();
// model数据
CollectItemData m_collectItemData;
//城市id
@ -350,12 +710,56 @@ void Core::initCollectModel(QString cityId, QString cityName)
//设置model的行列
m_collectModel->setItem(m_itemIndex / 3, m_itemIndex % 3, item);
m_hashIdItems.insert(cityId, item);
//请求数据---获取温度和阴晴
if (m_updateList) {
if (m_collectItemData.cityId == "") {
return;
}
requestDataColl(m_collectItemData.cityId);
}
}
//构造搜索BottomCollectmodel
void Core::initBottomCollectModel(QString cityId, QString cityName)
{
if (m_getLocationToModel == true) {
m_getLocationToModel = false;
if ("1" == CoreVar::getSettings("allow-locate").toString()) {
m_currentCityId = CoreVar::DEFAULT_CITYID;
} else {
m_currentCityId = "";
}
//设置item
QStandardItem *item = new QStandardItem;
if (m_locationItem == nullptr) {
m_locationItem = item;
///整体存取
item->setData(m_currentCityId, TitleSearchModel::CityId);
item->setData(TitleSearchModel::CityType::Location, TitleSearchModel::CityStyle);
//设置item不可拖拽
item->setDragEnabled(false);
//插入model
m_bottomCollectModel->appendRow(item);
} else {
item = m_locationItem;
}
}
//设置item
QStandardItem *item = new QStandardItem;
//设置item不可拖拽
item->setDragEnabled(false);
///整体存取
item->setData(cityId, TitleSearchModel::CityId);
item->setData(cityName, TitleSearchModel::CityName);
item->setData(TitleSearchModel::CityType::Collection, TitleSearchModel::CityStyle);
//设置悬浮提示
item->setToolTip(cityName);
//插入model
m_bottomCollectModel->appendRow(item);
emit sigShowBottomList(m_bottomCollectModel->rowCount());
}
//初始化dbus
QString Core::initDbus(const QStringList &arguments)
@ -401,9 +805,11 @@ void Core::networkState(bool isOnline)
{
//启动
if (isOnline) {
qDebug() << " ##### Function Positioning ##### effectiveNetwork = true ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//开始定位
location();
} else {
qDebug() << " ##### Function Positioning ##### effectiveNetwork = false ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//无网络或其他错误
return;
}

View File

@ -27,6 +27,7 @@
#include "model/searchmarch.h"
#include <QPersistentModelIndex>
#include <buried_point.hpp>
#include "model/titlesearchmodel.h"
class Core : public QObject
{
Q_OBJECT
@ -42,8 +43,11 @@ signals:
void collectNull(); //收藏城市为空--删光了
void collectShow(); //配置文件中收藏城市不为空
void searchUiShow(bool hasCity); //搜索有结果或搜索输入为空
void sigTitleSearchUiShow(bool hasCity); //标题栏搜索有结果或搜索输入为空
void searchNull(); //搜索为空
void updateFinish(); //收藏城市最后一个加载完成
void sigShowBottomList(int itemSize); // 显示主界面底部的收藏城市列表
void sigDeleCollectCity(); // 更换界面收藏图标样式
public:
Core();
@ -51,14 +55,20 @@ public:
void changeCity(QString cityId); //切换城市
void changeCityFromSearch(QModelIndex index); //切换到目标城市
void addCollectCity(QModelIndex index); //添加收藏城市
void addBottomCollectCity(QModelIndex index); //添加主界面最底部收藏城市
void addCollectCityFromWidget(QString cityId); //添加主界面收藏城市
void changeCityFromCollect(QModelIndex index); //切换到目标城市
void delCollectCity(QModelIndex index); //添加收藏城市
void delBottomCollectCity(QString cityId); //删除主界面最底部收藏城市
void delCollectCityFromWidget(QString cityId); //主界面点击取消收藏
void searchCity(QString inputText); //搜索本地词库表
void initCore(); //初始化核心
void loadCollectCity(); //加载收藏城市
void showInCenter(); //显示在屏幕中间
QStandardItemModel *getCityModel(); //获取搜索列表model指针
QStandardItemModel *getCityTitleModel(); //获取标题栏搜索列表model指针
QStandardItemModel *getCollectModel(); //获取收藏城市model指针
QStandardItemModel *getBottomCollectModel(); //获取主界面最底部收藏城市model指针
void allowLocationYes();
void allowLocationNo();
void progremExit(); //结束进程
@ -80,22 +90,33 @@ private:
void requestDataColl(QString cityIdList); //请求收藏数据
QStandardItemModel *m_model = nullptr;
QStandardItemModel *m_collectModel = nullptr;
TitleSearchModel *m_titleModel = nullptr;
TitleSearchModel *m_bottomCollectModel = nullptr;
QList<LocationData> m_searchResultList;
void setModel(); //设置model7x3x2请求一次一页21个城市缓存两页当鼠标滑动到某一个位置再去请求下两页
void setTitleModel(); //设置titlemodel
void initModel(LocationData m_locationdata, int i); //设置搜索model
void initTitleModel(LocationData m_locationdata, int i); //设置搜索model标题栏搜索
void initCollectModel(QString cityId, QString cityName); //设置收藏城市model
void initBottomCollectModel(QString cityId, QString cityName); //设置收藏城市model(主界面底部)
void processingCommand(const QStringList &cmd); //处理终端命令
QString processingApi(const QStringList &cmd); //处理外部命令
QTimer *m_canProcess = nullptr; //限制操作频率降低cpu占用
bool coreOperateTooOften(); //操作过于频繁
bool apiFunction(); //处理api函数
int m_itemIndex = 0; //收藏城市model
int m_BottomItemIndex = 0; //收藏城市model(主界面底部)
QStringList m_fullCityList; //获取收藏城市列表
void setCollectGsettings(); //更新配置文件中的收藏城市
bool m_open = false; //判断是打开时初始化model还是从列表中添加的----默认为false打开时初始化model。
QTimer *m_refreshweather;
bool m_updateList = false; //默认false时不进行访问收藏城市数据--避免多次访问
QString m_currentCityId = "";
bool m_getBottomModle; // 获取收藏数据计入model
bool m_getLocationToModel; // 定位本地数据计入Bottommodel
QHash<QString, QStandardItem *> m_hashIdItems;
QStandardItem * m_locationItem = nullptr;
private slots:
void networkState(bool isOnline);

View File

@ -19,6 +19,7 @@ CoreInteraction::CoreInteraction()
void CoreInteraction::creatCore(const QStringList &list)
{
qDebug() << " ##### Function Positioning ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//防止多次初始化后端-默认false
if (m_isCoreInit) {
return;
@ -47,11 +48,11 @@ void CoreInteraction::initConnect()
&CoreInteraction::dataUiShow); //返回数据解析错误给UI发信号
connect(ErrorReact::getInstance(), &ErrorReact::netTimeout, this, &CoreInteraction::netTimeout); //超时返回
connect(ErrorReact::getInstance(), &ErrorReact::geoUiShow, this, &CoreInteraction::geoUiShow); //定位失败
connect(m_core, &Core::sigShowBottomList, this, &CoreInteraction::sigShowBottomList); // 收藏城市+定位城市<2时隐藏列表
connect(m_core, &Core::searchNull, this, &CoreInteraction::searchNull); //返回搜索为无匹配城市给UI发信号
connect(m_core, &Core::searchUiShow, this,
&CoreInteraction::searchUiShow); //返回搜索有/输入为空城市结果给UI发信号
connect(m_core, &Core::startView, this,
&CoreInteraction::toStartView); //后端初始化之后,先进行网络诊断,之后初始化前端
connect(m_core, &Core::searchUiShow, this, &CoreInteraction::searchUiShow); //返回搜索有/输入为空城市结果给UI发信号
connect(m_core, &Core::sigTitleSearchUiShow, this, &CoreInteraction::searchUiShow); //返回搜索有/输入为空城市结果给UI发信号
connect(m_core, &Core::startView, this, &CoreInteraction::toStartView); //后端初始化之后,先进行网络诊断,之后初始化前端
// connect(m_core,&Core::showCenter,this,&CoreInteraction::showInCenter);//不起作用,有问题,带解决
connect(m_core, &Core::showCurrent, this, &CoreInteraction::showCurrent); //返回当前城市
connect(m_core, &Core::showForcast, this, &CoreInteraction::showForcast); //返回预测一周信息
@ -66,8 +67,12 @@ void CoreInteraction::initConnect()
connect(this, &CoreInteraction::coreSearchResult, m_core, &Core::searchCity); //根据输入字符,匹配本地城市
connect(this, &CoreInteraction::coreGetCityModel, m_core, &Core::getCityModel,
Qt::BlockingQueuedConnection); //获取搜索model指针
connect(this, &CoreInteraction::coreGetTitleModel, m_core, &Core::getCityTitleModel,
Qt::BlockingQueuedConnection); //获取搜索model指针
connect(this, &CoreInteraction::coreGetCollectModel, m_core, &Core::getCollectModel,
Qt::BlockingQueuedConnection); //获取收藏model指针
connect(this, &CoreInteraction::coreGetBottomCollectModel, m_core, &Core::getBottomCollectModel,
Qt::BlockingQueuedConnection); //获取收藏model指针
connect(this, &CoreInteraction::corechangeCityFromCollect, m_core,
&Core::changeCityFromCollect); //从收藏列表切换城市
connect(this, &CoreInteraction::coreDelCollectCity, m_core, &Core::delCollectCity); //删除收藏城市列表中的城市
@ -76,6 +81,9 @@ void CoreInteraction::initConnect()
connect(this, &CoreInteraction::setAllowLocationYes, m_core, &Core::allowLocationYes); //允许定位-刷新
connect(this, &CoreInteraction::setAllowLocationNo, m_core, &Core::allowLocationNo); //不允许定位
connect(this, &CoreInteraction::refreshCity, m_core, &Core::refreshCity); //重试等刷新城市函数
connect(this, &CoreInteraction::sigCoreAddCollectCity, m_core, &Core::addCollectCityFromWidget); //收藏城市
connect(this, &CoreInteraction::sigCoreDelCollectCity, m_core, &Core::delCollectCityFromWidget); //取消收藏
}
bool CoreInteraction::coreOperateTooOften()
@ -138,11 +146,26 @@ QStandardItemModel *CoreInteraction::getCityModel()
return coreGetCityModel();
}
QStandardItemModel *CoreInteraction::getTitleModel()
{
return coreGetTitleModel();
}
QStandardItemModel *CoreInteraction::getCollectModel()
{
return coreGetCollectModel();
}
QStandardItemModel *CoreInteraction::getBottomCollectModel()
{
return coreGetBottomCollectModel();
}
void CoreInteraction::changeCityFromTitleSearch(QString cityId)
{
emit coreChangeCity(cityId);
}
void CoreInteraction::changeCityFromSearch(QModelIndex index)
{
if (coreOperateTooOften()) {
@ -182,3 +205,13 @@ void CoreInteraction::loadCollectCity()
}
emit coreLoadCollect();
}
void CoreInteraction::addCollectCityFromWidget(QString cityId)
{
emit sigCoreAddCollectCity(cityId);
}
void CoreInteraction::delCollectCityFromWidget(QString cityId)
{
emit sigCoreDelCollectCity(cityId);
}

View File

@ -15,6 +15,7 @@ class CoreInteraction : public Interaction
signals:
void coreChangeCity(QString cityId); //切换城市
void corechangeCityFromSearch(QModelIndex index); //从搜索城市列表切换到目标城市
void corechangeCityFromTitleSearch(QString cityId); //从标题栏搜索城市列表切换到目标城市
void coreAddCollectCity(QModelIndex index); //添加收藏城市
void corechangeCityFromCollect(QModelIndex index); //从收藏城市切换到目标城市
void coreDelCollectCity(QModelIndex index); //删除收藏城市列表中的城市
@ -26,8 +27,13 @@ signals:
void setAllowLocationYes();
void setAllowLocationNo();
void refreshCity();
QStandardItemModel *coreGetCityModel(); //设置搜索城市列表model
QStandardItemModel *coreGetCollectModel(); //设置收藏城市列表model
void sigCoreChangeCityFromTitleSearch(QString cityid); // 标题栏搜索城市切换城市
void sigCoreAddCollectCity(QString cityId); // 主界面点击按钮进行收藏城市
void sigCoreDelCollectCity(QString cityId); // 主界面点击按钮进行取消收藏
QStandardItemModel *coreGetCityModel(); //设置搜索城市列表model
QStandardItemModel *coreGetTitleModel(); //设置标题栏搜索城市列表model
QStandardItemModel *coreGetCollectModel(); //设置收藏城市列表model
QStandardItemModel *coreGetBottomCollectModel(); //设置主界面最低处收藏城市列表model
public:
CoreInteraction();
@ -37,7 +43,10 @@ protected:
virtual void changeCity(QString cityId); //切换城市
virtual void searchResult(QString inputText); //搜索本地城市进行匹配
virtual QStandardItemModel *getCityModel(); //获取搜索model指针
virtual QStandardItemModel *getTitleModel(); //获取标题栏搜索model指针
virtual QStandardItemModel *getCollectModel(); //获取收藏model指针
virtual QStandardItemModel *getBottomCollectModel(); //获取主界面最低处收藏model指针
virtual void changeCityFromTitleSearch(QString cityId); //从标题栏的搜索城市切换到目标城市
virtual void changeCityFromSearch(QModelIndex index); //从搜索城市切换到目标城市
virtual void addCollectCity(QModelIndex index); //添加收藏城市
virtual void changeCityFromCollect(QModelIndex index); //从收藏城市切换到目标城市
@ -48,6 +57,8 @@ protected:
virtual void allowLocationYes();
virtual void allowLocationNo();
virtual void refresh();
virtual void addCollectCityFromWidget(QString cityId);
virtual void delCollectCityFromWidget(QString cityId);
private:
void initConnect(); //初始化绑定

View File

@ -43,6 +43,7 @@ void viewControl::toShowView()
//后端初始化
void viewControl::initCore(const QStringList &list, bool isStart)
{
qDebug() << " ##### Function Positioning ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//带showmainwindow 或 不带参
m_isStart = isStart;
//初始化后端

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View File

@ -4,7 +4,7 @@ Weather is an app that provides weather and life index information. By obtaining
### Open mode
“open menu”![](image/1.png)>“weather” or “taskbar”>“search”![](image/2.png)>“weather”
“open menu”>“weather” or “taskbar”>“search”>“weather”
![Fig 1 Eyes of Pictures-big](image/3.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 155 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View File

@ -4,7 +4,7 @@
### 打开方式
“开始菜单”![](image/1.png)>“天气”或“任务栏”>“搜索”![](image/2.png)>“天气”
“开始菜单”>“天气”或“任务栏”>“搜索”>“天气”
![图1 天气主界面-big](image/3.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,24 @@
# 天氣
## 概 述
天氣是一款能獲取天氣及生活指數信息的應用軟件。通過獲取權威氣象數據可以實時查看全國各城市未來一周的天氣狀況及生活指數信息(如紫外線指數、空氣指數等),支持自動定位當前所在城市、自定義添加城市。
### 打開方式
“開始菜單”![](image/1.png)>“天氣”或“任務欄”>“搜索”![](image/2.png)>“天氣”
![圖1 天氣主界面-big](image/3.png)
### 基本操作
首次打開應用,在已連接網絡的情況下,不開啓定位,默認显示北京的天氣狀況及生活指數信息;若系統未連接網絡,打開應用後會彈出。
在界面中選擇“變更”后,可以在展示的熱門城市中選擇城市進行切換,也可以在搜索欄中搜索全國的任一城市並選擇“+”將該城市添加到收藏城市,或直接點擊該城市進行切換。
![圖2 切換城市-big](image/4.png)
![圖3 搜索城市-big](image/5.png)
點擊導航欄中的“![](image/6.png)”可打開天氣菜單欄。選擇“位置”> “是”後,應用可以自動定位當前所在城市,獲取並显示所在城市的天氣狀況及生活指數信息。點擊菜單欄中的“說明”將自動跳轉至用戶手冊中,可查看該應用的操作說明。點擊菜單欄中的“关於”可查看當前版本信息,選擇“退出”可關閉應用。
![圖4 天氣下拉菜單-big](image/7.png)

27
debian/control vendored
View File

@ -3,30 +3,33 @@ Section: utils
Priority: optional
Maintainer: liuyuhui <liuyuhui@kylinos.cn>
Build-Depends: debhelper (>=9),
qtbase5-dev,
qt5-qmake,
qtchooser,
qtscript5-dev,
qttools5-dev-tools,
qtbase5-dev-tools,
pkgconf,
libgeoip-dev,
libx11-dev,
libgsettings-qt-dev,
libqt5x11extras5-dev,
libkf5windowsystem-dev,
libkysdk-applications-dev,
libkysdk-base-dev,
libqt5x11extras5-dev,
libx11-dev,
pkgconf,
qt5-qmake,
qtbase5-dev,
qtbase5-dev-tools,
qtchooser,
qtscript5-dev,
qttools5-dev-tools
qtdeclarative5-dev,
libukui-appwidget-manager-dev,
libukui-appwidget-provider-dev,
Standards-Version: 1.0.0
Homepage: https://github.com/ubuntukylin/kylin-weather
Vcs-Git: https://github.com/ubuntukylin/kylin-weather.git
Vcs-Browser: https://github.com/ubuntukylin/kylin-weather
Package: kylin-weather
Replaces: indicator-china-weather
Breaks: indicator-china-weather
Replaces: indicator-china-weather (<< 3.1.2-0~)
Breaks: indicator-china-weather (<< 3.1.2-0~)
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Depends: ${misc:Depends},${shlibs:Depends}
Description: Indicator that displays China weather information
Kylin Weather displays detail weather information for one place,
including weather forecast and observe weather, and you can

18
debian/rules vendored
View File

@ -3,20 +3,16 @@
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
export QT_SELECT=5
QMAKE_OPTS = DEFINES+=NO_DEBUG_ON_CONSOLE
MAKE_OPTS = PREFIX=/usr QMAKE=qmake LRELEASE=lrelease QMAKE_OPTS="$(QMAKE_OPTS)"
override_dh_auto_configure:
QT_SELECT=qt5 dh_auto_configure \
-- "QMAKE_CXXFLAGS=$(CFLAGS)" \
kylin-weather.pro
%:
dh $@
override_dh_auto_configure:
qmake ./kylin-weather.pro && \
make && \
qmake ./weather-card/kylin-weather-card.pro && \
make && \
qmake ./weather-install.pro && \
make
override_dh_missing:
dh_missing --fail-missing

View File

@ -42,6 +42,20 @@ const QString CoreVar::API_TYPE = QString("$api$"); //是否为外部作为API
const QStringList CoreVar::WEATHER_CODE_TMP = CoreVar::temList();
const QString CoreVar::DEFAULT_CITYID = QString("101010100");
const int CoreVar::DEFAULT_TIMEOUT = 30000; // 30s
bool CoreVar::GET_CITY_INFO = false; // 得到城市信息默认为false
CityType CoreVar::CURRENT_CITY_TYPE = CityType::None; // 当前城市的类别定位1/收藏2/其他3
QString CoreVar::CURRENT_CITY_ID = ""; // 当前城市的城市ID
QString CoreVar::CURRENT_CITY_NAME = ""; // 当前城市的城市名称
QString CoreVar::LOCATION_CITY_ID = QString("101010100"); // 定位城市的ID
QStringList CoreVar::CURRENT_COLLECT_LIST; // 收藏城市的ID列表
// 当前是否为标题栏搜索城市
bool CoreVar::CURRENT_TITLE_SEARCH = false;
// 标题栏搜索列表
int CoreVar::TITLE_SEARCH_LIST_NUM = 1;
QGSettings *CoreVar::getSettings()
{
QGSettings *mysetting = nullptr;

View File

@ -109,6 +109,15 @@ Q_DECLARE_METATYPE(ItemData) // QVarant 注册自定义类型
Q_DECLARE_METATYPE(CollectItemData) // QVarant 注册自定义类型
Q_DECLARE_METATYPE(oneDay) // QVarant 注册自定义类型
Q_DECLARE_METATYPE(Hourly) // QVarant 注册自定义类型
enum CityType {
None = 0,
Location,
Collection,
Other,
};
class CoreVar : public QObject
{
@ -137,6 +146,21 @@ public:
static const QStringList WEATHER_CODE_TMP; //临时用--逐小时
static const QString DEFAULT_CITYID;
static const int DEFAULT_TIMEOUT; //刷新间隔
// 标题栏搜索列表
static int TITLE_SEARCH_LIST_NUM; // 搜索城市,列表个数
// 当前城市信息
static bool GET_CITY_INFO; // 得到城市信息默认为false
static CityType CURRENT_CITY_TYPE; // 当前城市的类别定位1/收藏2/其他3
static QString CURRENT_CITY_ID; // 当前城市的城市ID
static QString CURRENT_CITY_NAME; // 当前城市的城市名称
static QString LOCATION_CITY_ID; // 定位城市的ID
static QStringList CURRENT_COLLECT_LIST; // 收藏城市的ID列表
// 当前是否为标题栏搜索城市
static bool CURRENT_TITLE_SEARCH;
private:
static QGSettings *m_settings; //配置文件对象
static QGSettings *getSettings(); //初始化gsettings

View File

@ -0,0 +1,54 @@
#include "rotatechangeinfo.h"
RotateChangeInfo::RotateChangeInfo(QObject *parent) : QObject(parent)
{
qDebug() << "rotate object has created!";
connect(QApplication::primaryScreen(), &QScreen::primaryOrientationChanged, this, &RotateChangeInfo::slotRotateChanged);
QDBusConnection::sessionBus().connect(KYLIN_ROTATION_SERVICE, KYLIN_ROTATION_PATH, KYLIN_ROTATION_INTERFACE,
QString("mode_change_signal"), this, SLOT(slotModeChanged(bool)));
getCurrentScale();
getCurrentMode();
}
void RotateChangeInfo::slotRotateChanged(){
QPair<int,int> scale = getCurrentScale();
qDebug() << "horizontal & vertical mode changed sig has received! current scale: " << scale.first << "*" ;
emit sigRotationChanged(m_isPCMode,scale.first,scale.second);
}
void RotateChangeInfo::slotModeChanged(bool isPadMode){
if(isPadMode){
m_isPCMode = false;
}else{
m_isPCMode = true;
}
qDebug() << "pc & pad mode changed sig has received! current mode: " << m_isPCMode;
emit sigRotationChanged(m_isPCMode,m_screenWidth,m_screenHeight);
}
QPair<int, int> RotateChangeInfo::getCurrentScale(){
QScreen *screen = qApp->primaryScreen();
m_screenWidth = screen->size().width();
m_screenHeight = screen->size().height();
QPair<int,int> scale;
scale.first = m_screenWidth;
scale.second = m_screenHeight;
qDebug() << "screen size: " << m_screenWidth << "*" << m_screenHeight;
return scale;
}
bool RotateChangeInfo::getCurrentMode(){
QDBusMessage message_pcORpad = QDBusMessage::createMethodCall(KYLIN_ROTATION_SERVICE, KYLIN_ROTATION_PATH,
KYLIN_ROTATION_INTERFACE, QString("get_current_tabletmode"));
QDBusPendingReply<bool> reply_pcORpad = QDBusConnection::sessionBus().call(message_pcORpad);
qDebug() << " ===== INFO ===== " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__ << " getCurrentMode >> value : " << reply_pcORpad.value() << " >> isValid : " << reply_pcORpad.isValid();
if (!reply_pcORpad.isValid()) {
m_existDbus = false;
}
if (reply_pcORpad.value()) {
m_isPCMode = false;
}else{
m_isPCMode = true;
}
return m_isPCMode;
}

46
global/rotatechangeinfo.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef ROTATECHANGEINFO_H
#define ROTATECHANGEINFO_H
#include <QObject>
#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusReply>
#include <unistd.h>
#include <sys/types.h>
#include <QScreen>
#include <QPair>
static const QString KYLIN_ROTATION_PATH = "/";
static const QString KYLIN_ROTATION_SERVICE = "com.kylin.statusmanager.interface";
static const QString KYLIN_ROTATION_INTERFACE = "com.kylin.statusmanager.interface";
class RotateChangeInfo : public QObject
{
Q_OBJECT
public:
explicit RotateChangeInfo(QObject *parent = nullptr);
QPair<int,int> getCurrentScale();
bool getCurrentMode();
bool m_existDbus = true;
private:
int m_screenWidth;
int m_screenHeight;
bool m_isPCMode;
signals:
void sigRotationChanged(bool mode,int scale_W,int scale_H);
public slots:
void slotRotateChanged();
void slotModeChanged(bool isPadMode);
};
#endif // ROTATECHANGEINFO_H

View File

@ -17,33 +17,34 @@ QMap<int, QStringList> ViewVar::HOTCITY_MAP = ViewVar::saveHotCity(); //热门
QColor ViewVar::s_colorItem = QColor(120, 120, 120);
QColor ViewVar::s_colorWid = QColor(246, 246, 246, 0);
QColor ViewVar::s_colorSearch = QColor(246, 246, 246, 1);
const QSize ViewVar::COLLECT_BTNSIZE = QSize(36, 36); //收藏城市按钮大小
const QSize ViewVar::COLLECT_BTNSIZE = QSize(16, 16); //收藏城市按钮大小
const QSize ViewVar::COLLECT_BTNSIZE_WHITE = QSize(36, 36); //收藏城市按钮大小
//按钮位置
const int ViewVar::COLLECT_BTNXL = 155;
const int ViewVar::COLLECT_BTNYL = 4;
const int ViewVar::COLLECT_BTNXL = 148;
const int ViewVar::COLLECT_BTNYL = 9;
const int ViewVar::COLLECT_BTNXR = -10;
const int ViewVar::COLLECT_BTNYR = -8;
//文字位置
const int ViewVar::COLLECT_NAMEXL = 4;
const int ViewVar::COLLECT_TMPXL = 120;
const int ViewVar::COLLECT_NAMEXL = 16;
const int ViewVar::COLLECT_TMPXL = 119;
const int ViewVar::COLLECT_CODEXL = 65;
//文字位置-same
const int ViewVar::COLLECT_SAMEYL = 4;
const int ViewVar::COLLECT_SAMEYL = 0;
const int ViewVar::COLLECT_SAMEXR = -4;
const int ViewVar::COLLECT_SAMEYR = -4;
//图标位置
const int ViewVar::COLLECT_ICONXL = 80;
const int ViewVar::COLLECT_ICONYL = 4;
const int ViewVar::COLLECT_ICONXR = -144;
const int ViewVar::COLLECT_ICONYR = -6;
const int ViewVar::COLLECT_ICONXL = 93;
const int ViewVar::COLLECT_ICONYL = 16;
const int ViewVar::COLLECT_ICONXR = -116;
const int ViewVar::COLLECT_ICONYR = -20;
//按钮位置
const int ViewVar::SEARCH_BTNXL = 120;
const int ViewVar::SEARCH_BTNYL = 4;
const int ViewVar::SEARCH_BTNXL = 140;
const int ViewVar::SEARCH_BTNYL = 9;
const int ViewVar::SEARCH_BTNXR = -10;
const int ViewVar::SEARCH_BTNYR = -10;
//文字位置
const int ViewVar::SEARCH_NAMEXL = 4;
const int ViewVar::SEARCH_NAMEYL = 4;
const int ViewVar::SEARCH_NAMEXL = 16;
const int ViewVar::SEARCH_NAMEYL = 0;
const int ViewVar::SEARCH_NAMEXR = -4;
const int ViewVar::SEARCH_NAMEYR = -4;
const QString ViewVar::COLLECT_ICONPATH = QString(":/res/weather-icon/PNG16/2x/");
@ -60,28 +61,35 @@ const qreal ViewVar::SAME_OPACITY_2 = 1;
bool ViewVar::s_themeStyle = true; //默认浅色
//收藏
const QSize ViewVar::COLLECT = QSize(595, 141);
const QSize ViewVar::COLLECT_LIST = QSize(580, 115);
const QPoint ViewVar::COLLECT_TITLE = QPoint(8, 0);
const int ViewVar::NONECITYX = 10;
const int ViewVar::CITYLISTX = 14;
const QSize ViewVar::COLLECT = QSize(608, 141);
const QSize ViewVar::COLLECT_PAD = QSize(724, 161);
// const QSize ViewVar::COLLECT = QSize(608, 360);
const QSize ViewVar::COLLECT_LIST = QSize(558, 111);
const QSize ViewVar::COLLECT_LIST_PAD = QSize(666, 131);
// const QSize ViewVar::COLLECT_LIST = QSize(558, 270);
const QPoint ViewVar::COLLECT_TITLE = QPoint(49, 0);
const int ViewVar::NONECITYX = 49;
const int ViewVar::CITYLISTX = 33;
const int ViewVar::COLLECT_ITEMH = 36;
const int ViewVar::COLLECT_ITEMW = 185;
const int ViewVar::COLLECT_ITEMW = 180;
const int ViewVar::COLLECT_ITEMH_PAD = 48;
const int ViewVar::COLLECT_ITEMW_PAD = 216;
//热门
const QSize ViewVar::HOT = QSize(595, 128); //热门
const QSize ViewVar::HOT_LIST = QSize(595, 98); //热门城市列表
const QPoint ViewVar::HOT_TITLE = QPoint(8, 0); //热门-title
const int ViewVar::HOTLISTX = 0; //热门城市list x值
const int ViewVar::ITEM_LENGTHM = 2; //热门城市文字长度最大值
const int ViewVar::ITEM_NUM = 8; //热门城市每行数量
const int ViewVar::ITEM_NUMM = 17; //热门城市每行数量
const int ViewVar::ITEM_POS = (46 + 17); //热门城市item的间隔值
const int ViewVar::ITEM_DIS0 = 9; //热门城市个数值-行1
const int ViewVar::ITEM_DIS2 = 18; //热门城市个数值-行2
const QSize ViewVar::HOT = QSize(608, 138); //热门
const QSize ViewVar::HOT_LIST = QSize(608, 120); //热门城市列表
const QPoint ViewVar::HOT_TITLE = QPoint(49, 0); //热门-title
const int ViewVar::HOTLISTX = 0; //热门城市list x值
const int ViewVar::ITEM_LENGTHM = 3; //热门城市文字长度最大值
const int ViewVar::ITEM_NUM = 5; //热门城市每行数量
const int ViewVar::ITEM_NUMM = 11; //热门城市每行数量
const int ViewVar::ITEM_POS = 96; //热门城市item的间隔值
const int ViewVar::ITEM_DIS0 = 6; //热门城市个数值-行1
const int ViewVar::ITEM_DIS2 = 12; //热门城市个数值-行2
//热门-按钮大小
const QSize ViewVar::HOT_BTN = QSize(79, 28);
const QSize ViewVar::HOT_BTN = QSize(96, 36);
//搜索框
const QSize ViewVar::SEARCH_BOX = QSize(244, 36);
const QSize ViewVar::SEARCH_BOX_PAD = QSize(300, 48);
//搜索框文本间距--左上右下
const QMargins ViewVar::SEARCH_MARGINS = QMargins(34, 0, 0, 0);
//搜索框-图标控件大小
@ -91,15 +99,16 @@ const int ViewVar::SEARCH_ICON_X0 = 97 - 8;
const int ViewVar::SEARCH_ICON_X1 = 9;
//搜索列表-个尺寸大小
const QSize ViewVar::SEARCH_LIST = QSize(538, 287);
const int ViewVar::SEARCH_ITEMH = 41; //搜索城市item height值
const int ViewVar::SEARCH_ITEMW = 170; //搜索城市item weight值
const QSize ViewVar::SEARCH_LIST = QSize(572, 287);
const int ViewVar::SEARCH_ITEMH = 36; //搜索城市item height值
const int ViewVar::SEARCH_ITEMW = 180; //搜索城市item weight值
const int ViewVar::SEARCH_NONEW = 500; //搜索城市无city的控件宽度值
//搜索-收藏-总界面
const QSize ViewVar::SEARCH = QSize(610, 350);
const QSize ViewVar::SEARCH = QSize(610, 368);
const QSize ViewVar::SEARCH_PAD = QSize(726, 422);
//搜索框位置-y值
const int ViewVar::SEARCH_BOXY = 8;
const QPoint ViewVar::SEARCHLIST_POS = QPoint(46, 54); //搜索列表位置
const QPoint ViewVar::SEARCHLIST_POS = QPoint(36, 54); //搜索列表位置
const int ViewVar::SEARCH_CHANGECITYX = 8;
const int ViewVar::DISTANCE0 = 10; //间隔0--热门和收藏的相互间距
const int ViewVar::DISTANCE1 = 16; //间隔1--热门和收藏与搜索框的相互间距
@ -107,6 +116,14 @@ QString ViewVar::icon_path = QString(":/res/weather-icon/PNG48/1x/");
QStringList ViewVar::platFormList = {"V10SP1-edu"};
QString ViewVar::platForm = ViewVar::platFormType();
bool ViewVar::widgetIsShow = false;
// 主界面图标尺寸
const QSize ViewVar::CITY_ICON = QSize(48, 48);
const QSize ViewVar::CITY_ICON_MAXSIZE = QSize(96, 96);
// 标题栏搜索
const QSize ViewVar::TITLESEARCHITEMSIZE = QSize(292, 48);
bool ViewVar::m_isTitleSearch = false;
QStringList ViewVar::hotMap(QString city, QString cityId)
{
QStringList hotcity;
@ -126,21 +143,18 @@ QMap<int, QStringList> ViewVar::saveHotCity()
hotcity.insert(4, hotMap(tr("Chengdu"), "101270101"));
hotcity.insert(5, hotMap(tr("Wuhan"), "101200101"));
hotcity.insert(6, hotMap(tr("Chongqing"), "101040100"));
hotcity.insert(7, hotMap(tr("Hangzhou"), "101210101"));
hotcity.insert(8, hotMap(tr("Nanjing"), "101190101"));
hotcity.insert(9, hotMap(tr("Taibei"), "101340101"));
hotcity.insert(10, hotMap(tr("Suzhou"), "101190401"));
hotcity.insert(11, hotMap(tr("Tianjin"), "101030100"));
hotcity.insert(12, hotMap(tr("Qingdao"), "101120201"));
hotcity.insert(13, hotMap(tr("Changsha"), "101250101"));
hotcity.insert(14, hotMap(tr("Zhengzhou"), "101180101"));
hotcity.insert(15, hotMap(tr("Xian"), "101110101"));
hotcity.insert(16, hotMap(tr("Wuxi"), "101190201"));
hotcity.insert(17, hotMap(tr("Jinan"), "101120101"));
hotcity.insert(18, hotMap(tr("Hongkong"), "101320101"));
hotcity.insert(19, hotMap(tr("Macao"), "101330101")); // Macao
hotcity.insert(20, hotMap(tr("Lasa"), "101140101"));
hotcity.insert(21, hotMap(tr("Lijiang"), "101291401"));
hotcity.insert(7, hotMap(tr("Tianjin"), "101030100"));
hotcity.insert(8, hotMap(tr("Suzhou"), "101190401"));
hotcity.insert(9, hotMap(tr("Nanjing"), "101190101"));
hotcity.insert(10, hotMap(tr("Xian"), "101110101"));
hotcity.insert(11, hotMap(tr("Changsha"), "101250101"));
hotcity.insert(12, hotMap(tr("Hangzhou"), "101210101"));
hotcity.insert(13, hotMap(tr("Zhengzhou"), "101180101"));
hotcity.insert(14, hotMap(tr("Taibei"), "101340101"));
hotcity.insert(15, hotMap(tr("Hongkong"), "101320101"));
hotcity.insert(16, hotMap(tr("Macao"), "101330101"));
hotcity.insert(17, hotMap(tr("Lasa"), "101140101"));
return hotcity;
}
void ViewVar::initGsetting()
@ -208,3 +222,50 @@ QString ViewVar::platFormType()
platformName = systemInformation.getProjectCodeName();
return platformName;
}
ViewVar::ViewVar()
{
m_rotateChange = new RotateChangeInfo(this);
connect(m_rotateChange, &RotateChangeInfo::sigRotationChanged, this, &ViewVar::slotChangeModel);
getCurrentMode();
}
void ViewVar::slotChangeModel(bool isPCMode, int width, int height)
{
m_currentSize.first = width;
m_currentSize.second = height;
if (isPCMode) {
m_currentMode = CurrentMode::PCMode;
emit sigChangeModeToPc();
} else {
if (width > height) {
m_currentMode = CurrentMode::PadHMode;
emit sigChangeModeToPadH();
} else {
m_currentMode = CurrentMode::PadVMode;
emit sigChangeModeToPadV();
}
}
return;
}
CurrentMode ViewVar::getCurrentMode()
{
bool isPCMode = m_rotateChange->getCurrentMode();
QPair<int, int> currentSize = m_rotateChange->getCurrentScale();
if (!m_rotateChange->m_existDbus) {
m_currentMode = CurrentMode::PCMode;
return m_currentMode;
}
m_currentSize = currentSize;
if (isPCMode) {
m_currentMode = CurrentMode::PCMode;
} else {
if (currentSize.first > currentSize.second) {
m_currentMode = CurrentMode::PadHMode;
} else {
m_currentMode = CurrentMode::PadVMode;
}
}
return m_currentMode;
}

View File

@ -17,6 +17,14 @@
#include <QMargins>
#include <gsettings.hpp>
#include <system_information.hpp>
#include "rotatechangeinfo.h"
enum CurrentMode {
PCMode = 0,
PadHMode,
PadVMode,
};
class ViewVar : public QObject
{
Q_OBJECT
@ -26,6 +34,7 @@ public:
static QColor s_colorWid; //收藏城市颜色
static QColor s_colorSearch; //收藏城市颜色
static const QSize COLLECT_BTNSIZE; //收藏城市按钮大小
static const QSize COLLECT_BTNSIZE_WHITE; //收藏城市按钮大小
static QString icon_path; //主界面图标路径
//按钮位置-收藏
static const int COLLECT_BTNXL;
@ -71,12 +80,16 @@ public:
//各窗口大小
//收藏
static const QSize COLLECT; //收藏
static const QSize COLLECT_PAD; //收藏(PAD)
static const QSize COLLECT_LIST; //收藏
static const QSize COLLECT_LIST_PAD;//收藏(Pad)
static const QPoint COLLECT_TITLE; //收藏-title
static const int NONECITYX; //无收藏城市x值
static const int CITYLISTX; //收藏城市list x值
static const int COLLECT_ITEMH; //收藏城市item height值
static const int COLLECT_ITEMW; //收藏城市item weight值
static const int COLLECT_ITEMH_PAD;//收藏城市item height值(pad)
static const int COLLECT_ITEMW_PAD;//收藏城市item weight值(pad)
//热门
static const QSize HOT; //热门
static const QSize HOT_LIST; //热门城市列表
@ -92,6 +105,7 @@ public:
static const QSize HOT_BTN; //热门-按钮
//搜索框
static const QSize SEARCH_BOX;
static const QSize SEARCH_BOX_PAD;
static const QMargins SEARCH_MARGINS; //搜索框文本间距--左上右下
static const QSize SEARCH_ICON; //搜索框-图标控件大小
@ -106,6 +120,7 @@ public:
//搜索-收藏-总界面
static const QSize SEARCH;
static const QSize SEARCH_PAD; // 收藏界面尺寸PAD
static const int SEARCH_BOXY; //搜索框位置-y值
static const QPoint SEARCHLIST_POS; //搜索列表位置
static const int SEARCH_CHANGECITYX; //交换位置的x值
@ -119,16 +134,42 @@ public:
static QStringList platFormList; //平台
static QString platForm; //平台
static bool widgetIsShow; //默认没有显示窗口
// 标题栏搜索
static const QSize TITLESEARCHITEMSIZE;
static bool m_isTitleSearch;
// 主界面图标尺寸
static const QSize CITY_ICON; // 主界面的城市图标
static const QSize CITY_ICON_MAXSIZE; // 主界面的城市图标(平板模式)
// 搜藏城市尺寸
static const QSize COLLECT_SIZE;
static const QSize COLLECT_SIZE_PAD;
static const QSize COLLECT_ITEM_SIZE;
static const QSize COLLECT_ITEM_SIZE_PAD;
// 获取当前模式
CurrentMode getCurrentMode();
CurrentMode m_currentMode = CurrentMode::PCMode;
QPair<int, int> m_currentSize;
private:
ViewVar();
static QStringList hotMap(QString city, QString cityId);
static void monitorGsetting(); //主题gsettings监听
static ViewVar *m_viewVar; //单例指针
static QString platFormType(); //获得平台名字
RotateChangeInfo *m_rotateChange = nullptr; // 平板切换
void slotChangeModel(bool mode,int width,int height);
signals:
void monitorThemeChanged(QString themeType);
void setFontSizeSignal(int);
void sigChangeModeToPadH(); // 切换平板横屏
void sigChangeModeToPadV(); // 切换平板竖屏
void sigChangeModeToPc(); // 切换PC模式
};
#endif // VIEWVAR_H

View File

@ -2,11 +2,14 @@
Name=Weather
Name[zh_CN]=天气
Name[bo_CN]=གནམ་གཤིས།
Name[zh_HK]=天氣
Comment[bo_CN]=ཀྲུང་གོའི་དུས་ལྟར་གནམ་གཤིས།
Comment=Indicator applet for current weather conditions in China
Comment[zh_CN]=中国实时天气
Comment[zh_HK]=中國實时天氣
GenericName[bo_CN]=གནམ་གཤིས།
GenericName=China Weather Applet
GenericName[zh_HK]=天氣
Keywords=weather,china
Exec=/usr/bin/kylin-weather showmainwindow%u
Icon=kylin-weather

View File

@ -5,7 +5,12 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = kylin-weather
TEMPLATE = app
# about widget version
VERSION = 3.2.0.8-2k11
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
CONFIG += link_pkgconfig c++11
QMAKE_CXXFLAGS += -Wall -g -O0
PKGCONFIG += kysdk-qtwidgets kysdk-log kysdk-waylandhelper kysdk-kabase gsettings-qt
@ -20,20 +25,23 @@ INCLUDEPATH += kabase/
INCLUDEPATH += kabase/Qt
!system($$PWD/translations/generate_translations_pm.sh): error("Failed to generate pm")
qm_files.files = translations/*.qm
qm_files.path = /usr/share/kylin-weather/translations/
TRANSLATIONS += \
translations/kylin-weather_zh_CN.ts \
translations/kylin-weather_kk.ts \
translations/kylin-weather_ky.ts \
translations/kylin-weather_ug.ts \
translations/kylin-weather_bo_CN.ts
translations/kylin-weather_bo_CN.ts \
translations/kylin-weather_zh_HK.ts
#-------------------仅保持原样实际不生效了后续修改在weather-install.pro中
#settings.files = data/org.kylin.weather.gschema.xml
qm_files.files = translations/*.qm
qm_files.path = /usr/share/kylin-weather/translations/
settings.files += \
$$PWD/data/org.kylin.weather.gschema.xml \
$$PWD/data/org.ukui.log4qt.kylin-weather.gschema.xml
settings.path = /usr/share/glib-2.0/schemas/
target.source += $$TARGET
target.path = /usr/bin
@ -41,8 +49,6 @@ target.path = /usr/bin
icons.files += res/kylin-weather.png
icons.path = /usr/share/pixmaps/
settings.path = /usr/share/glib-2.0/schemas/
appdesktop.files += kylin-weather.desktop
appdesktop.path = /usr/share/applications/
@ -107,12 +113,17 @@ SOURCES += \
view/search/collectitemdelegate.cpp \
view/search/hotcity.cpp \
view/search/hotcitybtn.cpp \
view/search/searchbox.cpp \
view/search/searchbtn.cpp \
view/search/searchcitylist.cpp \
view/search/searchdelegate.cpp \
view/search/searchview.cpp \
view/verscreen/verscreen.cpp
view/verscreen/verscreen.cpp \
view/horscreen/changecitywidget.cpp \
view/search/titlesearchcityview.cpp \
view/search/titlesearchlistdelegate.cpp \
view/search/bottomlistview.cpp \
view/search/bottomlistdelegate.cpp \
model/titlesearchmodel.cpp \
global/rotatechangeinfo.cpp \
HEADERS += \
controller/Interaction.h \
@ -156,12 +167,17 @@ HEADERS += \
view/search/collectitemdelegate.h \
view/search/hotcity.h \
view/search/hotcitybtn.h \
view/search/searchbox.h \
view/search/searchbtn.h \
view/search/searchcitylist.h \
view/search/searchdelegate.h \
view/search/searchview.h \
view/verscreen/verscreen.h
view/verscreen/verscreen.h \
view/horscreen/changecitywidget.h \
view/search/titlesearchcityview.h \
view/search/titlesearchlistdelegate.h \
view/search/bottomlistview.h \
view/search/bottomlistdelegate.h \
model/titlesearchmodel.h \
global/rotatechangeinfo.h \
DISTFILES += \
data/org.kylin.weather.gschema.xml \

View File

@ -5,6 +5,7 @@ DataParser::DataParser() {}
//处理返回的网络数据
void DataParser::dataReply(QByteArray dataBa)
{
qDebug() << " ##### Function Positioning ##### 处理返回的网络数据 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//数据异常
QJsonParseError jsonParserErr;
QJsonDocument jsonDocument = QJsonDocument::fromJson(dataBa, &jsonParserErr);
@ -35,40 +36,52 @@ void DataParser::dataReply(QByteArray dataBa)
return;
}
CurrentWeather m_currentWeather;
QList<Hourly> hourlist;
bool success = true;
//解析当前城市天气状况和一周预报天气
if (mainObj.contains("weather")) {
QJsonObject weatherObj = mainObj.value("weather").toObject();
if (!weatherObj.isEmpty() && weatherObj.size() > 0) {
CurrentWeather m_currentWeather;
currentWeather(weatherObj, m_currentWeather);
m_currentWeather = currentWeather(weatherObj);
forcastWeather(weatherObj, m_currentWeather);
}
} else {
// ErrorReact::getInstance()->dataFeedBack(false,"无当前城市天气信息");
ErrorReact::getInstance()->dataFeedBack(false, tr("Data is empty"));
return;
success = false;
}
//解析生活指数信息
if (mainObj.contains("lifestyle")) {
QJsonObject lifestyleObj = mainObj.value("lifestyle").toObject();
lifeStyle(lifestyleObj);
} else {
// ErrorReact::getInstance()->dataFeedBack(false,"无生活指数信息");
ErrorReact::getInstance()->dataFeedBack(false, tr("Data is empty"));
return;
}
// QJsonObject hourlyObj = mainObj.value("hourly").toObject();
// QList<Hourly>hourlist;
// tmphourlyWeather(hourlyObj,hourlist);
//随机生成逐小时的天气信息----备用,先模拟一个逐小时天气信息
//解析逐小时天气信息
if (mainObj.contains("hourly")) {
QJsonObject hourlyObj = mainObj.value("hourly").toObject();
QList<Hourly> hourlist;
hourlyWeather(hourlyObj, hourlist);
hourlist = hourlyWeather(hourlyObj);
} else {
ErrorReact::getInstance()->dataFeedBack(false, "无逐小时信息");
return;
success = false;
}
if (success){
emit showCurrent(m_currentWeather);
QVariant var;
var.setValue<QList<Hourly>>(hourlist);
emit showHourly(var);
//将当前城市信息存入配置文件
if (hourlist.length() > 0) {
QStringList serveTimeList = m_currentWeather.serveTime.split(' ');
if (hourlist.first().time.length() > 1 && serveTimeList.length() > 0) {
m_currentWeather.serveTime = serveTimeList.first() + " " + hourlist.first().time.mid(0);
}
}
setGsettings(m_currentWeather);
} else {
ErrorReact::getInstance()->dataFeedBack(false, tr("Data is empty"));
}
}
@ -127,8 +140,10 @@ void DataParser::lifeStyle(QJsonObject lifestyleObj)
emit showLifeStyle(m_lifestyle);
}
//解析当前城市信息
void DataParser::currentWeather(QJsonObject weatherObj, CurrentWeather currentWeather)
CurrentWeather DataParser::currentWeather(QJsonObject weatherObj)
{
CurrentWeather currentWeather;
qDebug() << " ##### Function Positioning ##### 解析当前城市信息 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//当前城市id
QString id_msg = weatherObj.value("id").toString();
if (id_msg != "") {
@ -156,9 +171,7 @@ void DataParser::currentWeather(QJsonObject weatherObj, CurrentWeather currentWe
currentWeather.cond_code = m_json.value("cond_code").toString();
currentWeather.wind_dir = m_json.value("wind_dir").toString();
currentWeather.serveTime = weatherObj.value("update_time").toString();
//将当前城市信息存入配置文件
setGsettings(currentWeather);
qDebug() << " ##### Function Positioning ##### 解析当前城市信息 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
} else {
currentWeather.tmp = "N/A";
@ -168,12 +181,11 @@ void DataParser::currentWeather(QJsonObject weatherObj, CurrentWeather currentWe
currentWeather.cond_code = "999";
currentWeather.wind_dir = "N/A";
currentWeather.serveTime = "N/A";
setGsettings(currentWeather);
// ErrorReact::getInstance()->dataFeedBack(false,"服务器返回数据为空或不全");
ErrorReact::getInstance()->dataFeedBack(false, tr("Data is empty"));
qDebug() << " ##### Function Positioning ##### 解析当前城市信息 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
}
emit showCurrent(currentWeather);
forcastWeather(weatherObj, currentWeather);
return currentWeather;
}
//解析预报天气信息
void DataParser::forcastWeather(QJsonObject weatherObj, CurrentWeather currentWeather)
@ -266,15 +278,16 @@ void DataParser::collectWeather(QString weatherList)
emit showCollectCode(collectItemList);
}
void DataParser::hourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist)
QList<Hourly> DataParser::hourlyWeather(QJsonObject hourlyObj)
{
QList<Hourly> hourlist;
if (hourlyObj.contains(QStringLiteral("hourly"))) {
QJsonValue arrayValue = hourlyObj.value(QStringLiteral("hourly"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
if (array.size() != 24) {
ErrorReact::getInstance()->dataFeedBack(false, tr("hourly != 24"));
return;
return hourlist;
}
for (int i = 0; i < array.size(); i++) {
QJsonValue jsonArray = array.at(i);
@ -282,7 +295,7 @@ void DataParser::hourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist)
Hourly tmp_hour;
if (!(m_json.contains("icon") && m_json.contains("fxTime") && m_json.contains("temp"))) {
ErrorReact::getInstance()->dataFeedBack(false, tr("hourly key is wrong"));
return;
return hourlist;
}
if (m_json.value("icon").toString() == "" || m_json.value("fxTime").toString() == ""
|| m_json.value("temp").toString() == "") {
@ -300,16 +313,9 @@ void DataParser::hourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist)
}
hourlist.append(tmp_hour);
}
} else {
ErrorReact::getInstance()->dataFeedBack(false, tr("Hourly is not array"));
return;
}
QVariant var;
var.setValue<QList<Hourly>>(hourlist);
emit showHourly(var);
} else {
ErrorReact::getInstance()->dataFeedBack(false, tr("Hourly is not exits"));
}
return hourlist;
}
//临时用
void DataParser::tmphourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist)

View File

@ -24,11 +24,11 @@ signals:
void showHourly(QVariant varHour); //逐小时天气信息
private:
void lifeStyle(QJsonObject lifestyleObj); //解析生活指数信息
void currentWeather(QJsonObject weatherObj, CurrentWeather currentWeather); //解析当前城市信息
CurrentWeather currentWeather(QJsonObject weatherObj); //解析当前城市信息
void forcastWeather(QJsonObject weatherObj, CurrentWeather currentWeather); //解析预报天气信息
void setGsettings(CurrentWeather currentWeather); //存当前城市信息于配置文件
void collectWeather(QString weatherList); //解析当前城市信息
void hourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist); //解析逐小时信息
QList<Hourly> hourlyWeather(QJsonObject hourlyObj); //解析逐小时信息
void tmphourlyWeather(QJsonObject hourlyObj, QList<Hourly> hourlist); //解析逐小时信息
void setCollectValue(int i, const QJsonObject &json, ForecastWeather &forecastweather,
const QString &dateTime); //给预报天气的结构体的每一天赋值

View File

@ -15,6 +15,7 @@ DataRequest::~DataRequest()
//利用连接请求网络数据
void DataRequest::dataRequest(const QString &cityId)
{
qDebug() << " ##### Function Positioning ##### 利用连接请求网络数据 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
if (cityId.isEmpty()) {
return;
}
@ -29,6 +30,7 @@ void DataRequest::dataRequest(const QString &cityId)
eventLoop.exec();
//超时处理
if (!timeOut(&m_timer, m_reply, &eventLoop)) {
qDebug() << " ##### Function Positioning ##### 超时处理 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
ErrorReact::getInstance()->networkTimeout("true"); //超时
return;
} else {
@ -40,6 +42,7 @@ void DataRequest::dataRequest(const QString &cityId)
//处理返回的网络数据
void DataRequest::dataReply()
{
qDebug() << " ##### Function Positioning ##### 处理返回的网络数据 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
// QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
int statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
//状态码不为200时异常

View File

@ -9,8 +9,11 @@ Network::Network(QObject *parent) : QObject(parent)
//检查网络
void Network::checkNetWork()
{
qDebug() << " ##### Function Positioning ##### 检查网络 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
QNetworkConfigurationManager mgr;
if (mgr.isOnline()) {
qDebug() << " ##### Function Positioning ##### QNetworkConfigurationManager ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//判断网络是否有连接不一定能上网如果连接了则开始检查互联网是否可以ping通
QHostInfo::lookupHost("www.gov.cn", this, SLOT(checkNetAvailable(QHostInfo)));
} else {
@ -21,6 +24,7 @@ void Network::checkNetWork()
//检查网络可用
void Network::checkNetAvailable(const QHostInfo &host)
{
qDebug() << " ##### Function Positioning ##### 检查网络可用 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
//判断网络可用---返回错误原因
if (host.error() != QHostInfo::NoError) {
ErrorReact::getInstance()->networkFeedBack(false, host.errorString());
@ -110,6 +114,10 @@ void Network::initConnect()
QString("/org/freedesktop/NetworkManager"),
QString("org.freedesktop.NetworkManager"), QString("PropertiesChanged"), this,
SLOT(onPropertiesChanged(QVariantMap)));
QDBusConnection::sessionBus().connect(QString("org.ukui.ScreenSaver"),
QString("/"),
QString("org.ukui.ScreenSaver"), QString("unlock"), this,
SLOT(onScreenSaverUnlock()));
}
void Network::onTimeFinished()
@ -117,3 +125,8 @@ void Network::onTimeFinished()
//发送信号--刷新界面
emit haveNet();
}
void Network::onScreenSaverUnlock()
{
emit haveNet();
}

View File

@ -30,6 +30,7 @@ private slots:
void checkNetAvailable(const QHostInfo &host); //检查网络可用
void onPropertiesChanged(QVariantMap qvm); //监听断网联网
void onTimeFinished(); //延时发送重新定位请求
void onScreenSaverUnlock(); //监听屏幕解锁
signals:
void effectiveNetwork(bool isOnline); //网络连接正常
void haveNet(); //网络从无到有,开始刷新

View File

@ -36,15 +36,15 @@ void SearchThread::run()
LocationData data;
data.id = id.remove(0, 2); // remove "CN"
data.city_en = resultList.at(1);
data.city = resultList.at(2);
data.city_en = resultList.at(1).toLower().remove(QRegExp("\\s")).remove("'");
data.city = resultList.at(2).toLower().remove(QRegExp("\\s")).remove("'");
data.country_en = resultList.at(4);
data.country = resultList.at(5);
data.province_en = resultList.at(6);
data.province = resultList.at(7);
data.province_en = resultList.at(6).toLower().remove(QRegExp("\\s")).remove("'");
data.province = resultList.at(7).toLower().remove(QRegExp("\\s")).remove("'");
data.admin_district_en = resultList.at(8);
data.admin_district = resultList.at(9);
data.shorthand = resultList.at(10);
data.shorthand = resultList.last().toLower().remove(QRegExp("\\s")).remove("'");
m_worker->m_locatonList << data; //将数据存入m_locatonList中
@ -72,15 +72,12 @@ QList<LocationData> SearchMarch::exactMatchCity(const QString &inputText) const
QList<LocationData> searchedList;
//搜索匹配-遍历m_locatonList
for (const LocationData line : m_locatonList) {
if (line.shorthand.toLower().remove(QRegExp("\\s")).remove("'") == inputText || line.id == inputText
|| //拼音和ID
line.province.toLower().remove(QRegExp("\\s")).remove("'") == inputText
|| line.province_en.toLower().remove(QRegExp("\\s")).remove("'") == inputText || //省
line.city.toLower().remove(QRegExp("\\s")).remove("'").contains(inputText)
|| line.city_en.toLower().remove(QRegExp("\\s")).remove("'").contains(inputText) //县
if (line.shorthand == inputText || line.id == inputText || //拼音和ID
line.province == inputText || line.province_en == inputText || //省
line.city.contains(inputText) || line.city_en.contains(inputText) //县
) {
//保证完全匹配的字符串放在显示的第一个
if (inputText == line.city_en.toLower().remove(QRegExp("\\s")).remove("'")) {
if (inputText == line.city_en) {
searchedList.insert(0, line);
} else {
searchedList.append(line); //将数据加入列表
@ -135,3 +132,46 @@ QString SearchMarch::setAutomaticCity(const QString &cityName)
}
return cityId;
}
//自动定位-查找当前地区id
QString SearchMarch::matchCityName(const QString &ID)
{
QString cityId = QString("CN%1").arg(ID);
QString cityName;
if (cityId.isEmpty()) {
return cityName;
}
QFile file(":/data/data/china-city-list.csv");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString line = file.readLine();
line = line.replace("\n", "");
while (!line.isEmpty()) {
QStringList resultList = line.split(",");
if (resultList.length() < 10) {
line = file.readLine();
line = line.replace("\n", "");
continue;
}
//("CN101340406", "yunlin", "云林", "CN", "China", "中国", "taiwan", "台湾", "taizhong", "台中", "yl",
//"23.718", "120.538", "710000")
QString id = resultList.at(0);
if (!id.startsWith("CN")) {
line = file.readLine();
line = line.replace("\n", "");
continue;
}
//对比cityID和词表的city拿name
if (resultList.at(0).compare(cityId, Qt::CaseInsensitive) == 0) {
cityName = resultList.at(2);
break;
}
line = file.readLine();
line = line.replace("\n", "");
}
file.close();
}
return cityName;
}

View File

@ -28,6 +28,7 @@ public:
explicit SearchMarch(QObject *parent = 0);
~SearchMarch();
QString setAutomaticCity(const QString &cityName); //定位当前城市
QString matchCityName(const QString &cityId); //定位当前城市
//将匹配到的每个城市加入一个列表中
QList<LocationData> exactMatchCity(const QString &inputText) const;
QList<LocationData> m_locatonList;

View File

@ -0,0 +1,12 @@
#include "titlesearchmodel.h"
TitleSearchModel::TitleSearchModel() : QStandardItemModel(NULL)
{
QHash<int, QByteArray> roleNames;
roleNames[CityId] = "cityid";
roleNames[CityName] = "cityname";
roleNames[CityStyle] = "citystyle";
setItemRoleNames(roleNames);
}
TitleSearchModel::~TitleSearchModel() {}

33
model/titlesearchmodel.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef TITLESEARCHMODEL_H
#define TITLESEARCHMODEL_H
#include <QObject>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QVariant>
#include <QHash>
#include <QDebug>
#include <QUuid>
class TitleSearchModel : public QStandardItemModel
{
Q_OBJECT
public:
TitleSearchModel();
~TitleSearchModel();
enum CityRoles {
CityId = Qt::UserRole + 1,
CityName,
CityStyle,
};
enum CityType {
Location = 0,
Collection,
};
private:
signals:
};
#endif // FRIENDLISTMODEL_H

13
res.qrc
View File

@ -230,5 +230,18 @@
<file>res/contorl_icons/search_light.png</file>
<file>res/contorl_icons/selected_normal.png</file>
<file>res/contorl_icons/selected_dark.png</file>
<file>res/contorl_icons/loadgif23.gif</file>
<file>res/contorl_icons/add_click.png</file>
<file>res/contorl_icons/add_hover.png</file>
<file>res/contorl_icons/add_normal.png</file>
<file>res/image/kylin-icon-collect-symbolic.png</file>
<file>res/image/kylin-icon-uncollect-symbolic.png</file>
<file>res/image/ukui-icon-point/normal-symbolic.png</file>
<file>res/image/ukui-icon-point/select-symbolic.png</file>
<file>res/image/ukui-icon-Location/normal-symbolic.png</file>
<file>res/image/ukui-icon-Location/select-symbolic.png</file>
<file>res/image/ukui-icon-city management/click-symbolic.png</file>
<file>res/image/ukui-icon-city management/hover-symbolic.png</file>
<file>res/image/ukui-icon-city management/normal-symbolic.png</file>
</qresource>
</RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Some files were not shown because too many files have changed in this diff Show More