Skip to content

Commit

Permalink
Merge pull request #1056 from ghutchis/undo-selection
Browse files Browse the repository at this point in the history
Add support for undo/redo selections, including custom menu text.
  • Loading branch information
ghutchis authored Jul 25, 2022
2 parents 7544d65 + 4529f9a commit b3b2a80
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 80 deletions.
9 changes: 6 additions & 3 deletions avogadro/qtgui/rwmolecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ bool RWMolecule::setAtomPosition3d(Index atomId, const Vector3& pos,
return true;
}

void RWMolecule::setAtomSelected(Index atomId, bool selected)
void RWMolecule::setAtomSelected(Index atomId, bool selected, const QString& undoText)
{
// FIXME: Add in an implementation (and use it from the selection tool).
m_molecule.setAtomSelected(atomId, selected);
auto* comm = new ModifySelectionCommand(*this, atomId, selected);
comm->setText(undoText);
comm->setCanMerge(true);
m_undoStack.push(comm);
// m_molecule.setAtomSelected(atomId, selected);
}

bool RWMolecule::atomSelected(Index atomId) const
Expand Down
22 changes: 11 additions & 11 deletions avogadro/qtgui/rwmolecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ class AVOGADROQTGUI_EXPORT RWMolecule : public QObject
*/
Vector3 atomPosition3d(Index atomId) const;

std::string label(Index atomId) const;
bool setLabel(Index atomId, const std::string& label,
const QString& undoText = QStringLiteral("Change Atom Label"));
/**
* Replace the current array of 3D atomic coordinates.
* @param pos The new coordinate array. Must be of length atomCount().
Expand All @@ -214,7 +211,7 @@ class AVOGADROQTGUI_EXPORT RWMolecule : public QObject
*/
bool setAtomPositions3d(
const Core::Array<Vector3>& pos,
const QString& undoText = QStringLiteral("Change Atom Positions"));
const QString& undoText = tr("Change Atom Positions"));

/**
* Set the 3D position of a single atom.
Expand All @@ -223,14 +220,18 @@ class AVOGADROQTGUI_EXPORT RWMolecule : public QObject
* @param undoText The undo text to be displayed for undo commands.
* @return True on success, false otherwise.
*/
bool setAtomPosition3d(
Index atomId, const Vector3& pos,
const QString& undoText = QStringLiteral("Change Atom Position"));
bool setAtomPosition3d(Index atomId, const Vector3& pos,
const QString& undoText = tr("Change Atom Position"));

std::string label(Index atomId) const;
bool setLabel(Index atomId, const std::string& label,
const QString& undoText = tr("Change Atom Label"));

/**
* Set whether the specified atom is selected or not.
*/
void setAtomSelected(Index atomId, bool selected);
void setAtomSelected(Index atomId, bool selected,
const QString& undoText = tr("Change Selection"));

/**
* Query whether the supplied atom index has been selected.
Expand Down Expand Up @@ -834,9 +835,8 @@ inline Core::Array<RWMolecule::BondType> RWMolecule::bonds(
auto atomBonds = m_molecule.bonds(atomId);
Core::Array<RWMolecule::BondType> result;
for (Index i = 0; i < atomBonds.size(); ++i) {
result.push_back(BondType(
const_cast<RWMolecule *>(this), atomBonds[i].index()
));
result.push_back(
BondType(const_cast<RWMolecule*>(this), atomBonds[i].index()));
}
return result;
}
Expand Down
Loading

0 comments on commit b3b2a80

Please sign in to comment.