CVB++ 14.0
Cvb/QtPropertyGrid

This example requires Qt5 >= 5.9 setup for building.

You may build it with Ubuntu 18.04's default Qt5 after installing:

1// ---------------------------------------------------------------------------
2// ---------------------------------------------------------------------------
5// ---------------------------------------------------------------------------
6
7
8
9#include <iostream>
10
11#pragma warning(push)
12#pragma warning(disable : 4127)
13
14#include <QApplication>
15#include <QVBoxLayout>
16#include <QTextEdit>
17
18#pragma warning(pop)
19
20#include <cvb/ui/property_grid.hpp>
21#include <cvb/device_factory.hpp>
22
23
24
25
26
27int main(int argc, char* argv[])
28{
29
30 QApplication app(argc, argv);
31
32 auto path = Cvb::InstallPath();
33 path += CVB_LIT("drivers/GenICam.vin");
34 // use command line argument if provided.
35 if (argc > 1)
36 {
37 std::string inputPath(argv[1]);
38 path = Cvb::String(inputPath.begin(), inputPath.end());
39 }
40
41 Cvb::DevicePtr dev = nullptr;
42 try
43 {
44 // open a device
45 dev = Cvb::DeviceFactory::Open(Cvb::ExpandPath(path), Cvb::AcquisitionStack::Vin);
46 }
47 catch (const std::exception& error)
48 {
49 std::cout << "Failed to open the device: " << error.what() << std::endl;
50 return 1;
51 }
52
53 try
54 {
55 // Qt Window and layout
56 auto mainWindow = new QWidget;
57 mainWindow->setWindowIcon(QIcon(":/qttutorial.png"));
58
59 auto layout = new QVBoxLayout;
60
61 // Get all nodemaps
62 auto nodemaps = dev->NodeMaps();
63
64 // Node map selection
65 auto cbNodeMaps = new QComboBox;
66 for (std::map<Cvb::String, Cvb::NodeMapPtr>::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
67 cbNodeMaps->addItem(Cvb::UI::CvbToQt(it->first));
68 layout->addWidget(cbNodeMaps);
69
70 // Visibility selection
71 auto cbVisibility = new QComboBox;
72 cbVisibility->addItem("Beginner");
73 cbVisibility->addItem("Expert");
74 cbVisibility->addItem("Guru");
75 layout->addWidget(cbVisibility);
76
77 // Show the camera node map / property grid
78 auto grid = new Cvb::UI::PropertyGrid(dev->NodeMap(CVB_LIT("Device")));
79 grid->SetVisibility(Cvb::Visibility::Beginner);
80 layout->addWidget(grid);
81
82 // Property information
83 auto propertyInfo = new QTextEdit;
84 propertyInfo->setReadOnly(true);
85 layout->addWidget(propertyInfo);
86
87 // Set search result color
88 grid->SetSearchResultBackgroundColor(QColor(255, 255, 150));
89
90 // Provide a search for a specific property
91 auto searchLayout = new QHBoxLayout;
92 searchLayout->addWidget(new QLabel("Search:"));
93 auto search = new QLineEdit;
94 search->setPlaceholderText("Search property...");
95 searchLayout->addWidget(search);
96 layout->addLayout(searchLayout);
97
98 // Update button to refresh the properties
99 auto updateButton = new QPushButton("Update");
100 layout->addWidget(updateButton);
101
102 // Auto update (start / stop) for automatic update of properties (e.g. Statistics)
103 auto startAutoUpdate = new QPushButton("AutoUpdate START");
104 layout->addWidget(startAutoUpdate);
105 auto stopAutoUpdate = new QPushButton("AutoUpdate STOP");
106 layout->addWidget(stopAutoUpdate);
107 auto autoUpdateButtonLayout = new QHBoxLayout;
108 autoUpdateButtonLayout->addWidget(startAutoUpdate);
109 autoUpdateButtonLayout->addWidget(stopAutoUpdate);
110 layout->addLayout(autoUpdateButtonLayout);
111
112 // Signal - slots
113 // ---------------
114
115 // Nodemap selection
116 QObject::connect(cbNodeMaps, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int /*index*/)
117 {
118 // Set the selected nodemap
119 grid->SetNodeMap(nodemaps.at(Cvb::UI::QtToCvb(cbNodeMaps->currentText())));
120 // Reset the search text
121 search->setText("");
122 grid->ResetSearch();
123 });
124
125 // Visibility selection
126 QObject::connect(cbVisibility, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index)
127 {
128 // Set the selected visibility
129 switch (index)
130 {
131 case 0: grid->SetVisibility(Cvb::Visibility::Beginner); break;
132 case 1: grid->SetVisibility(Cvb::Visibility::Expert); break;
133 case 2: grid->SetVisibility(Cvb::Visibility::Guru); break;
134 }
135 });
136
137 // Property selection provides info on the property in the propertyInfo field
139 {
140 propertyInfo->setText(grid->HtmlFormattedDescription(index));
141 });
142
143 // Start the search for a property
145 {
146 if (search->text().isEmpty())
147 {
148 grid->ResetSearch();
149 return;
150 }
151 auto found = grid->Search(search->text());
152 grid->ExpandSearchResult(found);
153 });
154
155 // Update the property grid
156 QObject::connect(updateButton, &QPushButton::clicked, [=]()
157 {
158 grid->update();
159 });
160
161 // Start the automatic update
162 QObject::connect(startAutoUpdate, &QPushButton::clicked, [=]()
163 {
164 grid->StartAutoUpdate(5000); // every 5 seconds
165 });
166
167 // Stop the automatic update
168 QObject::connect(stopAutoUpdate, &QPushButton::clicked, [=]()
169 {
170 grid->StopAutoUpdate();
171 });
172
173 mainWindow->setLayout(layout);
174 mainWindow->setAttribute(Qt::WA_DeleteOnClose);
175 mainWindow->show();
176
177 return app.exec();
178 }
179 catch (const std::exception& error)
180 {
181 std::cout << error.what() << std::endl;
182 return 1;
183 }
184}
185
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
Opens a device with the given provider with its default board and port (if applicable).
Definition: decl_device_factory.hpp:50
View to display a device's nodemap.
Definition: property_grid.hpp:157
Cvb::String QtToCvb(const QString text) noexcept
Convenience converter for strings.
Definition: ui.hpp:239
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition: ui.hpp:254
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:45
void clicked(bool checked)
void clicked(const QModelIndex &index)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void addItem(const QString &text, const QVariant &userData)
void currentIndexChanged(int index)
void returnPressed()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setReadOnly(bool ro)
void setWindowIcon(const QIcon &icon)