File indexing completed on 2024-12-01 06:33:53
0001 /* 0002 SPDX-FileCopyrightText: 2021 Valentin Boettcher <hiro at protagon.space; @hiro98:tchncs.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef ADDCATALOGOBJECT_H 0008 #define ADDCATALOGOBJECT_H 0009 0010 #include <QDialog> 0011 #include "catalogobject.h" 0012 0013 namespace Ui 0014 { 0015 class AddCatalogObject; 0016 } 0017 0018 /** 0019 * A simple data entry dialog to create and edit objects in 0020 * `CatalogDB` catalogs. It takes a `CatalogObject` and mutates it 0021 * according to user input. 0022 * 0023 * After the dialog is closed, the contained can then be retrieved by 0024 * calling `get_object`. 0025 */ 0026 class AddCatalogObject : public QDialog 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 /** 0032 * \param parent the parent widget, nullptr allowed 0033 * \parame obj the objects to be mutated, default constructed by default 0034 */ 0035 explicit AddCatalogObject(QWidget *parent, const CatalogObject &obj = {}); 0036 ~AddCatalogObject(); 0037 0038 /** 0039 * Retrieve the edited object. 0040 */ 0041 CatalogObject get_object() { return m_object; } 0042 0043 private: 0044 Ui::AddCatalogObject *ui; 0045 0046 /** The object to be edited. */ 0047 CatalogObject m_object; 0048 0049 /** Fill the form fields with the information from the object. */ 0050 void fill_form_from_object(); 0051 0052 /** Enable/Disable the `flux` field depending on object type. */ 0053 void refresh_flux(); 0054 0055 /** Guess the contents of the form by parsing the supplied text. */ 0056 void guess_form_contents_from_text(QString text); 0057 0058 private slots: 0059 /** Overload of the above that prompts for the text using an input box. */ 0060 void guess_form_contents_from_text(); 0061 }; 0062 0063 #endif // ADDCATALOGOBJECT_H