1 /* massXpert - the true massist's program.
2    --------------------------------------
3    Copyright (C) 2006,2007 Filippo Rusconi
4 
5    http://www.filomace.org/massXpert
6 
7    This file is part of the massXpert project.
8 
9    The massxpert project is the successor to the "GNU polyxmass"
10    project that is an official GNU project package (see
11    www.gnu.org). The massXpert project is not endorsed by the GNU
12    project, although it is released ---in its entirety--- under the
13    GNU General Public License. A huge part of the code in massXpert
14    is actually a C++ rewrite of code in GNU polyxmass. As such
15    massXpert was started at the Centre National de la Recherche
16    Scientifique (FRANCE), that granted me the formal authorization to
17    publish it under this Free Software License.
18 
19    This software is free software; you can redistribute it and/or
20    modify it under the terms of the GNU  General Public
21    License version 3, as published by the Free Software Foundation.
22 
23 
24    This software is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28 
29    You should have received a copy of the GNU General Public License
30    along with this software; if not, write to the
31 
32    Free Software Foundation, Inc.,
33 
34    51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
35 */
36 
37 #include<QtGui>
38 #include<QtGlobal>
39 #include<QLocale>
40 #include<QVBoxLayout>
41 #include<QLabel>
42 #include<QGroupBox>
43 #include<QObject>
44 #include<QTextEdit>
45 #include<QComboBox>
46 #include<QPushButton>
47 #include<QMainWindow>
48 
49 #include "massListSorterDlg.hpp"
50 #include "massList.hpp"
51 
52 using massXpert::MassList;
53 
54 
MassListSorterDlg(QWidget * parent)55 MassListSorterDlg::MassListSorterDlg (QWidget *parent)
56   : QDialog (parent, Qt::Dialog)
57 {
58   mp_parent = static_cast<QMainWindow*>(parent);
59 
60   QVBoxLayout *mainLayout = new QVBoxLayout;
61 
62   QLabel *label = new QLabel (tr ("Mass List Sorter Plugin"));
63 
64   mainLayout->addWidget (label, 0, Qt::AlignHCenter);
65 
66   createEditorGroupBox ();
67   mainLayout->addWidget(mp_editorGroupBox);
68 
69   createActionGroupBox ();
70   mainLayout->addWidget (mp_actionGroupBox);
71 
72   setLayout (mainLayout);
73 
74   setAttribute (Qt::WA_DeleteOnClose);
75 
76   setWindowTitle (tr ("Mass List Sorter Plugin"));
77 
78   connect(mp_parent,
79           SIGNAL (aboutToClose ()),
80           this,
81           SLOT (parentClosing ()));
82 }
83 
84 
85 void
parentClosing()86 MassListSorterDlg::parentClosing ()
87 {
88   QDialog::reject ();
89 }
90 
91 
92 void
createEditorGroupBox()93 MassListSorterDlg::createEditorGroupBox ()
94 {
95     mp_editorGroupBox = new QGroupBox (tr ("Manipulated Mass Lists"));
96 
97     QHBoxLayout *layout = new QHBoxLayout;
98 
99     mp_inputEditor = new QTextEdit;
100     layout->addWidget (mp_inputEditor);
101 
102     mp_outputEditor = new QTextEdit;
103     layout->addWidget (mp_outputEditor);
104 
105     mp_editorGroupBox->setLayout(layout);
106 }
107 
108 
109 void
createActionGroupBox()110 MassListSorterDlg::createActionGroupBox ()
111 {
112   mp_actionGroupBox = new QGroupBox (tr ("Actions"));
113 
114   QHBoxLayout *layout = new QHBoxLayout;
115 
116   mp_actionComboBox = new QComboBox ();
117 
118   QStringList menuItems = QStringList ()
119     << tr ("Ascending Order")
120     << tr ("Descending Order");
121 
122   mp_actionComboBox->addItems (menuItems);
123 
124   layout->addWidget (mp_actionComboBox);
125 
126   mp_executePushButton = new QPushButton (tr ("&Execute"));
127   connect(mp_executePushButton,
128 	  SIGNAL (clicked ()),
129 	  this,
130 	  SLOT (execute ()));
131 
132   layout->addWidget (mp_executePushButton);
133 
134   mp_actionGroupBox->setLayout (layout);
135 }
136 
137 
138 void
execute()139 MassListSorterDlg::execute ()
140 {
141   // What's the task to be performed?
142 
143   QString comboText = mp_actionComboBox->currentText ();
144 
145   // What's the text to work on?
146   QString docText = mp_inputEditor->toPlainText ();
147 
148   // Make a mass list with the text.
149   MassList inputMassList ("INPUT_MASS_LIST", docText, QLocale ());
150 
151   // Check the result.
152   if (inputMassList.makeMassList () == -1)
153     return;
154 
155   // Do the sort.
156   if (comboText == tr ("Ascending Order"))
157     inputMassList.sortAscending ();
158   else if (comboText == tr ("Descending Order"))
159     inputMassList.sortDescending ();
160 
161   // Convert list to text.
162   inputMassList.makeMassText ();
163 
164   // Clear the previous output text edit widget.
165   mp_outputEditor->clear ();
166 
167   // Output the new text.
168   mp_outputEditor->setPlainText (inputMassList.massText ());
169 }
170 
171