Stellarium 0.15.2
MSSearchDialog.hpp
1 /*
2  * Stellarium: Meteor Showers Plug-in
3  * Copyright (C) 2013-2015 Marcos Cardinot
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19 
20 #ifndef _MSSEARCHDIALOG_HPP_
21 #define _MSSEARCHDIALOG_HPP_
22 
23 #include <QTreeWidget>
24 
25 #include "MeteorShowers.hpp"
26 #include "StelDialog.hpp"
27 
28 class Ui_MSSearchDialog;
29 
33 class MSSearchDialog : public StelDialog
34 {
35  Q_OBJECT
36 
37 public:
40  enum ModelColumns {
41  ColumnName,
46  };
47 
50 
53 
54 protected:
56  void createDialogContent();
57 
58 public slots:
59  void retranslate();
60 
61 private slots:
63  void checkDates();
64 
66  void searchEvents();
67 
69  void selectEvent(const QModelIndex &modelIndex);
70 
73  void refreshRangeDates();
74 
75 private:
76  MeteorShowersMgr* m_mgr;
77  Ui_MSSearchDialog* m_ui;
78 
80  void initListEvents();
81 
83  void setHeaderNames();
84 };
85 
86 // Reimplements the QTreeWidgetItem class to fix the sorting bug
87 class MSTreeWidgetItem : public QTreeWidgetItem
88 {
89 public:
90  MSTreeWidgetItem(QTreeWidget* parent)
91  : QTreeWidgetItem(parent)
92  {
93  }
94 
95 private:
96  bool operator < (const QTreeWidgetItem &other) const
97  {
98  int column = treeWidget()->sortColumn();
99 
100  if (column == MSSearchDialog::ColumnPeak)
101  {
102  QDateTime a = QDateTime::fromString(text(column),"dd/MMM/yyyy");
103  QDateTime b = QDateTime::fromString(other.text(column),"dd/MMM/yyyy");
104  return a.operator < (b);
105  }
106  else if (column == MSSearchDialog::ColumnZHR)
107  {
108  // the zhr can be variable ("min-max")
109  QStringList as = text(column).split("-");
110  QStringList bs = other.text(column).split("-");
111  // in case of "variable", choose max value (1)
112  int a = as.size() == 1? as.at(0).toInt() : as.at(1).toInt();
113  int b = bs.size() == 1? bs.at(0).toInt() : bs.at(1).toInt();
114  return a < b;
115  }
116  else //ColumnName or ColumnDataType
117  {
118  return text(column).toLower() < other.text(column).toLower();
119  }
120  }
121 };
122 
123 #endif // _MSSEARCHDIALOG_HPP_
ModelColumns
Defines the number and the order of the columns in the table that lists active meteor showers...
Base class for all the GUI windows in Stellarium.
Definition: StelDialog.hpp:72
Main class of the Meteor Showers plugin, inherits from StelObjectModule.
~MSSearchDialog()
Destructor.
void createDialogContent()
Initialize the dialog and connect the signals/slots.
MSSearchDialog(MeteorShowersMgr *mgr)
Constructor.