Skip to content

Commit 8500ecb

Browse files
authored
Let design wizzard use the global selection (#497)
1 parent 629e90b commit 8500ecb

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

gui/components/visualizationwidget.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ VisualizationWidget::VisualizationWidget(theatre::Management *management,
9191
sigc::mem_fun(*this, &VisualizationWidget::onButtonRelease));
9292
signal_motion_notify_event().connect(
9393
sigc::mem_fun(*this, &VisualizationWidget::onMotion));
94-
inializeContextMenu();
94+
initializeContextMenu();
9595
primary_snapshot_ = _management->PrimarySnapshot();
9696
secondary_snapshot_ = _management->SecondarySnapshot();
9797
update_connection_ = _eventTransmitter->SignalUpdateControllables().connect(
9898
[&]() { Update(); });
9999
}
100100

101-
void VisualizationWidget::inializeContextMenu() {
101+
void VisualizationWidget::initializeContextMenu() {
102102
context_menu_.SignalSetFullOn.connect([&]() {
103103
theatre::SetAllFixtures(*_management, _selectedFixtures, Color::White());
104104
});
@@ -137,9 +137,10 @@ void VisualizationWidget::initialize() {
137137
}
138138

139139
void VisualizationWidget::onTheatreChanged() {
140-
for (size_t i = _selectedFixtures.size(); i != 0; --i) {
141-
if (!_management->GetTheatre().Contains(*_selectedFixtures[i - 1]))
142-
_selectedFixtures.erase(_selectedFixtures.begin() + i - 1);
140+
const auto iter =
141+
std::remove(_selectedFixtures.begin(), _selectedFixtures.end(), nullptr);
142+
if (iter != _selectedFixtures.end()) {
143+
_selectedFixtures.erase(iter, _selectedFixtures.end());
143144
}
144145
Update();
145146
}
@@ -660,7 +661,6 @@ void VisualizationWidget::onDesignFixtures() {
660661
std::unique_ptr<DesignWizard> &designWizard = main_window_->GetDesignWizard();
661662
designWizard = std::make_unique<DesignWizard>();
662663
designWizard->SetCurrentPath(main_window_->SelectedFolder().FullPath());
663-
designWizard->Select(_selectedFixtures);
664664
designWizard->present();
665665
}
666666

gui/components/visualizationwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class VisualizationWidget : public Gtk::DrawingArea {
5656
VisualizationWidget(const VisualizationWidget &) = delete;
5757
VisualizationWidget &operator=(const VisualizationWidget &) = delete;
5858

59-
void inializeContextMenu();
59+
void initializeContextMenu();
6060
void initialize();
6161
void drawAll(const Cairo::RefPtr<Cairo::Context> &cairo);
6262
void DrawShapshot(

gui/fixtureselection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class FixtureSelection {
3232
* If any fixtures are in the selection that no longer exist, remove them.
3333
*/
3434
void UpdateAfterDelete() {
35-
auto iter = std::remove(_selection.begin(), _selection.end(), nullptr);
35+
const auto iter =
36+
std::remove(_selection.begin(), _selection.end(), nullptr);
3637
if (iter != _selection.end()) {
3738
_selection.erase(iter, _selection.end());
3839
_signalChange.emit();

gui/windows/designwizard.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ranges>
55

66
#include "gui/eventtransmitter.h"
7+
#include "gui/fixtureselection.h"
78
#include "gui/functions.h"
89
#include "gui/instance.h"
910

@@ -96,6 +97,8 @@ DesignWizard::DesignWizard()
9697

9798
add(_mainBox);
9899
_mainBox.show();
100+
101+
_fixtureList.Select(Instance::Selection().Selection());
99102
}
100103

101104
DesignWizard::~DesignWizard() = default;

gui/windows/designwizard.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class DesignWizard : public Gtk::Window {
3737
_currentPath = currentPath;
3838
}
3939

40-
void Select(
41-
const std::vector<system::ObservingPtr<theatre::Fixture>> &fixtures) {
42-
_fixtureList.Select(fixtures);
43-
}
44-
4540
private:
4641
enum Page {
4742
Page1_SelFixtures,

system/optionalnumber.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ class OptionalNumber {
4444
constexpr explicit OptionalNumber(std::nullopt_t) noexcept {}
4545

4646
template <class T = NumberType>
47-
constexpr explicit OptionalNumber(T number) noexcept : number_(number) {}
47+
requires(!std::is_same_v<
48+
T, OptionalNumber<
49+
T>>) constexpr explicit OptionalNumber(T number) noexcept
50+
: number_(number) {}
4851

4952
constexpr OptionalNumber(const OptionalNumber<NumberType>& source) noexcept =
5053
default;
@@ -177,18 +180,22 @@ class OptionalNumber {
177180

178181
constexpr void Reset() noexcept { number_ = UnsetValue; }
179182

183+
constexpr void Swap(OptionalNumber<NumberType>& other) {
184+
// To let OptionalNumber also work with types that may implement their own
185+
// swap function, we bring std::swap in but don't call swap explicitly from
186+
// the std namespace.
187+
using std::swap;
188+
swap(other.number_, number_);
189+
}
190+
180191
private:
181192
NumberType number_ = UnsetValue;
182193
};
183194

184195
template <typename NumberType>
185-
void swap(OptionalNumber<NumberType>& first,
186-
OptionalNumber<NumberType>& second) noexcept {
187-
// To let OptionalNumber also work with types that may implement their own
188-
// swap function, we bring std::swap in but don't call swap explicitly from
189-
// the std namespace.
190-
using std::swap;
191-
swap(first.number_, second.number_);
196+
constexpr void swap(OptionalNumber<NumberType>& first,
197+
OptionalNumber<NumberType>& second) noexcept {
198+
first.Swap(second);
192199
}
193200

194201
} // namespace glight::system

0 commit comments

Comments
 (0)