diff --git a/avogadro/molequeue/inputgeneratorwidget.cpp b/avogadro/molequeue/inputgeneratorwidget.cpp index f6f4c5f699..4c1ae8914b 100644 --- a/avogadro/molequeue/inputgeneratorwidget.cpp +++ b/avogadro/molequeue/inputgeneratorwidget.cpp @@ -64,8 +64,10 @@ void InputGeneratorWidget::setMolecule(QtGui::Molecule* mol) m_molecule->disconnect(this); m_molecule = mol; - if (mol) { + // make sure to call the base class method + QtGui::JsonWidget::setMolecule(mol); + connect(mol, SIGNAL(changed(unsigned int)), SLOT(updatePreviewText())); connect(mol, SIGNAL(changed(unsigned int)), SLOT(updateTitlePlaceholder())); } @@ -120,6 +122,13 @@ void InputGeneratorWidget::showEvent(QShowEvent* e) { QWidget::showEvent(e); + if (m_molecule != nullptr) { + int charge = static_cast(m_molecule->totalCharge()); + int multiplicity = static_cast(m_molecule->totalSpinMultiplicity()); + setOption("Charge", charge); + setOption("Multiplicity", multiplicity); + } + // Update the preview text if an update was requested while hidden. Use a // single shot to allow the dialog to show before popping up any warnings. if (m_updatePending) @@ -649,4 +658,4 @@ void InputGeneratorWidget::updateOptions() setOptionDefaults(); } -} // namespace Avogadro +} // namespace Avogadro::MoleQueue diff --git a/avogadro/qtgui/jsonwidget.cpp b/avogadro/qtgui/jsonwidget.cpp index 237745c235..1e04b9f4ab 100644 --- a/avogadro/qtgui/jsonwidget.cpp +++ b/avogadro/qtgui/jsonwidget.cpp @@ -40,6 +40,15 @@ JsonWidget::~JsonWidget() {} void JsonWidget::setMolecule(QtGui::Molecule* mol) { + if (m_molecule != nullptr) { + // update charge and multiplicity if needed + int charge = static_cast(m_molecule->totalCharge()); + int multiplicity = static_cast(m_molecule->totalSpinMultiplicity()); + + setOption("Charge", charge); + setOption("Multiplicity", multiplicity); + } + if (mol == m_molecule) return; @@ -816,8 +825,11 @@ QJsonObject JsonWidget::collectOptions() const void JsonWidget::applyOptions(const QJsonObject& opts) { - foreach (const QString& label, opts.keys()) + foreach (const QString& label, opts.keys()) { setOption(label, opts[label]); + + qDebug() << "Setting option" << label << "to" << opts[label]; + } } QString JsonWidget::generateJobTitle() const diff --git a/avogadro/qtplugins/CMakeLists.txt b/avogadro/qtplugins/CMakeLists.txt index 1926f7f749..36122820dc 100644 --- a/avogadro/qtplugins/CMakeLists.txt +++ b/avogadro/qtplugins/CMakeLists.txt @@ -106,7 +106,7 @@ add_subdirectory(configurepython) add_subdirectory(copypaste) add_subdirectory(crystal) add_subdirectory(customelements) -add_subdirectory(dipole) +# add_subdirectory(dipole) add_subdirectory(editor) add_subdirectory(fetchpdb) add_subdirectory(focus) diff --git a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp index d28aa37f9f..ccd2ae7408 100644 --- a/avogadro/qtplugins/molecularproperties/molecularmodel.cpp +++ b/avogadro/qtplugins/molecularproperties/molecularmodel.cpp @@ -243,9 +243,10 @@ QVariant MolecularModel::data(const QModelIndex& index, int role) const else if (key == " 7residues") return QVariant::fromValue(m_molecule->residueCount()); else if (key == " 9totalCharge") - return QVariant::fromValue(m_molecule->totalCharge()); + return QVariant::fromValue(static_cast(m_molecule->totalCharge())); else if (key == " 9totalSpinMultiplicity") - return QVariant::fromValue(m_molecule->totalSpinMultiplicity()); + return QVariant::fromValue( + static_cast(m_molecule->totalSpinMultiplicity())); return QString::fromStdString(it->second.toString()); } @@ -336,6 +337,18 @@ Qt::ItemFlags MolecularModel::flags(const QModelIndex& index) const // for the types and columns that can be edited auto editable = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; + int row = index.row(); + + if (row == 0) // name + return editable; + + const auto map = m_propertiesCache; + auto it = map.begin(); + std::advance(it, row); + auto key = it->first; + if (key == " 9totalCharge" || key == " 9totalSpinMultiplicity") + return editable; + return QAbstractItemModel::flags(index); } @@ -348,7 +361,34 @@ bool MolecularModel::setData(const QModelIndex& index, const QVariant& value, if (role != Qt::EditRole) return false; - // TODO allow editing name, total charge, total spin multiplicity + int row = index.row(); + + if (row == 0) { // name should always be the first row + m_name = value.toString(); + m_autoName = false; + m_molecule->setData("name", m_name.toStdString()); + emit dataChanged(index, index); + return true; + } + + const auto map = m_propertiesCache; + auto it = map.begin(); + std::advance(it, row); + auto key = it->first; + if (key == " 9totalCharge") { + m_molecule->setData("totalCharge", value.toInt()); + emit dataChanged(index, index); + return true; + } else if (key == " 9totalSpinMultiplicity") { + int spin = value.toInt(); + if (spin < 1) + return false; + + m_molecule->setData("totalSpinMultiplicity", value.toInt()); + emit dataChanged(index, index); + return true; + } + return false; } @@ -391,11 +431,11 @@ void MolecularModel::updateTable(unsigned int flags) m_propertiesCache.setValue(" 8chains", chainCount); } - if (m_molecule->totalCharge() != 0) - m_propertiesCache.setValue(" 9totalCharge", m_molecule->totalCharge()); - if (m_molecule->totalSpinMultiplicity() != 1) - m_propertiesCache.setValue(" 9totalSpinMultiplicity", - m_molecule->totalSpinMultiplicity()); + m_propertiesCache.setValue(" 9totalCharge", + static_cast(m_molecule->totalCharge())); + m_propertiesCache.setValue( + " 9totalSpinMultiplicity", + static_cast(m_molecule->totalSpinMultiplicity())); if (m_molecule->hasData("dipoleMoment")) { auto dipole = m_molecule->data("dipoleMoment").toVector3(); QString moment = QString::number(dipole.norm(), 'f', 3); diff --git a/avogadro/qtplugins/molecularproperties/molecularview.cpp b/avogadro/qtplugins/molecularproperties/molecularview.cpp index 81721b3165..a95cb62003 100644 --- a/avogadro/qtplugins/molecularproperties/molecularview.cpp +++ b/avogadro/qtplugins/molecularproperties/molecularview.cpp @@ -174,6 +174,7 @@ void MolecularView::openExportDialogBox() // Write the data rows for (int row = 0; row < model()->rowCount(); ++row) { + stream << model()->headerData(row, Qt::Vertical).toString() << ","; for (int col = 0; col < model()->columnCount(); ++col) { stream << model()->index(row, col).data().toString(); if (col < model()->columnCount() - 1) {