[libcamera-devel] [PATCH v8 4/8] qcam: CamSelectDialog: Display Location and Model propety of camera
Utkarsh Tiwari
utkarsh02t at gmail.com
Mon Aug 15 18:43:49 CEST 2022
On Wed, Aug 10, 2022 at 8:34 PM Utkarsh Tiwari <utkarsh02t at gmail.com> wrote:
> The camera selection dialog currently only displays the camera Id.
> Display the camera location and camera model if available.
>
> Signed-off-by: Utkarsh Tiwari <utkarsh02t at gmail.com>
> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> Difference from v7:
> 1. Nothing
> src/qcam/cam_select_dialog.cpp | 52 ++++++++++++++++++++++++++++++++++
> src/qcam/cam_select_dialog.h | 10 +++++++
> 2 files changed, 62 insertions(+)
>
> diff --git a/src/qcam/cam_select_dialog.cpp
> b/src/qcam/cam_select_dialog.cpp
> index d8982800..f97ad6eb 100644
> --- a/src/qcam/cam_select_dialog.cpp
> +++ b/src/qcam/cam_select_dialog.cpp
> @@ -7,6 +7,7 @@
>
> #include "cam_select_dialog.h"
>
> +#include <memory>
> #include <string>
>
> #include <libcamera/camera.h>
> @@ -30,6 +31,14 @@
> CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager
> *cameraManag
> for (const auto &cam : cm_->cameras())
>
> cameraIdComboBox_->addItem(QString::fromStdString(cam->id()));
>
> + /* Set camera information labels. */
> + cameraLocation_ = new QLabel;
> + cameraModel_ = new QLabel;
> +
> + handleCameraChange();
> + connect(cameraIdComboBox_, &QComboBox::currentTextChanged,
> + this, &CameraSelectorDialog::handleCameraChange);
> +
> /* Setup the QDialogButton Box */
> QDialogButtonBox *buttonBox =
> new QDialogButtonBox(QDialogButtonBox::Ok |
> @@ -41,7 +50,10 @@
> CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager
> *cameraManag
> this, &QDialog::reject);
>
> /* Set the layout. */
> +
> layout->addRow("Camera:", cameraIdComboBox_);
> + layout->addRow("Location:", cameraLocation_);
> + layout->addRow("Model:", cameraModel_);
> layout->addWidget(buttonBox);
> }
>
> @@ -63,3 +75,43 @@ void
> CameraSelectorDialog::cameraRemoved(libcamera::Camera *camera)
>
> cameraIdComboBox_->removeItem(cameraIndex);
> }
> +
> +/* Camera Information */
> +void CameraSelectorDialog::handleCameraChange()
> +{
> + updateCamInfo(cm_->get(getCameraId()));
> +}
>
This function can be removed and we can shift the cm_->get(getCameraId())
in the updateCamInfo
itself.
> +
> +void CameraSelectorDialog::updateCamInfo(const
> std::shared_ptr<libcamera::Camera> &camera)
> +{
> + if (!camera)
> + return;
> +
> + const libcamera::ControlList &cameraProperties =
> camera->properties();
> +
> + const auto &location =
> + cameraProperties.get(libcamera::properties::Location);
> + if (location) {
> + switch (*location) {
> + case libcamera::properties::CameraLocationFront:
> + cameraLocation_->setText("Internal front camera");
> + break;
> + case libcamera::properties::CameraLocationBack:
> + cameraLocation_->setText("Internal back camera");
> + break;
> + case libcamera::properties::CameraLocationExternal:
> + cameraLocation_->setText("External camera");
> + break;
> + default:
> + cameraLocation_->setText("Unknown");
> + }
> + } else {
> + cameraLocation_->setText("Unknown");
> + }
> +
> + const auto &model = cameraProperties
> + .get(libcamera::properties::Model)
> + .value_or("Unknown");
> +
> + cameraModel_->setText(QString::fromStdString(model));
> +}
> diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
> index 04c71fd8..16475af6 100644
> --- a/src/qcam/cam_select_dialog.h
> +++ b/src/qcam/cam_select_dialog.h
> @@ -11,9 +11,12 @@
>
> #include <libcamera/camera.h>
> #include <libcamera/camera_manager.h>
> +#include <libcamera/controls.h>
> +#include <libcamera/property_ids.h>
>
> #include <QComboBox>
> #include <QDialog>
> +#include <QLabel>
>
> class CameraSelectorDialog : public QDialog
> {
> @@ -30,9 +33,16 @@ public:
> void cameraAdded(libcamera::Camera *camera);
>
> void cameraRemoved(libcamera::Camera *camera);
> +
> + /* Camera Information */
> + void updateCamInfo(const std::shared_ptr<libcamera::Camera>
> &camera);
> + void handleCameraChange();
> +
> private:
> libcamera::CameraManager *cm_;
>
> /* UI elements. */
> QComboBox *cameraIdComboBox_;
> + QLabel *cameraLocation_;
> + QLabel *cameraModel_;
> };
> --
> 2.25.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20220815/3f747def/attachment.htm>
More information about the libcamera-devel
mailing list