diff --git a/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp b/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp index b235ded2..ec496de4 100644 --- a/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/placefile_manager.cpp @@ -164,15 +164,18 @@ void PlacefileManager::AddUrl(const std::string& urlString) void PlacefileManager::LoadFile(const std::string& filename) { - logger_->debug("LoadFile: {}", filename); + const std::string placefileName = + QDir::toNativeSeparators(QString::fromStdString(filename)).toStdString(); + + logger_->debug("LoadFile: {}", placefileName); boost::asio::post( p->threadPool_, - [=, this]() + [placefileName, this]() { // Load file std::shared_ptr placefile = - gr::Placefile::Load(filename); + gr::Placefile::Load(placefileName); if (placefile == nullptr) { @@ -182,7 +185,7 @@ void PlacefileManager::LoadFile(const std::string& filename) std::unique_lock lock(p->placefileRecordLock_); // Determine if the placefile has been loaded previously - auto it = p->placefileRecordMap_.find(filename); + auto it = p->placefileRecordMap_.find(placefileName); if (it != p->placefileRecordMap_.end()) { // If the placefile has been loaded previously, update it @@ -190,19 +193,19 @@ void PlacefileManager::LoadFile(const std::string& filename) lock.unlock(); - Q_EMIT PlacefileUpdated(filename); + Q_EMIT PlacefileUpdated(placefileName); } else { // If this is a new placefile, add it auto& record = p->placefileRecords_.emplace_back( - std::make_shared(filename, placefile)); - p->placefileRecordMap_.insert_or_assign(filename, record); + std::make_shared(placefileName, placefile)); + p->placefileRecordMap_.insert_or_assign(placefileName, record); lock.unlock(); - Q_EMIT PlacefileEnabled(filename, record->enabled_); - Q_EMIT PlacefileUpdated(filename); + Q_EMIT PlacefileEnabled(placefileName, record->enabled_); + Q_EMIT PlacefileUpdated(placefileName); } }); } diff --git a/scwx-qt/source/scwx/qt/model/placefile_model.cpp b/scwx-qt/source/scwx/qt/model/placefile_model.cpp index 716e54a4..7fbf5984 100644 --- a/scwx-qt/source/scwx/qt/model/placefile_model.cpp +++ b/scwx-qt/source/scwx/qt/model/placefile_model.cpp @@ -4,7 +4,10 @@ #include #include +#include #include +#include +#include namespace scwx { @@ -19,7 +22,7 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); static constexpr int kFirstColumn = static_cast(PlacefileModel::Column::Enabled); static constexpr int kLastColumn = - static_cast(PlacefileModel::Column::Description); + static_cast(PlacefileModel::Column::Placefile); static constexpr int kNumColumns = kLastColumn - kFirstColumn + 1; class PlacefileModelImpl @@ -82,51 +85,88 @@ QVariant PlacefileModel::data(const QModelIndex& index, int role) const const auto& placefileName = p->placefileNames_.at(index.row()); if (role == Qt::ItemDataRole::DisplayRole || - role == Qt::ItemDataRole::ToolTipRole || - role == types::ItemDataRole::SortRole) + role == Qt::ItemDataRole::ToolTipRole) { + static const QString enabledString = QObject::tr("Enabled"); + static const QString disabledString = QObject::tr("Disabled"); + + static const QString thresholdsEnabledString = + QObject::tr("Thresholds Enabled"); + static const QString thresholdsDisabledString = + QObject::tr("Thresholds Disabled"); + switch (index.column()) { case static_cast(Column::Enabled): - if (role == types::ItemDataRole::SortRole) + if (role == Qt::ItemDataRole::ToolTipRole) { - return p->placefileManager_->PlacefileEnabled(placefileName); + return p->placefileManager_->PlacefileEnabled(placefileName) ? + enabledString : + disabledString; } break; case static_cast(Column::Thresholds): - if (role == types::ItemDataRole::SortRole) + if (role == Qt::ItemDataRole::ToolTipRole) { - return p->placefileManager_->PlacefileThresholded(placefileName); + return p->placefileManager_->PlacefileThresholded(placefileName) ? + thresholdsEnabledString : + thresholdsDisabledString; } break; - case static_cast(Column::Url): - return QString::fromStdString(placefileName); - - case static_cast(Column::Description): + case static_cast(Column::Placefile): { - auto placefile = p->placefileManager_->Placefile(placefileName); + std::string description = placefileName; + auto placefile = p->placefileManager_->Placefile(placefileName); if (placefile != nullptr) { - return QString::fromStdString(placefile->title()); + std::string title = placefile->title(); + if (!title.empty()) + { + description = title + '\n' + description; + } } - return QString {}; + + return QString::fromStdString(description); } default: break; } } + else if (role == types::ItemDataRole::SortRole) + { + switch (index.column()) + { + case static_cast(Column::Enabled): + return p->placefileManager_->PlacefileEnabled(placefileName); + + case static_cast(Column::Thresholds): + return p->placefileManager_->PlacefileThresholded(placefileName); + + case static_cast(Column::Placefile): + return QString::fromStdString(placefileName); + + default: + break; + } + } else if (role == Qt::ItemDataRole::CheckStateRole) { switch (index.column()) { case static_cast(Column::Enabled): - return p->placefileManager_->PlacefileEnabled(placefileName); + return static_cast( + p->placefileManager_->PlacefileEnabled(placefileName) ? + Qt::CheckState::Checked : + Qt::CheckState::Unchecked); case static_cast(Column::Thresholds): - return p->placefileManager_->PlacefileThresholded(placefileName); + return static_cast( + p->placefileManager_->PlacefileThresholded(placefileName) ? + Qt::CheckState::Checked : + Qt::CheckState::Unchecked); default: break; @@ -147,41 +187,53 @@ QVariant PlacefileModel::headerData(int section, switch (section) { case static_cast(Column::Enabled): - return tr("Enabled"); + return tr("E"); case static_cast(Column::Thresholds): - return tr("Thresholds"); + return tr("T"); - case static_cast(Column::Url): - return tr("URL"); - - case static_cast(Column::Description): - return tr("Description"); + case static_cast(Column::Placefile): + return tr("Placefile"); default: break; } } } - else if (role == Qt::ItemDataRole::SizeHintRole) + else if (role == Qt::ItemDataRole::ToolTipRole) { - static const QFontMetrics fontMetrics(QApplication::font()); - - QSize contentsSize {}; - switch (section) { - case static_cast(Column::Url): - contentsSize = fontMetrics.size(0, QString(15, 'W')); - break; + case static_cast(Column::Enabled): + return tr("Enabled"); + + case static_cast(Column::Thresholds): + return tr("Thresholds"); default: break; } - - if (contentsSize != QSize {}) + } + else if (role == Qt::ItemDataRole::SizeHintRole) + { + switch (section) { - return contentsSize; + case static_cast(Column::Enabled): + case static_cast(Column::Thresholds): + { + static const QCheckBox checkBox {}; + QStyleOptionButton option {}; + option.initFrom(&checkBox); + + // Width values from QCheckBox + return QApplication::style()->sizeFromContents( + QStyle::ContentsType::CT_CheckBox, + &option, + {option.iconSize.width() + 4, 0}); + } + + default: + break; } } diff --git a/scwx-qt/source/scwx/qt/model/placefile_model.hpp b/scwx-qt/source/scwx/qt/model/placefile_model.hpp index 0f5a1b10..68bffdcf 100644 --- a/scwx-qt/source/scwx/qt/model/placefile_model.hpp +++ b/scwx-qt/source/scwx/qt/model/placefile_model.hpp @@ -21,10 +21,9 @@ class PlacefileModel : public QAbstractTableModel public: enum class Column : int { - Enabled = 0, - Thresholds = 1, - Url = 2, - Description = 3 + Enabled = 0, + Thresholds = 1, + Placefile = 2 }; explicit PlacefileModel(QObject* parent = nullptr); diff --git a/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.cpp b/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.cpp index d9167fb6..c5f73945 100644 --- a/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.cpp +++ b/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.cpp @@ -58,19 +58,21 @@ PlacefileSettingsWidget::PlacefileSettingsWidget(QWidget* parent) : ui->setupUi(this); ui->placefileView->setModel(p->placefileProxyModel_); - ui->placefileView->header()->setSortIndicator( - static_cast(model::PlacefileModel::Column::Url), Qt::AscendingOrder); - ui->placefileView->resizeColumnToContents( - static_cast(model::PlacefileModel::Column::Enabled)); - ui->placefileView->resizeColumnToContents( - static_cast(model::PlacefileModel::Column::Thresholds)); - ui->placefileView->resizeColumnToContents( - static_cast(model::PlacefileModel::Column::Url)); + auto placefileViewHeader = ui->placefileView->header(); - ui->placefileView->setItemDelegateForColumn( - static_cast(model::PlacefileModel::Column::Url), - p->leftElidedItemDelegate_); + placefileViewHeader->setMinimumSectionSize(10); + placefileViewHeader->setSortIndicator( + static_cast(model::PlacefileModel::Column::Placefile), + Qt::AscendingOrder); + + // Enabled and Thresholds columns have a fixed size (checkbox) + placefileViewHeader->setSectionResizeMode( + static_cast(model::PlacefileModel::Column::Enabled), + QHeaderView::ResizeMode::ResizeToContents); + placefileViewHeader->setSectionResizeMode( + static_cast(model::PlacefileModel::Column::Thresholds), + QHeaderView::ResizeMode::ResizeToContents); p->ConnectSignals(); } diff --git a/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.ui b/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.ui index ef2f24fd..e5f3595b 100644 --- a/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.ui +++ b/scwx-qt/source/scwx/qt/ui/placefile_settings_widget.ui @@ -16,6 +16,9 @@ + + true + 0