Line |
Branch |
Exec |
Source |
1 |
|
|
/************************************************************************ |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2009-2023 IRCAD France |
4 |
|
|
* Copyright (C) 2012-2017 IHU Strasbourg |
5 |
|
|
* |
6 |
|
|
* This file is part of Sight. |
7 |
|
|
* |
8 |
|
|
* Sight is free software: you can redistribute it and/or modify it under |
9 |
|
|
* the terms of the GNU Lesser General Public License as published by |
10 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
11 |
|
|
* (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* Sight is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU Lesser General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU Lesser General Public |
19 |
|
|
* License along with Sight. If not, see <https://www.gnu.org/licenses/>. |
20 |
|
|
* |
21 |
|
|
***********************************************************************/ |
22 |
|
|
|
23 |
|
|
#include "ui/__/dialog/progress.hpp" |
24 |
|
|
|
25 |
|
|
#include <core/thread/worker.hpp> |
26 |
|
|
|
27 |
|
|
#include <functional> |
28 |
|
|
|
29 |
|
|
namespace sight::ui::dialog |
30 |
|
|
{ |
31 |
|
|
|
32 |
|
|
//----------------------------------------------------------------------------- |
33 |
|
|
|
34 |
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 |
progress::progress(const std::string& _title, const std::string& _message) |
35 |
|
|
{ |
36 |
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
|
16 |
core::thread::get_default_worker()->post_task<void>( |
37 |
|
8 |
[&] |
38 |
|
|
{ |
39 |
|
8 |
ui::object::sptr gui_obj = ui::factory::make(progress_base::REGISTRY_KEY); |
40 |
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
8 |
m_implementation = std::dynamic_pointer_cast<ui::dialog::progress_base>(gui_obj); |
41 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
8 |
if(m_implementation) |
42 |
|
|
{ |
43 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
m_implementation->set_title(_title); |
44 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
m_implementation->set_message(_message); |
45 |
|
|
} |
46 |
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
16 |
}).wait(); |
47 |
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
8 |
} |
48 |
|
|
|
49 |
|
|
//----------------------------------------------------------------------------- |
50 |
|
|
|
51 |
|
82 |
progress::~progress() |
52 |
|
|
{ |
53 |
1/2
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
140 |
core::thread::get_default_worker()->post_task<void>( |
54 |
|
35 |
[&] |
55 |
|
|
{ |
56 |
|
35 |
m_implementation.reset(); |
57 |
1/2
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
|
70 |
}).wait(); |
58 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
82 |
} |
59 |
|
|
|
60 |
|
|
//----------------------------------------------------------------------------- |
61 |
|
|
|
62 |
|
1 |
void progress::set_title(const std::string& _title) |
63 |
|
|
{ |
64 |
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 |
core::thread::get_default_worker()->post_task<void>( |
65 |
|
1 |
[&] |
66 |
|
|
{ |
67 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
if(m_implementation) |
68 |
|
|
{ |
69 |
|
1 |
m_implementation->set_title(_title); |
70 |
|
|
} |
71 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
}).wait(); |
72 |
|
1 |
} |
73 |
|
|
|
74 |
|
|
//----------------------------------------------------------------------------- |
75 |
|
|
|
76 |
|
✗ |
void progress::set_message(const std::string& _msg) |
77 |
|
|
{ |
78 |
|
✗ |
core::thread::get_default_worker()->post_task<void>( |
79 |
|
✗ |
[&] |
80 |
|
|
{ |
81 |
|
✗ |
if(m_implementation) |
82 |
|
|
{ |
83 |
|
✗ |
m_implementation->set_message(_msg); |
84 |
|
|
} |
85 |
|
✗ |
}).wait(); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
//----------------------------------------------------------------------------- |
89 |
|
|
|
90 |
|
100 |
void progress::operator()(float _percent, std::string _msg) |
91 |
|
|
{ |
92 |
2/4
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
200 |
core::thread::get_default_worker()->post_task<void>( |
93 |
|
100 |
[&] |
94 |
|
|
{ |
95 |
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
|
100 |
if(m_implementation) |
96 |
|
|
{ |
97 |
1/2
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
|
200 |
(*m_implementation)(_percent, _msg); |
98 |
|
|
} |
99 |
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
200 |
}).wait(); |
100 |
|
100 |
} |
101 |
|
|
|
102 |
|
|
//----------------------------------------------------------------------------- |
103 |
|
|
|
104 |
|
1 |
void progress::set_cancel_callback(cancel_callback_t _callback) |
105 |
|
|
{ |
106 |
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 |
core::thread::get_default_worker()->post_task<void>( |
107 |
|
1 |
[&] |
108 |
|
|
{ |
109 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
if(m_implementation) |
110 |
|
|
{ |
111 |
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 |
m_implementation->set_cancel_callback(_callback); |
112 |
|
|
} |
113 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
}).wait(); |
114 |
|
1 |
} |
115 |
|
|
|
116 |
|
|
//----------------------------------------------------------------------------- |
117 |
|
|
|
118 |
|
✗ |
void progress::cancel_pressed() |
119 |
|
|
{ |
120 |
|
✗ |
assert(0); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
//----------------------------------------------------------------------------- |
124 |
|
|
|
125 |
|
✗ |
void progress::hide_cancel_button() |
126 |
|
|
{ |
127 |
|
✗ |
core::thread::get_default_worker()->post_task<void>( |
128 |
|
✗ |
[&] |
129 |
|
|
{ |
130 |
|
✗ |
m_implementation->hide_cancel_button(); |
131 |
|
✗ |
}).wait(); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
} // namespace sight::ui::dialog |
135 |
|
|
|