Skip to content

Commit

Permalink
Update to use rich text delegate and charged formula
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Oct 28, 2024
1 parent dd4b6af commit 6730c3c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 473 deletions.
12 changes: 9 additions & 3 deletions avogadro/qtplugins/molecularproperties/molecularmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ int MolecularModel::columnCount(const QModelIndex& parent) const
return 1; // values
}

QString formatFormula(std::string f)
QString formatFormula(Molecule* m)
{
QString formula = QString::fromStdString(f);
QString formula = QString::fromStdString(molecule->formula());
QRegularExpression digitParser("(\\d+)");

QRegularExpressionMatchIterator i = digitParser.globalMatch(formula);
Expand All @@ -74,6 +74,12 @@ QString formatFormula(std::string f)
QString("<sub>%1</sub>").arg(digits));
offset += 11; // length of <sub>...</sub>
}

// add total charge as a superscript
int charge = m->totalCharge();
if (charge != 0)
formula += QString("<sup>%1</sup>").arg(charge);

return formula;
}

Expand Down Expand Up @@ -105,7 +111,7 @@ QVariant MolecularModel::data(const QModelIndex& index, int role) const
} else if (row == Mass) {
return m_molecule->mass();
} else if (row == Formula) {
return formatFormula(m_molecule->formula());
return formatFormula(m_molecule);
} else if (row == Atoms) {
return QVariant::fromValue(m_molecule->atomCount());
} else if (row == Bonds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
#include "molecularproperties.h"
#include "molecularview.h"

#include <avogadro/qtgui/richtextdelegate.h>

#include <QAction>
#include <QStringList>
#include <QtWidgets/QDialog>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QVBoxLayout>

using Avogadro::QtGui::RichTextDelegate;

namespace Avogadro::QtPlugins {

MolecularProperties::MolecularProperties(QObject* parent_)
Expand Down Expand Up @@ -69,6 +73,8 @@ void MolecularProperties::showDialog()
view->setSourceModel(model);
view->setModel(model);

view->setItemDelegateForColumn(0, new RichTextDelegate(view));

view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->resizeColumnsToContents();

Expand Down
251 changes: 0 additions & 251 deletions avogadro/qtplugins/molecularproperties/molecularpropertiesdialog.cpp

This file was deleted.

75 changes: 0 additions & 75 deletions avogadro/qtplugins/molecularproperties/molecularpropertiesdialog.h

This file was deleted.

Loading

0 comments on commit 6730c3c

Please sign in to comment.