[{"id":24367,"web_url":"https://patchwork.libcamera.org/comment/24367/","msgid":"<03caa7ef-c3e7-3dc7-c8f5-e0c4b2931db4@ideasonboard.com>","date":"2022-08-04T12:24:07","subject":"Re: [libcamera-devel] [PATCH 4/4] qcam: MainWindow: Replace\n\tcameraCombo_ with cameraSelectDialog","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Utkarsh,\n\nThank you for the patch.\n\nOn 8/3/22 23:25, Utkarsh Tiwari via libcamera-devel wrote:\n> Replace the cameraCombo_ on the toolbar with a QPushButton which\n> displays the cameraSelectDialog. This would allow the user to view\n> information about the camera when switching.\n>\n> The QPushButton text is set to the camera Id currently in use.\n>\n> Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>\n> ---\n>   src/qcam/main_window.cpp | 47 ++++++++++++++++++++++------------------\n>   src/qcam/main_window.h   |  5 +++--\n>   2 files changed, 29 insertions(+), 23 deletions(-)\n>\n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 81fa3e60..2a9dcc1e 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -198,14 +198,11 @@ int MainWindow::createToolbars()\n>   \tconnect(action, &QAction::triggered, this, &MainWindow::quit);\n>   \n>   \t/* Camera selector. */\n> -\tcameraCombo_ = new QComboBox();\n> -\tconnect(cameraCombo_, QOverload<int>::of(&QComboBox::activated),\n> +\tcameraSelectButton_ = new QPushButton;\n> +\tconnect(cameraSelectButton_, &QPushButton::clicked,\n>   \t\tthis, &MainWindow::switchCamera);\n>   \n> -\tfor (const std::shared_ptr<Camera> &cam : cm_->cameras())\n> -\t\tcameraCombo_->addItem(QString::fromStdString(cam->id()));\n> -\n> -\ttoolbar_->addWidget(cameraCombo_);\n> +\ttoolbar_->addWidget(cameraSelectButton_);\n>   \n>   \ttoolbar_->addSeparator();\n>   \n> @@ -265,14 +262,18 @@ void MainWindow::updateTitle()\n>    * Camera Selection\n>    */\n>   \n> -void MainWindow::switchCamera(int index)\n> +void MainWindow::switchCamera()\n>   {\n>   \t/* Get and acquire the new camera. */\n> -\tconst auto &cameras = cm_->cameras();\n> -\tif (static_cast<unsigned int>(index) >= cameras.size())\n> +\tstd::string cameraId = chooseCamera();\n\n\nCan this be renamed to better clarify that the string belongs to a \n(newly) chosen camera?\n\n> +\tif (cameraId.empty())\n>   \t\treturn;\n>   \n> -\tconst std::shared_ptr<Camera> &cam = cameras[index];\n> +\t/* Don't try the current camera. */\n\n\nAre you missing something here, I find the comment a bit confusing. Is \nthis similar,\n\n         /* Is user selects the current camera, return */\n\n> +\tif (cameraId == camera_->id())\n> +\t\treturn;\n> +\n> +\tconst std::shared_ptr<Camera> &cam = cm_->get(cameraId);\n>   \n>   \tif (cam->acquire()) {\n>   \t\tqInfo() << \"Failed to acquire camera\" << cam->id().c_str();\n> @@ -290,6 +291,9 @@ void MainWindow::switchCamera(int index)\n>   \tcamera_->release();\n>   \tcamera_ = cam;\n>   \n> +\t/* Set the QPushButton text with current camera. */\n> +\tcameraSelectButton_->setText(QString::fromStdString(camera_->id()));\n> +\n>   \tstartStopAction_->setChecked(true);\n>   }\n>   \n> @@ -356,10 +360,16 @@ std::string MainWindow::chooseCamera()\n>   \t * When the Qdialog starts, the QComboBox would have the first\n>   \t * camera's Id as its currentText.\n>   \t */\n> -\tif (cm_->cameras().size())\n> -\t\tcurrentCamera = cm_->cameras()[0];\n> -\telse\n> -\t\tcurrentCamera = nullptr;\n> +\tif (!isCapturing_) {\n> +\t\tif (cm_->cameras().size())\n> +\t\t\tcurrentCamera = cm_->cameras()[0];\n> +\t\telse\n> +\t\t\tcurrentCamera = nullptr;\n\n\nsame comment from previous patch on nullptr\n\nOther than that,\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> +\t} else {\n> +\t\tint cameraIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id()));\n> +\t\tcameraIdComboBox_->setCurrentIndex(cameraIndex);\n> +\t\tcurrentCamera = camera_;\n> +\t}\n>   \n>   \tif (currentCamera)\n>   \t\tupdateCameraInfo(currentCamera);\n> @@ -428,8 +438,8 @@ int MainWindow::openCamera()\n>   \t\treturn -EBUSY;\n>   \t}\n>   \n> -\t/* Set the combo-box entry with the currently selected Camera. */\n> -\tcameraCombo_->setCurrentText(QString::fromStdString(cameraName));\n> +\t/* Set the QPushButton text with the currently selected Camera. */\n> +\tcameraSelectButton_->setText(QString::fromStdString(cameraName));\n>   \n>   \treturn 0;\n>   }\n> @@ -695,7 +705,6 @@ void MainWindow::processHotplug(HotplugEvent *e)\n>   \n>   \tif (event == HotplugEvent::HotPlug) {\n>   \t\tQString cameraId = QString::fromStdString(camera->id());\n> -\t\tcameraCombo_->addItem(cameraId);\n>   \n>   \t\t/* Update cameraIdCombox_ to include the new camera. */\n>   \t\tif (cameraIdComboBox_)\n> @@ -706,16 +715,12 @@ void MainWindow::processHotplug(HotplugEvent *e)\n>   \t\t\ttoggleCapture(false);\n>   \t\t\tcamera_->release();\n>   \t\t\tcamera_.reset();\n> -\t\t\tcameraCombo_->setCurrentIndex(0);\n>   \t\t}\n>   \n>   \t\tif (cameraIdComboBox_) {\n>   \t\t\tint cameraIdIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id()));\n>   \t\t\tcameraIdComboBox_->removeItem(cameraIdIndex);\n>   \t\t}\n> -\n> -\t\tint camIndex = cameraCombo_->findText(QString::fromStdString(camera->id()));\n> -\t\tcameraCombo_->removeItem(camIndex);\n>   \t}\n>   }\n>   \n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index 3a1c6156..b15f9409 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -25,6 +25,7 @@\n>   #include <QMutex>\n>   #include <QObject>\n>   #include <QPointer>\n> +#include <QPushButton>\n>   #include <QQueue>\n>   #include <QStringList>\n>   #include <QTimer>\n> @@ -62,7 +63,7 @@ private Q_SLOTS:\n>   \tvoid quit();\n>   \tvoid updateTitle();\n>   \n> -\tvoid switchCamera(int index);\n> +\tvoid switchCamera();\n>   \tvoid toggleCapture(bool start);\n>   \n>   \tvoid saveImageAs();\n> @@ -96,7 +97,7 @@ private:\n>   \t/* UI elements */\n>   \tQToolBar *toolbar_;\n>   \tQAction *startStopAction_;\n> -\tQComboBox *cameraCombo_;\n> +\tQPushButton *cameraSelectButton_;\n>   \tQAction *saveRaw_;\n>   \tViewFinder *viewfinder_;\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 81184C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Aug 2022 12:24:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F17196332B;\n\tThu,  4 Aug 2022 14:24:14 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E1B66330D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Aug 2022 14:24:13 +0200 (CEST)","from [IPV6:2401:4900:1f3e:69e0:a479:4ccc:ab2a:bf48] (unknown\n\t[IPv6:2401:4900:1f3e:69e0:a479:4ccc:ab2a:bf48])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 75ECE481;\n\tThu,  4 Aug 2022 14:24:12 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659615855;\n\tbh=PaghMcL8NrOfiKVP/xy9uq6XtTjF4vyb0cuJYEr769E=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=HPDt0tzfoA5domHnQ7nTvL+buCqcUUx8DeVP9rLY3Fa/F/5r/qbGt4Y+G1ZNW9sAr\n\tE28Qmap1n/M79q/0ofYdxl3vPQgABQFECqEnW6lsu0F1e6dl6s3PXr/d5aU7qbOxdB\n\tNdByn2pglx/dCGX0pZpd1ud9r5vM6Mu15ApKZMcQjcvzG9EBhvAT6JTqTmh/XWHC1s\n\tOflG2nWQcEhZ2CT9OPf+ylP0W6C767WK/flAm7LsvENAehvbGaiR5ZCXKlGox3+FOP\n\tBd3gUr9a6iZKmumAHU60W896jyejQ3KR2OreDKTZCAazkB+wcS27YKI2gWWJ3SY0Tm\n\tLjqD6oCd2ZHbQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659615853;\n\tbh=PaghMcL8NrOfiKVP/xy9uq6XtTjF4vyb0cuJYEr769E=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=GtLTP3kjRDjs76Ku4iLxjwLUioBNHWl95QF+mGxpxsnvJsq1GoaaYJbs/Pemn9IbI\n\tq1iW3LXIneKwwH0DEYrPC/CE4LtF63mPchOqHimQnw5yb0dUYOb5MFLlfX9WCf854Z\n\tgGPea9GrR0K6SlO8QJBOTzUGyD53XQcboI5cCRdU="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"GtLTP3kj\"; dkim-atps=neutral","Message-ID":"<03caa7ef-c3e7-3dc7-c8f5-e0c4b2931db4@ideasonboard.com>","Date":"Thu, 4 Aug 2022 17:54:07 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.4.1","Content-Language":"en-US","To":"Utkarsh Tiwari <utkarsh02t@gmail.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220803175517.175332-1-utkarsh02t@gmail.com>\n\t<20220803175517.175332-5-utkarsh02t@gmail.com>","In-Reply-To":"<20220803175517.175332-5-utkarsh02t@gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 4/4] qcam: MainWindow: Replace\n\tcameraCombo_ with cameraSelectDialog","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]