[{"id":24376,"web_url":"https://patchwork.libcamera.org/comment/24376/","msgid":"<YuvlKcyqWFpTN6mb@pendragon.ideasonboard.com>","date":"2022-08-04T15:26:33","subject":"Re: [libcamera-devel] [PATCH 1/4] qcam: Use QDialog for selection\n\tof cameras","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Utkarsh,\n\nThank you for the patch.\n\nOn Wed, Aug 03, 2022 at 11:25:14PM +0530, Utkarsh Tiwari via libcamera-devel wrote:\n> Currently we use QInputDialog convenience dialogs to allow the user to\n> select a camera. This doesn't allow adding of more information (such as\n> camera location, model etc).\n> \n> Create a QDialog with a QFormLayout that shows a QComboBox with camera\n> Ids. Use a QButtonBox to provide buttons for accepting and cancelling the\n> action.\n> \n> Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>\n> ---\n>  src/qcam/main_window.cpp | 47 ++++++++++++++++++++++++++++++----------\n>  1 file changed, 35 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 7433d647..7761a6c6 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -16,7 +16,10 @@\n>  \n>  #include <QComboBox>\n>  #include <QCoreApplication>\n> +#include <QDialog>\n> +#include <QDialogButtonBox>\n>  #include <QFileDialog>\n> +#include <QFormLayout>\n>  #include <QImage>\n>  #include <QImageWriter>\n>  #include <QInputDialog>\n\nI think you can now drop this header.\n\n> @@ -291,23 +294,43 @@ void MainWindow::switchCamera(int index)\n>  std::string MainWindow::chooseCamera()\n>  {\n>  \tQStringList cameras;\n> -\tbool result;\n> -\n> -\t/* If only one camera is available, use it automatically. */\n> -\tif (cm_->cameras().size() == 1)\n> -\t\treturn cm_->cameras()[0]->id();\n> +\tstd::string result;\n>  \n>  \t/* Present a dialog box to pick a camera. */\n> +\tQDialog *cameraSelectDialog = new QDialog(this);\n> +\n> +\t/* Setup a QComboBox to display camera Ids. */\n>  \tfor (const std::shared_ptr<Camera> &cam : cm_->cameras())\n> -\t\tcameras.append(QString::fromStdString(cam->id()));\n> +\t\tcameras.push_back(QString::fromStdString(cam->id()));\n\nIs there a specific reason for switching from append() to push_back() ?\n\n> +\n> +\tQComboBox *cameraIdComboBox = new QComboBox;\n> +\tcameraIdComboBox->addItems(cameras);\n> +\n> +\t/* Setup QDialogButtonBox. */\n> +\tQDialogButtonBox *dialogButtonBox = new QDialogButtonBox;\n> +\tdialogButtonBox->addButton(QDialogButtonBox::Cancel);\n> +\tdialogButtonBox->addButton(QDialogButtonBox::Ok);\n\nThere's a convenience API you can use for this:\n\n\tQDialogButtonBox *dialogButtonBox =\n\t\tnew QDialogButtonBox(QDialogButtonBox::Ok |\n\t\t\t\t     QDialogButtonBox::Cancel);\n\n> +\n> +\tconnect(dialogButtonBox, &QDialogButtonBox::accepted,\n> +\t\tthis, [&]() {\n> +\t\t\tresult = cameraIdComboBox->currentText().toStdString();\n> +\t\t\tcameraSelectDialog->accept();\n> +\t\t});\n> +\n> +\tconnect(dialogButtonBox, &QDialogButtonBox::rejected,\n> +\t\tthis, [&]() {\n> +\t\t\tresult = std::string();\n\nThis isn't needed as result is initialized to an empty string.\n\n> +\t\t\tcameraSelectDialog->reject();\n> +\t\t});\n\nWhich means that you can just\n\n\tconnect(dialogButtonBox, &QDialogButtonBox::rejected,\n\t        cameraSelectDialog, &QDialog::reject);\n\nBut overall, given that the next patches make this code more complex,\nyou should create a CameraSelectorDialog class that inherits from\nQDialog, and implement all the camera selection process in there.\n\n> +\n> +\t/* Setup the layout for the dialog. */\n> +\tQFormLayout *cameraSelectLayout = new QFormLayout(cameraSelectDialog);\n> +\tcameraSelectLayout->addRow(\"Camera: \", cameraIdComboBox);\n> +\tcameraSelectLayout->addWidget(dialogButtonBox);\n>  \n> -\tQString id = QInputDialog::getItem(this, \"Select Camera\",\n> -\t\t\t\t\t   \"Camera:\", cameras, 0,\n> -\t\t\t\t\t   false, &result);\n> -\tif (!result)\n> -\t\treturn std::string();\n> +\tcameraSelectDialog->exec();\n>  \n> -\treturn id.toStdString();\n> +\treturn result;\n>  }\n>  \n>  int MainWindow::openCamera()","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 EAAE2C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Aug 2022 15:26:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5D63F63311;\n\tThu,  4 Aug 2022 17:26:43 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B4FCB6330D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Aug 2022 17:26:41 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A7B8481;\n\tThu,  4 Aug 2022 17:26:41 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659626803;\n\tbh=S5oHx+shzEvrVD+vUoxU69wT8FQ4ut5jHnuUQ0GNJOE=;\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:Cc:\n\tFrom;\n\tb=W0W+GDXrK12PnF4Mf+l0rKgPWvRrkb8SpgRgtXUe5BcZHabYiyM42QgvzRp6yoozF\n\tdDI/bdqJEyx3662B+g6GDy1w83edyPF8S3EZX4Sw5R7pxXaaNdVXTkg/FVngaOAywp\n\tICx8YPX4kHuYYjr4kl5nQkK+mujEFSCq97gtlhlQkuCxMSwR0fZh8FaC7/C+E+ZHBF\n\tD0LQ6dd1POMw7/ZDZnt+2ELXRl1Q47QQzMF2drI6d4aqvrP7Lo25FK/gazO3fTjcP6\n\tRzjR+NH6YX8PcA2aVtNmDKN3Nux9TXEXXwU3Wt99zU+8bXYEcTMfaU0dnb/zHoVve/\n\t4p7zQ4Tc5hLQw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659626801;\n\tbh=S5oHx+shzEvrVD+vUoxU69wT8FQ4ut5jHnuUQ0GNJOE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=VB+BUWIMsz5CI9pXLoGvgf+zPvm8a6BCPeDQu52QfLzHg4Iz7M9OSprNVohL9477w\n\tQi6PptaFF3wLjDKcbJwLa1w/cQQaImSGIIYYudWFXpFw6KSmz+EKbQOaTSPtaWxY1f\n\tjbqImLwq/or9Fa/j3z4WnovkhITvWtSzplP2vdbw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"VB+BUWIM\"; dkim-atps=neutral","Date":"Thu, 4 Aug 2022 18:26:33 +0300","To":"Utkarsh Tiwari <utkarsh02t@gmail.com>","Message-ID":"<YuvlKcyqWFpTN6mb@pendragon.ideasonboard.com>","References":"<20220803175517.175332-1-utkarsh02t@gmail.com>\n\t<20220803175517.175332-2-utkarsh02t@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220803175517.175332-2-utkarsh02t@gmail.com>","Subject":"Re: [libcamera-devel] [PATCH 1/4] qcam: Use QDialog for selection\n\tof cameras","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]