mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 14:50:05 +00:00
Mark favorites in radar site dialog
- No effect currently - Does not persist through application restart
This commit is contained in:
parent
e721633629
commit
9d673af291
6 changed files with 114 additions and 34 deletions
1
scwx-qt/res/icons/font-awesome-6/star-solid.svg
Normal file
1
scwx-qt/res/icons/font-awesome-6/star-solid.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="18" viewBox="0 0 576 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path opacity="1" fill="#000000" d="M316.9 18C311.6 7 300.4 0 288.1 0s-23.4 7-28.8 18L195 150.3 51.4 171.5c-12 1.8-22 10.2-25.7 21.7s-.7 24.2 7.9 32.7L137.8 329 113.2 474.7c-2 12 3 24.2 12.9 31.3s23 8 33.8 2.3l128.3-68.5 128.3 68.5c10.8 5.7 23.9 4.9 33.8-2.3s14.9-19.3 12.9-31.3L438.5 329 542.7 225.9c8.6-8.5 11.7-21.2 7.9-32.7s-13.7-19.9-25.7-21.7L381.2 150.3 316.9 18z"/></svg>
|
||||
|
After Width: | Height: | Size: 615 B |
|
|
@ -45,6 +45,7 @@
|
|||
<file>res/icons/font-awesome-6/square-caret-right-regular.svg</file>
|
||||
<file>res/icons/font-awesome-6/square-minus-regular.svg</file>
|
||||
<file>res/icons/font-awesome-6/square-plus-regular.svg</file>
|
||||
<file>res/icons/font-awesome-6/star-solid.svg</file>
|
||||
<file>res/icons/font-awesome-6/stop-solid.svg</file>
|
||||
<file>res/icons/font-awesome-6/volume-high-solid.svg</file>
|
||||
<file>res/palettes/wct/CC.pal</file>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <scwx/common/geographic.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
|
|
@ -15,15 +17,11 @@ namespace model
|
|||
static const std::string logPrefix_ = "scwx::qt::model::radar_site_model";
|
||||
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||
|
||||
static constexpr size_t kColumnSiteId = 0u;
|
||||
static constexpr size_t kColumnPlace = 1u;
|
||||
static constexpr size_t kColumnState = 2u;
|
||||
static constexpr size_t kColumnCountry = 3u;
|
||||
static constexpr size_t kColumnLatitude = 4u;
|
||||
static constexpr size_t kColumnLongitude = 5u;
|
||||
static constexpr size_t kColumnType = 6u;
|
||||
static constexpr size_t kColumnDistance = 7u;
|
||||
static constexpr size_t kNumColumns = 8u;
|
||||
static constexpr int kFirstColumn =
|
||||
static_cast<int>(RadarSiteModel::Column::SiteId);
|
||||
static constexpr int kLastColumn =
|
||||
static_cast<int>(RadarSiteModel::Column::Favorite);
|
||||
static constexpr int kNumColumns = kLastColumn - kFirstColumn + 1;
|
||||
|
||||
class RadarSiteModelImpl
|
||||
{
|
||||
|
|
@ -32,12 +30,15 @@ public:
|
|||
~RadarSiteModelImpl() = default;
|
||||
|
||||
QList<std::shared_ptr<config::RadarSite>> radarSites_;
|
||||
std::vector<bool> favorites_;
|
||||
|
||||
const GeographicLib::Geodesic& geodesic_;
|
||||
|
||||
std::unordered_map<std::string, double> distanceMap_;
|
||||
scwx::common::DistanceType distanceDisplay_;
|
||||
scwx::common::Coordinate previousPosition_;
|
||||
|
||||
QIcon starIcon_ {":/res/icons/font-awesome-6/star-solid.svg"};
|
||||
};
|
||||
|
||||
RadarSiteModel::RadarSiteModel(QObject* parent) :
|
||||
|
|
@ -53,28 +54,32 @@ int RadarSiteModel::rowCount(const QModelIndex& parent) const
|
|||
|
||||
int RadarSiteModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : static_cast<int>(kNumColumns);
|
||||
return parent.isValid() ? 0 : kNumColumns;
|
||||
}
|
||||
|
||||
QVariant RadarSiteModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (index.isValid() && index.row() >= 0 &&
|
||||
index.row() < p->radarSites_.size() &&
|
||||
(role == Qt::DisplayRole || role == types::SortRole))
|
||||
if (!index.isValid() || index.row() < 0 ||
|
||||
index.row() >= p->radarSites_.size())
|
||||
{
|
||||
const auto& site = p->radarSites_.at(index.row());
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const auto& site = p->radarSites_.at(index.row());
|
||||
|
||||
if (role == Qt::DisplayRole || role == types::SortRole)
|
||||
{
|
||||
switch (index.column())
|
||||
{
|
||||
case kColumnSiteId:
|
||||
case static_cast<int>(Column::SiteId):
|
||||
return QString::fromStdString(site->id());
|
||||
case kColumnPlace:
|
||||
case static_cast<int>(Column::Place):
|
||||
return QString::fromStdString(site->place());
|
||||
case kColumnState:
|
||||
case static_cast<int>(Column::State):
|
||||
return QString::fromStdString(site->state());
|
||||
case kColumnCountry:
|
||||
case static_cast<int>(Column::Country):
|
||||
return QString::fromStdString(site->country());
|
||||
case kColumnLatitude:
|
||||
case static_cast<int>(Column::Latitude):
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return QString::fromStdString(
|
||||
|
|
@ -84,7 +89,7 @@ QVariant RadarSiteModel::data(const QModelIndex& index, int role) const
|
|||
{
|
||||
return site->latitude();
|
||||
}
|
||||
case kColumnLongitude:
|
||||
case static_cast<int>(Column::Longitude):
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return QString::fromStdString(
|
||||
|
|
@ -94,9 +99,9 @@ QVariant RadarSiteModel::data(const QModelIndex& index, int role) const
|
|||
{
|
||||
return site->longitude();
|
||||
}
|
||||
case kColumnType:
|
||||
case static_cast<int>(Column::Type):
|
||||
return QString::fromStdString(site->type_name());
|
||||
case kColumnDistance:
|
||||
case static_cast<int>(Column::Distance):
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (p->distanceDisplay_ == scwx::common::DistanceType::Miles)
|
||||
|
|
@ -116,6 +121,26 @@ QVariant RadarSiteModel::data(const QModelIndex& index, int role) const
|
|||
{
|
||||
return p->distanceMap_.at(site->id());
|
||||
}
|
||||
case static_cast<int>(Column::Favorite):
|
||||
if (role == types::SortRole)
|
||||
{
|
||||
return QVariant(p->favorites_.at(index.row()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (role == Qt::DecorationRole)
|
||||
{
|
||||
switch (index.column())
|
||||
{
|
||||
case static_cast<int>(Column::Favorite):
|
||||
if (p->favorites_.at(index.row()))
|
||||
{
|
||||
return p->starIcon_;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -134,27 +159,40 @@ QVariant RadarSiteModel::headerData(int section,
|
|||
{
|
||||
switch (section)
|
||||
{
|
||||
case kColumnSiteId:
|
||||
case static_cast<int>(Column::SiteId):
|
||||
return tr("Site ID");
|
||||
case kColumnPlace:
|
||||
case static_cast<int>(Column::Place):
|
||||
return tr("Place");
|
||||
case kColumnState:
|
||||
case static_cast<int>(Column::State):
|
||||
return tr("State");
|
||||
case kColumnCountry:
|
||||
case static_cast<int>(Column::Country):
|
||||
return tr("Country");
|
||||
case kColumnLatitude:
|
||||
case static_cast<int>(Column::Latitude):
|
||||
return tr("Latitude");
|
||||
case kColumnLongitude:
|
||||
case static_cast<int>(Column::Longitude):
|
||||
return tr("Longitude");
|
||||
case kColumnType:
|
||||
case static_cast<int>(Column::Type):
|
||||
return tr("Type");
|
||||
case kColumnDistance:
|
||||
case static_cast<int>(Column::Distance):
|
||||
return tr("Distance");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (role == Qt::DecorationRole)
|
||||
{
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case static_cast<int>(Column::Favorite):
|
||||
return p->starIcon_;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
|
@ -175,12 +213,21 @@ void RadarSiteModel::HandleMapUpdate(double latitude, double longitude)
|
|||
p->distanceMap_[site->id()] = distanceInMeters;
|
||||
}
|
||||
|
||||
QModelIndex topLeft = createIndex(0, kColumnDistance);
|
||||
QModelIndex bottomRight = createIndex(rowCount() - 1, kColumnDistance);
|
||||
QModelIndex topLeft = createIndex(0, static_cast<int>(Column::Distance));
|
||||
QModelIndex bottomRight =
|
||||
createIndex(rowCount() - 1, static_cast<int>(Column::Distance));
|
||||
|
||||
Q_EMIT dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
|
||||
void RadarSiteModel::ToggleFavorite(int row)
|
||||
{
|
||||
if (row >= 0 && row < p->favorites_.size())
|
||||
{
|
||||
p->favorites_.at(row) = !p->favorites_.at(row);
|
||||
}
|
||||
}
|
||||
|
||||
RadarSiteModelImpl::RadarSiteModelImpl() :
|
||||
radarSites_ {},
|
||||
geodesic_(util::GeographicLib::DefaultGeodesic()),
|
||||
|
|
@ -197,6 +244,7 @@ RadarSiteModelImpl::RadarSiteModelImpl() :
|
|||
{
|
||||
distanceMap_[site->id()] = 0.0;
|
||||
radarSites_.emplace_back(std::move(site));
|
||||
favorites_.emplace_back(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,19 @@ class RadarSiteModelImpl;
|
|||
class RadarSiteModel : public QAbstractTableModel
|
||||
{
|
||||
public:
|
||||
enum class Column : int
|
||||
{
|
||||
SiteId = 0,
|
||||
Place = 1,
|
||||
State = 2,
|
||||
Country = 3,
|
||||
Latitude = 4,
|
||||
Longitude = 5,
|
||||
Type = 6,
|
||||
Distance = 7,
|
||||
Favorite = 8
|
||||
};
|
||||
|
||||
explicit RadarSiteModel(QObject* parent = nullptr);
|
||||
~RadarSiteModel();
|
||||
|
||||
|
|
@ -29,6 +42,7 @@ public:
|
|||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
void HandleMapUpdate(double latitude, double longitude);
|
||||
void ToggleFavorite(int row);
|
||||
|
||||
private:
|
||||
std::unique_ptr<RadarSiteModelImpl> p;
|
||||
|
|
|
|||
|
|
@ -70,9 +70,22 @@ RadarSiteDialog::RadarSiteDialog(QWidget* parent) :
|
|||
p->proxyModel_,
|
||||
&QSortFilterProxyModel::setFilterWildcard);
|
||||
connect(ui->radarSiteView,
|
||||
&QTreeView::doubleClicked,
|
||||
&QAbstractItemView::doubleClicked,
|
||||
this,
|
||||
[this]() { Q_EMIT accept(); });
|
||||
connect(ui->radarSiteView,
|
||||
&QAbstractItemView::pressed,
|
||||
this,
|
||||
[this](const QModelIndex& index)
|
||||
{
|
||||
QModelIndex selectedIndex = p->proxyModel_->mapToSource(index);
|
||||
|
||||
if (selectedIndex.column() ==
|
||||
static_cast<int>(model::RadarSiteModel::Column::Favorite))
|
||||
{
|
||||
p->radarSiteModel_->ToggleFavorite(selectedIndex.row());
|
||||
}
|
||||
});
|
||||
connect(
|
||||
ui->radarSiteView->selectionModel(),
|
||||
&QItemSelectionModel::selectionChanged,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>576</width>
|
||||
<width>627</width>
|
||||
<height>550</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeView" name="radarSiteView">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue