}
}
-bool StationListModel::setData(const QModelIndex &index, QVariant &value, int role)
+bool StationListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
return false;
}
Settings *settings = Settings::instance();
settings->setFavoriteStations(QStringList::fromSet(m_favorites));
- QVector<int> changedRoles;
- changedRoles << FavoriteIndicatorRole;
- //emit dataChanged(index, index, changedRoles);
emit dataChanged(index, index);
}
return true;
Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const;
Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const;
- Q_INVOKABLE bool setData(const QModelIndex &index, QVariant &value, int role = Qt::EditRole);
+ Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
signals:
#include <QtGlobal>
#include <QDebug>
#include <QGeoCoordinate>
+#include <QGeoPositionInfo>
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QTM_USE_NAMESPACE
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSortCaseSensitivity(Qt::CaseInsensitive);
setDynamicSortFilter(true);
+ qRegisterMetaType<QGeoCoordinate>();
if (positionInfoSource) {
qDebug() << "position info source available";
connect(positionInfoSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
} else {
qDebug() << "No position info source available";
}
+ connect(settings, SIGNAL(favoriteStationsChanged()),
+ this, SLOT(updateFavoriteStations()));
+ updateFavoriteStations();
connect(settings, SIGNAL(recentStationsChanged()),
this, SLOT(updateRecentStations()));
updateRecentStations();
}
+Qt::ItemFlags StationListProxyModel::flags(const QModelIndex &index) const
+{
+ return QSortFilterProxyModel::flags(index);
+}
+
+bool StationListProxyModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ return QSortFilterProxyModel::setData(index, value, role);
+}
+
bool StationListProxyModel::lessThan(const QModelIndex &left,
const QModelIndex &right) const
{
setRecentStations(settings->recentStations());
}
+void StationListProxyModel::setFavoriteStations(const QStringList &stations)
+{
+ qDebug() << "Favorite stations are now" << stations;
+ if (sortingMode() == StationListProxyModel::AlphaSorting) {
+ invalidate();
+ }
+}
+
+void StationListProxyModel::updateFavoriteStations(void)
+{
+ Settings *settings = Settings::instance();
+ setFavoriteStations(settings->favoriteStations());
+}
+
bool StationListProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
explicit StationListProxyModel(QObject *parent = 0);
+ Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const;
+ Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+
QString searchPattern() const;
void setSearchPattern(const QString &pattern);
Q_INVOKABLE void setUserPosition(const QGeoCoordinate &pos);
Q_INVOKABLE void setRecentStations(const QStringList &stations);
Q_INVOKABLE void setRecentOnlyFilter(bool);
+ Q_INVOKABLE void setFavoriteStations(const QStringList &stations);
signals:
void sortingModeChanged(SortingMode mode);
private slots:
void updatePosition(const QGeoPositionInfo &update);
void updateRecentStations(void);
+ void updateFavoriteStations(void);
private:
QString m_searchPattern;
QGeoPositionInfoSource *positionInfoSource;