1 /******************************************************************************
2 
3   This source file is part of the Avogadro project.
4 
5   Copyright 2013 Kitware, Inc.
6 
7   This source code is released under the New BSD License, (the "License").
8 
9   Unless required by applicable law or agreed to in writing, software
10   distributed under the License is distributed on an "AS IS" BASIS,
11   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   See the License for the specific language governing permissions and
13   limitations under the License.
14 
15 ******************************************************************************/
16 
17 #include "lineformatinputdialog.h"
18 #include "ui_lineformatinputdialog.h"
19 
20 #include <QtCore/QSettings>
21 
22 namespace Avogadro {
23 namespace QtPlugins {
24 
LineFormatInputDialog(QWidget * aParent)25 LineFormatInputDialog::LineFormatInputDialog(QWidget* aParent)
26   : QDialog(aParent), m_ui(new Ui::LineFormatInputDialog)
27 {
28   m_ui->setupUi(this);
29 }
30 
~LineFormatInputDialog()31 LineFormatInputDialog::~LineFormatInputDialog()
32 {
33   delete m_ui;
34 }
35 
setFormats(const QStringList & indents)36 void LineFormatInputDialog::setFormats(const QStringList& indents)
37 {
38   m_ui->formats->clear();
39   m_ui->formats->addItems(indents);
40 
41   QSettings settings;
42   QString lastUsed = settings.value("lineformatinput/lastUsed").toString();
43   int index = m_ui->formats->findText(lastUsed);
44   if (index >= 0)
45     m_ui->formats->setCurrentIndex(index);
46 }
47 
format() const48 QString LineFormatInputDialog::format() const
49 {
50   return m_ui->formats->currentText();
51 }
52 
setCurrentFormat(const QString & format)53 void LineFormatInputDialog::setCurrentFormat(const QString& format)
54 {
55   int index = m_ui->formats->findText(format);
56   if (index >= 0)
57     m_ui->formats->setCurrentIndex(index);
58 }
59 
descriptor() const60 QString LineFormatInputDialog::descriptor() const
61 {
62   return m_ui->descriptor->text();
63 }
64 
accept()65 void LineFormatInputDialog::accept()
66 {
67   QSettings settings;
68   settings.setValue("lineformatinput/lastUsed", format());
69   QDialog::accept();
70 }
71 
72 } // namespace QtPlugins
73 } // namespace Avogadro
74