1 /***************************************************************************
2 addcatdialog.cpp - description
5 copyright : (C) 2002 by Jason Harris
6 email : kstars@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
19 #include <kmessagebox.h>
22 #include "kstarsdata.h"
23 //#include "skyobject.h"
24 //#include "starobject.h"
25 #include "addcatdialog.h"
27 AddCatDialog::AddCatDialog( QWidget
*parent
)
28 : KDialogBase( KDialogBase::Plain
, i18n( "Add Catalog" ), Help
|Ok
|Cancel
, Ok
, parent
) {
30 QFrame
*page
= plainPage();
32 vlay
= new QVBoxLayout( page
, 0, spacingHint() );
33 acd
= new AddCatDialogUI(page
);
34 vlay
->addWidget( acd
);
36 connect( acd
->catFileName
, SIGNAL( textChanged( const QString
& ) ), this, SLOT( slotCheckLineEdits() ) );
37 connect( acd
->catName
, SIGNAL( textChanged( const QString
& ) ), this, SLOT( slotCheckLineEdits() ) );
38 connect( this, SIGNAL( okClicked() ), this, SLOT( slotValidateFile() ) );
39 // connect( catName, SIGNAL( returnPressed() ), this, SLOT( checkLineEdits() ) );
41 enableButtonOK( false ); //disable until both lineedits are filled
43 objList
.setAutoDelete( false );
46 AddCatDialog::~AddCatDialog(){
49 void AddCatDialog::slotOk() {
50 //Overriding slotOk() so that custom data file can be validated before
51 //QDialog::accept() is emitted and the window is closed.
53 //the validation code needs to be aware of AddCatDialog members, so I will just
54 //emit the okClicked() signal, which is connected to AddCatDialog::validateFile()
58 void AddCatDialog::slotHelp() {
60 i18n( "A valid custom catalog file has one line per object, "
61 "with the following fields in each line:") + "\n\t" +
62 i18n( "1. Type identifier. Must be one of: 0 (star), 3 (open cluster), 4 (globular cluster), "
63 "5 (gaseous nebula), 6 (planetary nebula), 7 (supernova remnant), or 8 (galaxy)" ) + "\n\t" +
64 i18n( "2. Right Ascension (floating-point value)" ) + "\n\t" +
65 i18n( "3. Declination (floating-point value)" ) + "\n\t" +
66 i18n( "4. Magnitude (floating-point value)" ) + "\n\t" +
67 i18n( "5. Spectral type (if type=0); otherwise object's catalog name" ) + "\n\t" +
68 i18n( "6. Star name (if type=0); otherwise object's common name. [field 6 is optional]" ) + "\n\n" +
70 i18n( "The fields should be separated by whitespace. In addition, the catalog "
71 "may contain comment lines beginning with \'#\'." );
73 KMessageBox::information( 0, message
, i18n( "Help on custom catalog file format" ) );
76 void AddCatDialog::slotValidateFile() {
77 //A Valid custom data file must satisfy the following conditions:
78 //1. Each line is either a comment (beginning with '#'), or a data line
79 //2. A data line consists of whitespace-delimited fields
80 // a. the object type integer is the first field
81 // b. the RA, Dec, and magnitude are the 2nd, 3rd and 4th fields (J2000 coords)
82 // c. If type==0 (or 1) (star), the next fields are the spectral type and the name (if any)
83 // d. If type==3-8, the next fields are the primary name and long name (if any)
84 // the type cannot be 1 or 2 (redundant star category and planet)
86 // Also, if names contain spaces, they should be enclosed in quotes so they
87 // aren't split into multiple fields.
89 // I moved the file parse code to KStarsData, so we can read in custom
90 // data files without needing an AddCatDialog (on startup, for example).
91 // The bool argument below flags whether the detailed warning messagebox
92 // should appear when parse errors are found.
93 KStars
*ksw
= (KStars
*) parent()->parent(); // ViewOpsDialog->KStars
94 bool result
= ksw
->data()->readCustomData( filename(), objList
, true );
97 emit
QDialog::accept();
102 void AddCatDialog::slotCheckLineEdits() {
103 enableButtonOK(! acd
->catFileName
->lineEdit()->text().isEmpty() && ! acd
->catName
->text().isEmpty());
106 #include "addcatdialog.moc"