Kstars

catalogeditform.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Valentin Boettcher <hiro at protagon.space; @hiro98:tchncs.de>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "catalogeditform.h"
8 #include "dialogs/catalogcoloreditor.h"
9 #include "kstarsdata.h"
10 #include "ui_catalogeditform.h"
11 #include "catalogsdb.h"
12 #include <QColorDialog>
13 
14 CatalogEditForm::CatalogEditForm(QWidget *parent, const CatalogsDB::Catalog &catalog,
15  const int min_id, const bool allow_id_edit)
16  : QDialog(parent), ui(new Ui::CatalogEditForm), m_catalog{ catalog }
17 {
18  ui->setupUi(this);
19  ui->id->setMinimum(min_id);
20  ui->id->setEnabled(allow_id_edit);
21 
22  fill_form_from_catalog();
23  connect(ui->id, QOverload<int>::of(&QSpinBox::valueChanged),
24  [&](const int id) { m_catalog.id = id; });
25 
26  connect(ui->name, &QLineEdit::textChanged,
27  [&](const QString &s) { m_catalog.name = s; });
28 
29  connect(ui->author, &QLineEdit::textChanged,
30  [&](const QString &s) { m_catalog.author = s; });
31 
32  connect(ui->source, &QLineEdit::textChanged,
33  [&](const QString &s) { m_catalog.source = s; });
34 
35  connect(ui->description, &QTextEdit::textChanged,
36  [&]() { m_catalog.description = ui->description->toHtml(); });
37 
38  connect(ui->license, &QLineEdit::textChanged,
39  [&](const QString &s) { m_catalog.license = s; });
40 
41  connect(ui->maintainer, &QLineEdit::textChanged,
42  [&](const QString &s) { m_catalog.maintainer = s; });
43 
44  connect(ui->color, &QPushButton::clicked, [&]() {
45  CatalogColorEditor editor{
46  m_catalog.color == "" ?
47  KStarsData::Instance()->colorScheme()->colorNamed("DSOColor").name() :
48  m_catalog.color
49  };
50 
51  if (editor.exec() != QDialog::Accepted)
52  return;
53 
54  m_catalog.color = editor.color_string();
55  });
56 }
57 
58 CatalogEditForm::~CatalogEditForm()
59 {
60  delete ui;
61 }
62 
63 void CatalogEditForm::fill_form_from_catalog()
64 {
65  ui->id->setValue(m_catalog.id);
66  ui->name->setText(m_catalog.name);
67  ui->author->setText(m_catalog.author);
68  ui->source->setText(m_catalog.source);
69  ui->description->setHtml(m_catalog.description);
70  ui->license->setText(m_catalog.license);
71  ui->maintainer->setText(m_catalog.maintainer);
72 }
QString maintainer
The catalog maintainer.
Definition: catalogsdb.h:100
QString author
The author of the catalog.
Definition: catalogsdb.h:58
int id
The catalog id.
Definition: catalogsdb.h:40
QString license
The catalog license.
Definition: catalogsdb.h:95
A simple data entry form for creating/editing catalog meta information.
void clicked(bool checked)
QString source
The catalog source.
Definition: catalogsdb.h:63
void textChanged(const QString &text)
QString name
The catalog mame.
Definition: catalogsdb.h:45
QString description
A (short) description for the catalog.
Definition: catalogsdb.h:69
void textChanged()
void valueChanged(int i)
A simple struct to hold information about catalogs.
Definition: catalogsdb.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:49 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.