Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for undo/redo selections, including custom menu text. #1056

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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