diff options
-rw-r--r-- | compat/camera-names.cpp | 23 | ||||
-rw-r--r-- | compat/camera-names.hpp | 3 | ||||
-rw-r--r-- | video-opencv/impl-metadata.cpp | 9 |
3 files changed, 24 insertions, 11 deletions
diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp index 40edba49..8e777028 100644 --- a/compat/camera-names.cpp +++ b/compat/camera-names.cpp @@ -28,16 +28,22 @@ int camera_name_to_index(const QString &name) { auto list = get_camera_names(); - auto it = std::find(list.cbegin(), list.cend(), name); + auto it = std::find_if(list.cbegin(), list.cend(), [&name](const auto& tuple) { + const auto& [str, idx] = tuple; + return str == name; + }); if (it != list.cend()) - return std::distance(list.cbegin(), it); + { + const auto& [ str, idx ] = *it; + return idx; + } return -1; } -std::vector<QString> get_camera_names() +std::vector<std::tuple<QString, int>> get_camera_names() { - std::vector<QString> ret; + std::vector<std::tuple<QString, int>> ret; #ifdef _WIN32 // Create the System Device Enumerator. HRESULT hr; @@ -70,7 +76,7 @@ std::vector<QString> get_camera_names() { // Display the name in your UI somehow. QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal))); - ret.push_back(str); + ret.push_back({ str, ret.size() }); } VariantClear(&var); pPropBag->Release(); @@ -101,16 +107,15 @@ std::vector<QString> get_camera_names() close(fd); continue; } - ret.push_back(QString((const char*)video_cap.card)); + ret.push_back({ QString((const char*)video_cap.card), i}); close(fd); } } #endif #ifdef __APPLE__ QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); - foreach (const QCameraInfo &cameraInfo, cameras) { - ret.push_back(cameraInfo.description()); - } + for (const QCameraInfo &cameraInfo : cameras) + ret.push_back({ cameraInfo.description(), ret.size() }); #endif return ret; diff --git a/compat/camera-names.hpp b/compat/camera-names.hpp index bda15e81..3585edfe 100644 --- a/compat/camera-names.hpp +++ b/compat/camera-names.hpp @@ -10,9 +10,10 @@ #include <vector> #include <QString> +# include <tuple> #include "export.hpp" -OTR_COMPAT_EXPORT std::vector<QString> get_camera_names(); +OTR_COMPAT_EXPORT std::vector<std::tuple<QString, int>> get_camera_names(); OTR_COMPAT_EXPORT int camera_name_to_index(const QString &name); diff --git a/video-opencv/impl-metadata.cpp b/video-opencv/impl-metadata.cpp index 48a2e693..ffc51773 100644 --- a/video-opencv/impl-metadata.cpp +++ b/video-opencv/impl-metadata.cpp @@ -17,7 +17,14 @@ std::unique_ptr<camera> metadata::make_camera(const QString& name) std::vector<QString> metadata::camera_names() const { - return get_camera_names(); + std::vector<std::tuple<QString, int>> names = get_camera_names(); + std::vector<QString> ret; + for (const auto& t : names) + { + const auto& [str, idx] = t; + ret.push_back(str); + } + return ret; } bool metadata::can_show_dialog(const QString& camera_name) |