mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:30:05 +00:00
Add favorite selection to radar toolbox
This commit is contained in:
parent
9d673af291
commit
436a3e0a9f
5 changed files with 205 additions and 53 deletions
|
|
@ -224,7 +224,13 @@ void RadarSiteModel::ToggleFavorite(int row)
|
|||
{
|
||||
if (row >= 0 && row < p->favorites_.size())
|
||||
{
|
||||
p->favorites_.at(row) = !p->favorites_.at(row);
|
||||
bool isFavorite = !p->favorites_.at(row);
|
||||
p->favorites_.at(row) = isFavorite;
|
||||
|
||||
QModelIndex index = createIndex(row, static_cast<int>(Column::Favorite));
|
||||
Q_EMIT dataChanged(index, index);
|
||||
|
||||
Q_EMIT FavoriteToggled(p->radarSites_.at(row)->id(), isFavorite);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,6 +254,25 @@ RadarSiteModelImpl::RadarSiteModelImpl() :
|
|||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<RadarSiteModel> RadarSiteModel::Instance()
|
||||
{
|
||||
static std::weak_ptr<RadarSiteModel> radarSiteModelReference_ {};
|
||||
static std::mutex instanceMutex_ {};
|
||||
|
||||
std::unique_lock lock(instanceMutex_);
|
||||
|
||||
std::shared_ptr<RadarSiteModel> radarSiteModel =
|
||||
radarSiteModelReference_.lock();
|
||||
|
||||
if (radarSiteModel == nullptr)
|
||||
{
|
||||
radarSiteModel = std::make_shared<RadarSiteModel>();
|
||||
radarSiteModelReference_ = radarSiteModel;
|
||||
}
|
||||
|
||||
return radarSiteModel;
|
||||
}
|
||||
|
||||
} // namespace model
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ class RadarSiteModelImpl;
|
|||
|
||||
class RadarSiteModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class Column : int
|
||||
{
|
||||
|
|
@ -44,6 +46,11 @@ public:
|
|||
void HandleMapUpdate(double latitude, double longitude);
|
||||
void ToggleFavorite(int row);
|
||||
|
||||
static std::shared_ptr<RadarSiteModel> Instance();
|
||||
|
||||
signals:
|
||||
void FavoriteToggled(const std::string& siteId, bool isFavorite);
|
||||
|
||||
private:
|
||||
std::unique_ptr<RadarSiteModelImpl> p;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue