| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#include "lineformatinputdialog.h" |
| 7 |
#include "ui_lineformatinputdialog.h" |
| 8 |
|
| 9 |
#include <QtCore/QSettings> |
| 10 |
|
| 11 |
namespace Avogadro::QtPlugins { |
| 12 |
|
| 13 |
LineFormatInputDialog::LineFormatInputDialog(QWidget* aParent) |
| 14 |
: QDialog(aParent), m_ui(new Ui::LineFormatInputDialog) |
| 15 |
{ |
| 16 |
m_ui->setupUi(this); |
| 17 |
|
| 18 |
QSettings settings; |
| 19 |
// set the last used descriptor |
| 20 |
QString lastDescriptor = |
| 21 |
settings.value("lineformatinput/lastDescriptor").toString(); |
| 22 |
setDescriptor(lastDescriptor); |
| 23 |
} |
| 24 |
|
| 25 |
LineFormatInputDialog::~LineFormatInputDialog() |
| 26 |
{ |
| 27 |
delete m_ui; |
| 28 |
} |
| 29 |
|
| 30 |
void LineFormatInputDialog::setFormats(const QStringList& indents) |
| 31 |
{ |
| 32 |
m_ui->formats->clear(); |
| 33 |
m_ui->formats->addItems(indents); |
| 34 |
|
| 35 |
QSettings settings; |
| 36 |
QString lastUsed = settings.value("lineformatinput/lastUsed").toString(); |
| 37 |
int index = m_ui->formats->findText(lastUsed); |
| 38 |
if (index >= 0) |
| 39 |
m_ui->formats->setCurrentIndex(index); |
| 40 |
} |
| 41 |
|
| 42 |
QString LineFormatInputDialog::format() const |
| 43 |
{ |
| 44 |
return m_ui->formats->currentText(); |
| 45 |
} |
| 46 |
|
| 47 |
void LineFormatInputDialog::setCurrentFormat(const QString& format) |
| 48 |
{ |
| 49 |
int index = m_ui->formats->findText(format); |
| 50 |
if (index >= 0) |
| 51 |
m_ui->formats->setCurrentIndex(index); |
| 52 |
} |
| 53 |
|
| 54 |
void LineFormatInputDialog::setDescriptor(const QString& descriptor) |
| 55 |
{ |
| 56 |
m_ui->descriptor->setText(descriptor); |
| 57 |
} |
| 58 |
|
| 59 |
QString LineFormatInputDialog::descriptor() const |
| 60 |
{ |
| 61 |
return m_ui->descriptor->text(); |
| 62 |
} |
| 63 |
|
| 64 |
void LineFormatInputDialog::accept() |
| 65 |
{ |
| 66 |
QSettings settings; |
| 67 |
settings.setValue("lineformatinput/lastUsed", format()); |
| 68 |
settings.setValue("lineformatinput/lastDescriptor", descriptor()); |
| 69 |
QDialog::accept(); |
| 70 |
} |
| 71 |
|
| 72 |
} // namespace Avogadro::QtPlugins |