Skip to content

Commit

Permalink
Force placefile refresh button
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulat committed Nov 5, 2023
1 parent e43dcb9 commit 66ef65f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
11 changes: 11 additions & 0 deletions scwx-qt/source/scwx/qt/manager/placefile_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,17 @@ void PlacefileManager::RemoveUrl(const std::string& urlString)
Q_EMIT PlacefileRemoved(urlString);
}

void PlacefileManager::Refresh(const std::string& name)
{
std::shared_lock lock {p->placefileRecordLock_};

auto it = p->placefileRecordMap_.find(name);
if (it != p->placefileRecordMap_.cend())
{
it->second->UpdateAsync();
}
}

void PlacefileManager::Impl::PlacefileRecord::Update()
{
logger_->debug("Update: {}", name_);
Expand Down
2 changes: 2 additions & 0 deletions scwx-qt/source/scwx/qt/manager/placefile_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class PlacefileManager : public QObject
bool thresholded = false);
void RemoveUrl(const std::string& urlString);

void Refresh(const std::string& name);

static std::shared_ptr<PlacefileManager> Instance();

signals:
Expand Down
27 changes: 27 additions & 0 deletions scwx-qt/source/scwx/qt/ui/placefile_settings_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ PlacefileSettingsWidget::PlacefileSettingsWidget(QWidget* parent) :
ui->setupUi(this);

ui->removeButton->setEnabled(false);
ui->refreshButton->setEnabled(false);

ui->placefileView->setModel(p->placefileProxyModel_);

Expand Down Expand Up @@ -114,6 +115,31 @@ void PlacefileSettingsWidgetImpl::ConnectSignals()
}
});

QObject::connect(self_->ui->refreshButton,
&QPushButton::clicked,
self_,
[this]()
{
auto selectionModel =
self_->ui->placefileView->selectionModel();

// Get selected URL string
QModelIndex selected =
selectionModel
->selectedRows(static_cast<int>(
model::PlacefileModel::Column::Placefile))
.first();
QVariant data = self_->ui->placefileView->model()->data(
selected, types::ItemDataRole::SortRole);
std::string urlString = data.toString().toStdString();

// Refresh placefile
if (!urlString.empty())
{
placefileManager_->Refresh(urlString);
}
});

QObject::connect(
openUrlDialog_,
&OpenUrlDialog::accepted,
Expand Down Expand Up @@ -143,6 +169,7 @@ void PlacefileSettingsWidgetImpl::ConnectSignals()

bool itemSelected = selected.size() > 0;
self_->ui->removeButton->setEnabled(itemSelected);
self_->ui->refreshButton->setEnabled(itemSelected);
});
}

Expand Down
12 changes: 11 additions & 1 deletion scwx-qt/source/scwx/qt/ui/placefile_settings_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Remove</string>
<string>R&amp;emove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refreshButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Refresh</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 66ef65f

Please sign in to comment.