MCPcopy Create free account
hub / github.com/LibrePCB/LibrePCB / execNewBoardDialog

Method execNewBoardDialog

libs/librepcb/editor/project/projecteditor.cpp:634–679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

632}
633
634std::shared_ptr<BoardEditor> ProjectEditor::execNewBoardDialog(
635 std::optional<int> copyFromIndex) noexcept {
636 const Board* copyFrom =
637 copyFromIndex ? mProject->getBoardByIndex(*copyFromIndex) : nullptr;
638 if (copyFromIndex && (!copyFrom)) {
639 qWarning() << "ProjectEditor: Invalid board index to copy from.";
640 return nullptr;
641 }
642
643 QString name = tr("Board %1").arg(mProject->getBoards().count() + 1);
644 if (copyFrom) {
645 name = tr("Copy of %1").arg(*copyFrom->getName());
646 if (!ElementNameConstraint()(name)) {
647 name = QString("Copy of %1").arg(*copyFrom->getName());
648 }
649 }
650 if (!ElementNameConstraint()(name)) {
651 name = QString("Board %1").arg(mProject->getBoards().count() + 1);
652 }
653
654 bool ok = false;
655 name = QInputDialog::getText(
656 qApp->activeWindow(), copyFrom ? tr("Copy Board") : tr("Add New Board"),
657 tr("Choose a name:"), QLineEdit::Normal, name, &ok);
658 if (!ok) return nullptr;
659
660 emit abortBlockingToolsInOtherEditors(nullptr); // Release undo stack.
661
662 try {
663 const QString dirName = FilePath::cleanFileName(
664 name, FilePath::ReplaceSpaces | FilePath::ToLowerCase);
665 if (dirName.isEmpty()) {
666 throw RuntimeError(__FILE__, __LINE__,
667 tr("Invalid name: '%1'").arg(name));
668 }
669
670 const int index = mProject->getBoards().count();
671 CmdBoardAdd* cmd = new CmdBoardAdd(*mProject, dirName, ElementName(name),
672 copyFrom); // can throw
673 mUndoStack->execCmd(cmd);
674 return mBoards->value(index);
675 } catch (const Exception& e) {
676 QMessageBox::critical(qApp->activeWindow(), tr("Error"), e.getMsg());
677 return nullptr;
678 }
679}
680
681void ProjectEditor::execDeleteBoardDialog(int index) noexcept {
682 Board* board = mProject->getBoardByIndex(index);

Callers 2

triggerProjectMethod · 0.80
triggerBoardMethod · 0.80

Calls 10

QStringClass · 0.85
RuntimeErrorClass · 0.85
getBoardByIndexMethod · 0.80
getBoardsMethod · 0.80
countMethod · 0.45
getNameMethod · 0.45
isEmptyMethod · 0.45
execCmdMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected