Skip to content

Commit

Permalink
Split ligands and functioanl groups in the template tool
Browse files Browse the repository at this point in the history
Fixes OpenChemistry#1496

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 8, 2023
1 parent d1f1560 commit e4e4419
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 23 deletions.
3 changes: 3 additions & 0 deletions avogadro/qtplugins/templatetool/templatetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ void TemplateTool::atomLeftClick(QMouseEvent*)
// - check if we should use the clipboard
// - otherwise use the template
Molecule templateMolecule;

qDebug() << "ligandString: " << m_toolWidget->ligandString();

if (m_toolWidget->ligandString() == "Clipboard") {
const QMimeData* mimeData(QApplication::clipboard()->mimeData());

Expand Down
68 changes: 51 additions & 17 deletions avogadro/qtplugins/templatetool/templatetoolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ const int ELEMENT_SELECTOR_TAG = 255;
namespace Avogadro {
namespace QtPlugins {

enum TabType
{
Elements = 0,
Ligands = 1,
FunctionalGroups = 2
};

enum LigandType
{
Monodentate = 0,
Expand All @@ -35,7 +42,6 @@ enum LigandType
Tetradentate = 3,
Hexadentate = 4,
Haptic = 5,
FunctionalGroup = 6,
Clipboard = 7
};

Expand Down Expand Up @@ -79,6 +85,9 @@ TemplateToolWidget::TemplateToolWidget(QWidget* parent_)
connect(m_ui->ligandComboBox, SIGNAL(currentIndexChanged(int)), this,
SLOT(ligandChanged(int)));

connect(m_ui->groupComboBox, SIGNAL(currentIndexChanged(int)), this,
SLOT(groupChanged(int)));

// default coordination = octahedral
QString currentCoord = settings.value("coordination", "6-oct").toString();
int index = m_centers.indexOf(currentCoord);
Expand All @@ -94,6 +103,7 @@ TemplateToolWidget::TemplateToolWidget(QWidget* parent_)
m_ui->typeComboBox->setCurrentIndex(ligandType);
// update the ligand combo box
typeChanged(ligandType);
groupChanged(0);
}

TemplateToolWidget::~TemplateToolWidget()
Expand Down Expand Up @@ -153,6 +163,17 @@ unsigned char TemplateToolWidget::ligand() const

QString TemplateToolWidget::ligandString() const
{
// first check which tab is open
int tabIndex = m_ui->tabWidget->currentIndex();

if (tabIndex == TabType::FunctionalGroups) {
// check if it's "other"
if (m_ui->groupComboBox->currentText() == "Other…")
return m_ligandPath;
else
return m_ui->groupComboBox->currentText();
}

// tell us if we are using the clipboard
if (m_ui->typeComboBox->currentIndex() == LigandType::Clipboard)
return "Clipboard";
Expand All @@ -176,9 +197,34 @@ void TemplateToolWidget::coordinationChanged(int index)
m_ui->centerPreview->setIcon(QIcon(":/icons/centers/" + iconName + ".png"));
}

void TemplateToolWidget::groupChanged(int index)
{
// get the current name from the text
QString groupName = m_ui->groupComboBox->currentText();
QString iconName = groupName;
m_denticity = 1;

// check if it's "other"
if (index == m_ui->groupComboBox->count() - 1) {
QString path = "fragments/groups";

if (m_fragmentDialog != nullptr)
m_fragmentDialog->deleteLater();

m_fragmentDialog = new QtGui::InsertFragmentDialog(this, path);
connect(m_fragmentDialog, SIGNAL(performInsert(const QString&, bool)), this,
SLOT(otherLigandInsert(const QString&, bool)));
m_fragmentDialog->show();
return;
}

m_ui->groupPreview->setIcon(QIcon(":/icons/ligands/" + iconName + ".png"));
}

void TemplateToolWidget::ligandChanged(int index)
{
if (index < 0 || index > m_ui->ligandComboBox->count())
// we need to check if it's "other"
if (index < 0 || index > m_ui->ligandComboBox->count() - 1)
return;

// get the icon name
Expand Down Expand Up @@ -211,9 +257,6 @@ void TemplateToolWidget::ligandChanged(int index)
case LigandType::Haptic:
path += "/ligands/haptic";
break;
case LigandType::FunctionalGroup:
path += "/groups";
break;
}

if (m_fragmentDialog != nullptr)
Expand Down Expand Up @@ -247,6 +290,9 @@ void TemplateToolWidget::otherLigandInsert(const QString& fileName,
if (iconName.endsWith(".cjson"))
iconName.chop(6);
iconName += ".png";

// check which tab is active

m_ui->ligandPreview->setIcon(QIcon(iconName));
}

Expand Down Expand Up @@ -319,18 +365,6 @@ void TemplateToolWidget::typeChanged(int index)
<< "eta-other";
m_denticity = 1;
break;
case LigandType::FunctionalGroup: // Functional Groups
ligandNames << "amide"
<< "carboxylate"
<< "ester"
<< "nitro"
<< "phenyl"
<< "sulfonate" << tr("Other…");
m_ligands = ligandNames;
// make sure last one is "other"
m_ligands.last() = "1-other";
m_denticity = 1;
break;
case LigandType::Clipboard: // Clipboard
ligandNames << "clipboard";
m_ligands = ligandNames;
Expand Down
1 change: 1 addition & 0 deletions avogadro/qtplugins/templatetool/templatetoolwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private slots:

void typeChanged(int index);
void ligandChanged(int index);
void groupChanged(int index);

void otherLigandInsert(const QString& fileName, bool crystal);

Expand Down
120 changes: 114 additions & 6 deletions avogadro/qtplugins/templatetool/templatetoolwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="centersTab">
<property name="minimumSize">
Expand Down Expand Up @@ -356,11 +356,6 @@
<string>Haptic</string>
</property>
</item>
<item>
<property name="text">
<string>Functional Groups</string>
</property>
</item>
<item>
<property name="text">
<string>From Clipboard</string>
Expand Down Expand Up @@ -455,6 +450,119 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Groups</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Group:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="groupComboBox">
<item>
<property name="text">
<string>amide</string>
</property>
</item>
<item>
<property name="text">
<string>carboxylate</string>
</property>
</item>
<item>
<property name="text">
<string>ester</string>
</property>
</item>
<item>
<property name="text">
<string>nitro</string>
</property>
</item>
<item>
<property name="text">
<string>phenyl</string>
</property>
</item>
<item>
<property name="text">
<string>sulfonate</string>
</property>
</item>
<item>
<property name="text">
<string>Other...</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QToolButton" name="groupPreview">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down

1 comment on commit e4e4419

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: clang-format-diff detected formatting issues. See the artifact for a patch or run clang-format on your branch.

Please sign in to comment.