Commit a8764f3b authored by Stuart Dilts's avatar Stuart Dilts Committed by Devin Lin
Browse files

Avoid unneeded copies

Avoid unneeded copies by using const references and `std::move` where
possible.
+ Changes suggested by clang-tidy
parent fd019caa
Pipeline #72960 passed with stage
in 17 seconds
......@@ -58,14 +58,14 @@ KWeatherCore::LocationQueryResult LocationQueryModel::get(int index)
void LocationQueryModel::textChanged(QString query, int timeout)
{
m_text = query;
m_text = std::move(query);
beginResetModel();
// clear results list
m_results.clear();
endResetModel();
if (!query.isEmpty()) { // do not query nothing
if (!m_text.isEmpty()) { // do not query nothing
m_loading = true;
m_networkError = false;
Q_EMIT propertyChanged();
......
......@@ -40,7 +40,7 @@ QHash<int, QByteArray> HourlyModel::roleNames() const
void HourlyModel::loadForecast(QExplicitlySharedDataPointer<KWeatherCore::WeatherForecast> forecast)
{
beginResetModel();
m_location = forecast;
m_location = std::move(forecast);
endResetModel();
Q_EMIT reseted();
}
......
......@@ -18,7 +18,7 @@ WeatherDay::WeatherDay(WeatherDayListModel *parent)
WeatherDay::WeatherDay(SharedForecastPtr ptr, int day, WeatherDayListModel *parent)
: QObject(parent)
, m_day(day)
, m_forecast(ptr)
, m_forecast(std::move(ptr))
{
if (parent)
connect(parent, &WeatherDayListModel::weatherRefresh, this, &WeatherDay::refreshDaysFromForecasts);
......@@ -47,7 +47,7 @@ void WeatherDay::determineSunrise()
}
void WeatherDay::refreshDaysFromForecasts(SharedForecastPtr ptr)
{
m_forecast = ptr;
m_forecast = std::move(ptr);
determineSunrise();
Q_EMIT propertyChanged();
}
......@@ -18,14 +18,14 @@ WeatherHour::WeatherHour(WeatherHourListModel *parent)
WeatherHour::WeatherHour(SharedForecastPtr ptr, int day, int hour, WeatherHourListModel *parent)
: QObject(parent)
, m_forecast(ptr)
, m_forecast(std::move(ptr))
, m_day(day)
, m_hour(hour)
{
}
void WeatherHour::refreshHoursFromForecasts(SharedForecastPtr ptr)
{
m_forecast = ptr;
m_forecast = std::move(ptr);
Q_EMIT propertyChanged();
}
QString WeatherHour::windSpeed() const
......
......@@ -152,7 +152,7 @@ int WeatherLocationListModel::count() const
void WeatherLocationListModel::addLocation(const KWeatherCore::LocationQueryResult &ret)
{
qDebug() << "add location";
auto locId = ret.geonameId(), locName = ret.toponymName();
const auto &locId = ret.geonameId(), &locName = ret.toponymName();
auto lat = ret.latitude(), lon = ret.longitude();
// add location
......@@ -176,7 +176,7 @@ void WeatherLocationListModel::requestCurrentLocation()
connect(geoPtr, &KWeatherCore::LocationQuery::located, this, &WeatherLocationListModel::addCurrentLocation);
}
void WeatherLocationListModel::addCurrentLocation(KWeatherCore::LocationQueryResult ret)
void WeatherLocationListModel::addCurrentLocation(const KWeatherCore::LocationQueryResult &ret)
{
auto location = new WeatherLocation(ret.geonameId(), ret.toponymName(), QString(), ret.latitude(), ret.longitude());
location->update();
......
......@@ -46,7 +46,7 @@ protected:
return m_locations;
}
private Q_SLOTS:
void addCurrentLocation(KWeatherCore::LocationQueryResult ret);
void addCurrentLocation(const KWeatherCore::LocationQueryResult &ret);
private:
std::vector<WeatherLocation *> m_locations;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment