Skip to content

Commit

Permalink
Refactor ComponentSymbolVariantItemListEditorWidget
Browse files Browse the repository at this point in the history
Using Qt's model/view framework.
  • Loading branch information
ubruhin committed Jun 6, 2019
1 parent 614e136 commit d44243c
Show file tree
Hide file tree
Showing 13 changed files with 1,262 additions and 576 deletions.
137 changes: 137 additions & 0 deletions libs/librepcb/library/cmp/cmd/cmdcomponentsymbolvariantitemedit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*******************************************************************************
* Includes
******************************************************************************/
#include "cmdcomponentsymbolvariantitemedit.h"

#include <QtCore>

/*******************************************************************************
* Namespace
******************************************************************************/
namespace librepcb {
namespace library {

/*******************************************************************************
* Constructors / Destructor
******************************************************************************/

CmdComponentSymbolVariantItemEdit::CmdComponentSymbolVariantItemEdit(
ComponentSymbolVariantItem& item) noexcept
: UndoCommand(tr("Edit component symbol variant item")),
mItem(item),
mOldSymbolUuid(item.getSymbolUuid()),
mNewSymbolUuid(mOldSymbolUuid),
mOldSymbolPos(item.getSymbolPosition()),
mNewSymbolPos(mOldSymbolPos),
mOldSymbolRot(item.getSymbolRotation()),
mNewSymbolRot(mOldSymbolRot),
mOldIsRequired(item.isRequired()),
mNewIsRequired(mOldIsRequired),
mOldSuffix(item.getSuffix()),
mNewSuffix(mOldSuffix),
mOldPinSignalMap(item.getPinSignalMap()),
mNewPinSignalMap(mOldPinSignalMap) {
}

CmdComponentSymbolVariantItemEdit::
~CmdComponentSymbolVariantItemEdit() noexcept {
}

/*******************************************************************************
* Setters
******************************************************************************/

void CmdComponentSymbolVariantItemEdit::setSymbolUuid(
const Uuid& uuid) noexcept {
Q_ASSERT(!wasEverExecuted());
mNewSymbolUuid = uuid;
}

void CmdComponentSymbolVariantItemEdit::setSymbolPosition(
const Point& pos) noexcept {
Q_ASSERT(!wasEverExecuted());
mNewSymbolPos = pos;
}

void CmdComponentSymbolVariantItemEdit::setSymbolRotation(
const Angle& rot) noexcept {
Q_ASSERT(!wasEverExecuted());
mNewSymbolRot = rot;
}

void CmdComponentSymbolVariantItemEdit::setIsRequired(bool required) noexcept {
Q_ASSERT(!wasEverExecuted());
mNewIsRequired = required;
}

void CmdComponentSymbolVariantItemEdit::setSuffix(
const ComponentSymbolVariantItemSuffix& suffix) noexcept {
Q_ASSERT(!wasEverExecuted());
mNewSuffix = suffix;
}

void CmdComponentSymbolVariantItemEdit::setPinSignalMap(
const ComponentPinSignalMap& map) noexcept {
Q_ASSERT(!wasEverExecuted());
mNewPinSignalMap = map;
}

/*******************************************************************************
* Inherited from UndoCommand
******************************************************************************/

bool CmdComponentSymbolVariantItemEdit::performExecute() {
performRedo(); // can throw

if (mNewSymbolUuid != mOldSymbolUuid) return true;
if (mNewSymbolPos != mOldSymbolPos) return true;
if (mNewSymbolRot != mOldSymbolRot) return true;
if (mNewIsRequired != mOldIsRequired) return true;
if (mNewSuffix != mOldSuffix) return true;
if (mNewPinSignalMap != mOldPinSignalMap) return true;
return false;
}

void CmdComponentSymbolVariantItemEdit::performUndo() {
mItem.setSymbolUuid(mOldSymbolUuid);
mItem.setSymbolPosition(mOldSymbolPos);
mItem.setSymbolRotation(mOldSymbolRot);
mItem.setIsRequired(mOldIsRequired);
mItem.setSuffix(mOldSuffix);
mItem.getPinSignalMap() = mOldPinSignalMap;
}

void CmdComponentSymbolVariantItemEdit::performRedo() {
mItem.setSymbolUuid(mNewSymbolUuid);
mItem.setSymbolPosition(mNewSymbolPos);
mItem.setSymbolRotation(mNewSymbolRot);
mItem.setIsRequired(mNewIsRequired);
mItem.setSuffix(mNewSuffix);
mItem.getPinSignalMap() = mNewPinSignalMap;
}

/*******************************************************************************
* End of File
******************************************************************************/

} // namespace library
} // namespace librepcb
101 changes: 101 additions & 0 deletions libs/librepcb/library/cmp/cmd/cmdcomponentsymbolvariantitemedit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBREPCB_LIBRARY_CMDCOMPONENTSYMBOLVARIANTITEMEDIT_H
#define LIBREPCB_LIBRARY_CMDCOMPONENTSYMBOLVARIANTITEMEDIT_H

/*******************************************************************************
* Includes
******************************************************************************/
#include "../componentsymbolvariant.h"

#include <librepcb/common/undocommand.h>

#include <QtCore>

/*******************************************************************************
* Namespace / Forward Declarations
******************************************************************************/
namespace librepcb {
namespace library {

/*******************************************************************************
* Class CmdComponentSymbolVariantItemEdit
******************************************************************************/

/**
* @brief The CmdComponentSymbolVariantItemEdit class
*/
class CmdComponentSymbolVariantItemEdit final : public UndoCommand {
public:
// Constructors / Destructor
CmdComponentSymbolVariantItemEdit() = delete;
CmdComponentSymbolVariantItemEdit(
const CmdComponentSymbolVariantItemEdit& other) = delete;
explicit CmdComponentSymbolVariantItemEdit(
ComponentSymbolVariantItem& item) noexcept;
~CmdComponentSymbolVariantItemEdit() noexcept;

// Setters
void setSymbolUuid(const Uuid& uuid) noexcept;
void setSymbolPosition(const Point& pos) noexcept;
void setSymbolRotation(const Angle& rot) noexcept;
void setIsRequired(bool required) noexcept;
void setSuffix(const ComponentSymbolVariantItemSuffix& suffix) noexcept;
void setPinSignalMap(const ComponentPinSignalMap& map) noexcept;

// Operator Overloadings
CmdComponentSymbolVariantItemEdit& operator =(
const CmdComponentSymbolVariantItemEdit& rhs) = delete;

private: // Methods
/// @copydoc UndoCommand::performExecute()
bool performExecute() override;

/// @copydoc UndoCommand::performUndo()
void performUndo() override;

/// @copydoc UndoCommand::performRedo()
void performRedo() override;

private: // Data
ComponentSymbolVariantItem& mItem;

Uuid mOldSymbolUuid;
Uuid mNewSymbolUuid;
Point mOldSymbolPos;
Point mNewSymbolPos;
Angle mOldSymbolRot;
Angle mNewSymbolRot;
bool mOldIsRequired;
bool mNewIsRequired;
ComponentSymbolVariantItemSuffix mOldSuffix;
ComponentSymbolVariantItemSuffix mNewSuffix;
ComponentPinSignalMap mOldPinSignalMap;
ComponentPinSignalMap mNewPinSignalMap;
};

/*******************************************************************************
* End of File
******************************************************************************/

} // namespace library
} // namespace librepcb

#endif // LIBREPCB_LIBRARY_CMDCOMPONENTSYMBOLVARIANTITEMEDIT_H
Loading

0 comments on commit d44243c

Please sign in to comment.