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

Schematic Editor: Add support for renaming sheets #640

Merged
merged 3 commits into from Dec 28, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -106,6 +106,7 @@ SOURCES += \
metadata/projectmetadata.cpp \
project.cpp \
schematics/cmd/cmdschematicadd.cpp \
schematics/cmd/cmdschematicedit.cpp \
schematics/cmd/cmdschematicnetlabeladd.cpp \
schematics/cmd/cmdschematicnetlabelanchorsupdate.cpp \
schematics/cmd/cmdschematicnetlabeledit.cpp \
@@ -227,6 +228,7 @@ HEADERS += \
metadata/projectmetadata.h \
project.h \
schematics/cmd/cmdschematicadd.h \
schematics/cmd/cmdschematicedit.h \
schematics/cmd/cmdschematicnetlabeladd.h \
schematics/cmd/cmdschematicnetlabelanchorsupdate.h \
schematics/cmd/cmdschematicnetlabeledit.h \
@@ -0,0 +1,82 @@
/*
* 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 "cmdschematicedit.h"

#include "../schematic.h"

#include <QtCore>

/*******************************************************************************
* Namespace
******************************************************************************/
namespace librepcb {
namespace project {

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

CmdSchematicEdit::CmdSchematicEdit(Schematic& schematic) noexcept
: UndoCommand(tr("Edit sheet properties")),
mSchematic(schematic),
mOldName(schematic.getName()),
mNewName(mOldName) {
}

CmdSchematicEdit::~CmdSchematicEdit() noexcept {
}

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

void CmdSchematicEdit::setName(const ElementName& name) noexcept {
Q_ASSERT(!wasEverExecuted());
mNewName = name;
}

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

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

if (mNewName != mOldName) return true;
return false;
}

void CmdSchematicEdit::performUndo() {
mSchematic.setName(mOldName);
}

void CmdSchematicEdit::performRedo() {
mSchematic.setName(mNewName);
}

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

} // namespace project
} // namespace librepcb
@@ -0,0 +1,84 @@
/*
* 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_PROJECT_CMDSCHEMATICEDIT_H
#define LIBREPCB_PROJECT_CMDSCHEMATICEDIT_H

/*******************************************************************************
* Includes
******************************************************************************/
#include <librepcb/common/elementname.h>
#include <librepcb/common/undocommand.h>

#include <QtCore>

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

class Schematic;

/*******************************************************************************
* Class CmdSchematicEdit
******************************************************************************/

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

// Setters
void setName(const ElementName& name) noexcept;

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

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

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

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

private: // Data
Schematic& mSchematic;

ElementName mOldName;
ElementName mNewName;
};

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

} // namespace project
} // namespace librepcb

#endif // LIBREPCB_PROJECT_CMDSCHEMATICEDIT_H
@@ -226,13 +226,18 @@ QList<SI_SymbolPin*> Schematic::getPinsAtScenePos(const Point& pos) const
}

/*******************************************************************************
* Setters: General
* Setters
******************************************************************************/

void Schematic::setGridProperties(const GridProperties& grid) noexcept {
*mGridProperties = grid;
}

void Schematic::setName(const ElementName& name) noexcept {
mName = name;
emit mProject.attributesChanged();
}

/*******************************************************************************
* Symbol Methods
******************************************************************************/
@@ -138,6 +138,9 @@ class Schematic final : public QObject,
const ElementName& getName() const noexcept { return mName; }
const QIcon& getIcon() const noexcept { return mIcon; }

// Setters: Attributes
void setName(const ElementName& name) noexcept;

// Symbol Methods
QList<SI_Symbol*> getSymbols() const noexcept { return mSymbols; }
SI_Symbol* getSymbolByUuid(const Uuid& uuid) const noexcept;
@@ -43,6 +43,8 @@
#include <librepcb/project/metadata/projectmetadata.h>
#include <librepcb/project/project.h>
#include <librepcb/project/schematics/cmd/cmdschematicadd.h>
#include <librepcb/project/schematics/cmd/cmdschematicedit.h>
#include <librepcb/project/schematics/cmd/cmdschematicremove.h>
#include <librepcb/project/schematics/schematic.h>
#include <librepcb/project/settings/projectsettings.h>
#include <librepcb/workspace/library/workspacelibrarydb.h>
@@ -86,7 +88,17 @@ SchematicEditor::SchematicEditor(ProjectEditor& projectEditor, Project& project)
setWindowTitle(QString("%1 - LibrePCB Schematic Editor").arg(filenameStr));

// Add Dock Widgets
mPagesDock = new SchematicPagesDock(mProject, *this);
mPagesDock = new SchematicPagesDock(mProject, this);
connect(this, &SchematicEditor::activeSchematicChanged, mPagesDock,
&SchematicPagesDock::setSelectedSchematic);
connect(mPagesDock, &SchematicPagesDock::selectedSchematicChanged, this,
&SchematicEditor::setActiveSchematicIndex);
connect(mPagesDock, &SchematicPagesDock::addSchematicTriggered, this,
&SchematicEditor::addSchematic);
connect(mPagesDock, &SchematicPagesDock::removeSchematicTriggered, this,
&SchematicEditor::removeSchematic);
connect(mPagesDock, &SchematicPagesDock::renameSchematicTriggered, this,
&SchematicEditor::renameSchematic);
addDockWidget(Qt::LeftDockWidgetArea, mPagesDock, Qt::Vertical);
mErcMsgDock = new ErcMsgDock(mProject);
addDockWidget(Qt::RightDockWidgetArea, mErcMsgDock, Qt::Vertical);
@@ -109,6 +121,8 @@ SchematicEditor::SchematicEditor(ProjectEditor& projectEditor, Project& project)
mUi->menuView->addAction(mErcMsgDock->toggleViewAction());

// connect some actions which are created with the Qt Designer
connect(mUi->actionNew_Schematic_Page, &QAction::triggered, this,
&SchematicEditor::addSchematic);
connect(mUi->actionSave_Project, &QAction::triggered, &mProjectEditor,
&ProjectEditor::saveProject);
connect(mUi->actionQuit, &QAction::triggered, this, &SchematicEditor::close);
@@ -282,8 +296,8 @@ bool SchematicEditor::setActiveSchematicIndex(int index) noexcept {
}

// schematic page has changed!
emit activeSchematicChanged(mActiveSchematicIndex, index);
mActiveSchematicIndex = index;
emit activeSchematicChanged(mActiveSchematicIndex);
return true;
}

@@ -317,20 +331,8 @@ void SchematicEditor::on_actionClose_Project_triggered() {
mProjectEditor.closeAndDestroy(true, this);
}

void SchematicEditor::on_actionNew_Schematic_Page_triggered() {
bool ok = false;
QString name = QInputDialog::getText(this, tr("Add schematic page"),
tr("Choose a name:"), QLineEdit::Normal,
tr("New Page"), &ok);
if (!ok) return;

try {
CmdSchematicAdd* cmd =
new CmdSchematicAdd(mProject, ElementName(name)); // can throw
mProjectEditor.getUndoStack().execCmd(cmd);
} catch (Exception& e) {
QMessageBox::critical(this, tr("Error"), e.getMsg());
}
void SchematicEditor::on_actionRenameSheet_triggered() {
renameSchematic(mActiveSchematicIndex);
}

void SchematicEditor::on_actionGrid_triggered() {
@@ -513,6 +515,54 @@ void SchematicEditor::toolActionGroupChangeTriggered(
}
}

void SchematicEditor::addSchematic() noexcept {
bool ok = false;
QString name = QInputDialog::getText(this, tr("Add schematic page"),
tr("Choose a name:"), QLineEdit::Normal,
tr("New Page"), &ok);
if (!ok) return;

try {
CmdSchematicAdd* cmd =
new CmdSchematicAdd(mProject, ElementName(name)); // can throw
mProjectEditor.getUndoStack().execCmd(cmd);
setActiveSchematicIndex(mProject.getSchematics().count() - 1);
} catch (Exception& e) {
QMessageBox::critical(this, tr("Error"), e.getMsg());
}
}

void SchematicEditor::removeSchematic(int index) noexcept {
Schematic* schematic = mProject.getSchematicByIndex(index);
if (!schematic) return;

try {
CmdSchematicRemove* cmd = new CmdSchematicRemove(mProject, *schematic);
mProjectEditor.getUndoStack().execCmd(cmd);
} catch (Exception& e) {
QMessageBox::critical(this, tr("Error"), e.getMsg());
}
}

void SchematicEditor::renameSchematic(int index) noexcept {
Schematic* schematic = mProject.getSchematicByIndex(index);
if (!schematic) return;

bool ok = false;
QString name =
QInputDialog::getText(this, tr("Rename sheet"), tr("Choose new name:"),
QLineEdit::Normal, *schematic->getName(), &ok);
if (!ok) return;

try {
QScopedPointer<CmdSchematicEdit> cmd(new CmdSchematicEdit(*schematic));
cmd->setName(ElementName(cleanElementName(name))); // can throw
mProjectEditor.getUndoStack().execCmd(cmd.take());
} catch (Exception& e) {
QMessageBox::critical(this, tr("Error"), e.getMsg());
}
}

/*******************************************************************************
* End of File
******************************************************************************/
@@ -92,7 +92,7 @@ private slots:

// Actions
void on_actionClose_Project_triggered();
void on_actionNew_Schematic_Page_triggered();
void on_actionRenameSheet_triggered();
void on_actionGrid_triggered();
void on_actionPrint_triggered();
void on_actionPDF_Export_triggered();
@@ -107,8 +107,7 @@ private slots:
void on_actionUpdateLibrary_triggered();

signals:

void activeSchematicChanged(int oldIndex, int newIndex);
void activeSchematicChanged(int index);

private:
// make some methods inaccessible...
@@ -119,6 +118,9 @@ private slots:
// Private Methods
bool graphicsViewEventHandler(QEvent* event);
void toolActionGroupChangeTriggered(const QVariant& newTool) noexcept;
void addSchematic() noexcept;
void removeSchematic(int index) noexcept;
void renameSchematic(int index) noexcept;

// General Attributes
ProjectEditor& mProjectEditor;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.