-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend doc with extended example (#491)
- Loading branch information
1 parent
84e2b24
commit 14fcc97
Showing
4 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# add_subdirectory(interactive_window) | ||
add_subdirectory(basic) | ||
add_subdirectory(doxygen) | ||
# add_subdirectory(multi_threaded) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
add_executable(basic_rppqt basic_rppqt.cpp) | ||
target_link_libraries(basic_rppqt PRIVATE rpp rppqt) | ||
set_target_properties(basic_rppqt PROPERTIES FOLDER Examples/rppqt) | ||
rpp_add_qt_support_to_executable(basic_rppqt) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <rpp/rpp.hpp> | ||
#include <rppqt/rppqt.hpp> | ||
|
||
#include <QApplication> | ||
#include <QMainWindow> | ||
#include <QPushButton> | ||
#include <QVBoxLayout> | ||
#include <QLabel> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
QApplication app{argc, argv}; | ||
|
||
auto button_1 = new QPushButton("Click me!"); | ||
auto button_2 = new QPushButton("Click me!"); | ||
auto clicks_count_label = new QLabel(); | ||
auto clicks_duration_label = new QLabel(); | ||
|
||
const auto clicks_1 = rppqt::source::from_signal(*button_1, &QPushButton::clicked); | ||
const auto clicks_2 = rppqt::source::from_signal(*button_2, &QPushButton::clicked); | ||
const auto merged_clicks = clicks_1 | rpp::operators::merge_with(clicks_2); | ||
|
||
const auto total_clicks = merged_clicks | rpp::operators::scan(0, [](int seed, auto) { return ++seed; }); | ||
const auto click_times = merged_clicks | rpp::operators::map([](auto) { return std::chrono::high_resolution_clock::now(); }); | ||
const auto time_since_click = rpp::source::interval(std::chrono::milliseconds{1}, rppqt::schedulers::main_thread_scheduler{}) | ||
| rpp::operators::with_latest_from([](auto, const auto click_time) { return std::chrono::high_resolution_clock::now() - click_time; }, click_times); | ||
|
||
// ..... | ||
|
||
total_clicks.subscribe([&clicks_count_label](int clicks) | ||
{ | ||
clicks_count_label->setText(QString{"Clicked %1 times in total!"}.arg(clicks)); | ||
}); | ||
|
||
|
||
time_since_click.subscribe([&clicks_duration_label](std::chrono::high_resolution_clock::duration ms) { | ||
clicks_duration_label->setText(QString{"MS since last click %1!"}.arg(std::chrono::duration_cast<std::chrono::milliseconds>(ms).count())); | ||
}); | ||
|
||
QMainWindow window{}; | ||
auto vbox = new QVBoxLayout(); | ||
vbox->addWidget(button_1); | ||
vbox->addWidget(button_2); | ||
vbox->addWidget(clicks_count_label); | ||
vbox->addWidget(clicks_duration_label); | ||
window.setCentralWidget(new QWidget); | ||
window.centralWidget()->setLayout(vbox); | ||
window.show(); | ||
|
||
return app.exec(); | ||
} |
14fcc97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BENCHMARK RESULTS (AUTOGENERATED)
ci-ubuntu-gcc
General
Sources
Filtering Operators
Schedulers
Transforming Operators
Conditional Operators
Utility Operators
Combining Operators
Subjects
Scenarios
Aggregating Operators
ci-macos
General
Sources
Filtering Operators
Schedulers
Transforming Operators
Conditional Operators
Utility Operators
Combining Operators
Subjects
Scenarios
Aggregating Operators
ci-ubuntu-clang
General
Sources
Filtering Operators
Schedulers
Transforming Operators
Conditional Operators
Utility Operators
Combining Operators
Subjects
Scenarios
Aggregating Operators
ci-windows
General
Sources
Filtering Operators
Schedulers
Transforming Operators
Conditional Operators
Utility Operators
Combining Operators
Subjects
Scenarios
Aggregating Operators