File indexing completed on 2024-05-19 05:42:18

0001 // ct_lvtqtc_inputdialog.h                                    -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #ifndef INCLUDED_CT_LVTQTC_NAME_TOOLTIP_DIALOG
0021 #define INCLUDED_CT_LVTQTC_NAME_TOOLTIP_DIALOG
0022 
0023 #include <lvtqtc_export.h>
0024 
0025 #include <QByteArray>
0026 #include <QDialog>
0027 #include <QLabel>
0028 #include <QString>
0029 
0030 #include <any>
0031 #include <functional>
0032 #include <memory>
0033 #include <vector>
0034 
0035 namespace Codethink::lvtqtc {
0036 class LVTQTC_EXPORT InputDialog : public QDialog {
0037     // dialog that returns the name and tooltip of a created entity
0038     // upon accepted.
0039     // should not be used if rejected.
0040 
0041     Q_OBJECT
0042   public:
0043     explicit InputDialog(const QString& title = tr("Input Dialog"), QWidget *parent = nullptr);
0044     ~InputDialog() override;
0045 
0046     // List of pair - field name, field text.
0047     void prepareFields(const std::vector<std::pair<QByteArray, QString>>& fields);
0048     [[nodiscard]] virtual std::any fieldValue(const QByteArray& fieldId) const;
0049 
0050     void addTextField(const QByteArray& fieldId, const QString& labelText);
0051     void setTextFieldValue(const QByteArray& fieldId, const QString& value);
0052 
0053     void addComboBoxField(const QByteArray& fieldId, const QString& labelText, const std::vector<QString>& options);
0054     void addSpinBoxField(const QByteArray& fieldId, const QString& labelText, std::pair<int, int> minMax, int value);
0055     void finish();
0056 
0057     int exec() override;
0058 
0059     void overrideExec(std::function<bool(void)> exec);
0060     // should be used only for testing purposes.
0061 
0062   protected:
0063     void registerField(const QByteArray& fieldId, const QString& labelText, QWidget *widget);
0064     void showEvent(QShowEvent *ev) override;
0065 
0066   private:
0067     struct Private;
0068     std::unique_ptr<Private> d;
0069 };
0070 
0071 } // namespace Codethink::lvtqtc
0072 
0073 #endif