[TechDraw] Add new Insert Repetition Count command
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
# include <Mod/TechDraw/App/DrawViewPart.h>
|
||||
# include <Mod/TechDraw/App/Preferences.h>
|
||||
|
||||
#include "DlgTemplateField.h"
|
||||
#include "DrawGuiUtil.h"
|
||||
#include "TaskCustomizeFormat.h"
|
||||
#include "TaskSelectLineAttributes.h"
|
||||
@@ -99,20 +100,42 @@ namespace TechDrawGui {
|
||||
// TechDraw_ExtensionInsertDiameter
|
||||
//===========================================================================
|
||||
|
||||
void execInsertPrefixChar(Gui::Command* cmd, std::string prefixChar) {
|
||||
void execInsertPrefixChar(Gui::Command* cmd, std::string prefixFormat, const QAction *action = nullptr) {
|
||||
// insert a prefix character into the format specifier
|
||||
std::vector<Gui::SelectionObject> selection;
|
||||
if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("Command","TechDraw Insert Prefix"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string prefixText(prefixFormat);
|
||||
if (prefixFormat.find("%s") != std::string::npos) {
|
||||
DlgTemplateField ui;
|
||||
const int MAX_PREFIX_LENGTH = 31;
|
||||
|
||||
if (action) {
|
||||
if (action->objectName() == QString::fromUtf8("TechDraw_ExtensionInsertRepetition")) {
|
||||
ui.setFieldName(QT_TR_NOOP("Repeat Count"));
|
||||
}
|
||||
}
|
||||
|
||||
ui.setFieldLength(MAX_PREFIX_LENGTH);
|
||||
ui.setFieldContent("");
|
||||
if (ui.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
char prefixData[(MAX_PREFIX_LENGTH + 1)*4];
|
||||
snprintf(prefixData, sizeof(prefixData), prefixFormat.c_str(), ui.getFieldContent().toUtf8().constData());
|
||||
prefixText = prefixData;
|
||||
}
|
||||
|
||||
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Insert Prefix"));
|
||||
for (auto selected : selection) {
|
||||
auto object = selected.getObject();
|
||||
if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
|
||||
auto dim = static_cast<TechDraw::DrawViewDimension*>(selected.getObject());
|
||||
std::string formatSpec = dim->FormatSpec.getStrValue();
|
||||
formatSpec = prefixChar + formatSpec;
|
||||
formatSpec = prefixText + formatSpec;
|
||||
dim->FormatSpec.setValue(formatSpec);
|
||||
}
|
||||
}
|
||||
@@ -181,6 +204,40 @@ bool CmdTechDrawExtensionInsertSquare::isActive()
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// TechDraw_ExtensionInsertRepetition
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdTechDrawExtensionInsertRepetition)
|
||||
|
||||
CmdTechDrawExtensionInsertRepetition::CmdTechDrawExtensionInsertRepetition()
|
||||
: Command("TechDraw_ExtensionInsertRepetition")
|
||||
{
|
||||
sAppModule = "TechDraw";
|
||||
sGroup = QT_TR_NOOP("TechDraw");
|
||||
sMenuText = QT_TR_NOOP("Insert 'n×' Prefix");
|
||||
sToolTipText = QT_TR_NOOP("Insert repeated feature count at the beginning of the dimension text:<br>\
|
||||
- Select one or more dimensions<br>\
|
||||
- Click this tool");
|
||||
sWhatsThis = "TechDraw_ExtensionInsertRepetition";
|
||||
sStatusTip = sMenuText;
|
||||
sPixmap = "TechDraw_ExtensionInsertRepetition";
|
||||
}
|
||||
|
||||
void CmdTechDrawExtensionInsertRepetition::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
|
||||
execInsertPrefixChar(this, "%s× ", this->getAction()->action()); //× Multiplication sign U+00D7
|
||||
}
|
||||
|
||||
bool CmdTechDrawExtensionInsertRepetition::isActive()
|
||||
{
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// TechDraw_ExtensionRemovePrefixChar
|
||||
//===========================================================================
|
||||
@@ -277,7 +334,10 @@ void CmdTechDrawExtensionInsertPrefixGroup::activated(int iMsg)
|
||||
case 1: //insert "□" as prefix
|
||||
execInsertPrefixChar(this, "□");
|
||||
break;
|
||||
case 2: //remove prefix characters
|
||||
case 2: //insert "n×" as prefix
|
||||
execInsertPrefixChar(this, "%s× ", pcAction->actions().at(iMsg));
|
||||
break;
|
||||
case 3: //remove prefix characters
|
||||
execRemovePrefixChar(this);
|
||||
break;
|
||||
default:
|
||||
@@ -300,9 +360,13 @@ Gui::Action* CmdTechDrawExtensionInsertPrefixGroup::createAction()
|
||||
p2->setObjectName(QString::fromLatin1("TechDraw_ExtensionInsertSquare"));
|
||||
p2->setWhatsThis(QString::fromLatin1("TechDraw_ExtensionInsertSquare"));
|
||||
QAction* p3 = pcAction->addAction(QString());
|
||||
p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionRemovePrefixChar"));
|
||||
p3->setObjectName(QString::fromLatin1("TechDraw_ExtensionRemovePrefixChar"));
|
||||
p3->setWhatsThis(QString::fromLatin1("TechDraw_ExtensionRemovePrefixChar"));
|
||||
p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionInsertRepetition"));
|
||||
p3->setObjectName(QString::fromLatin1("TechDraw_ExtensionInsertRepetition"));
|
||||
p3->setWhatsThis(QString::fromLatin1("TechDraw_ExtensionInsertRepetition"));
|
||||
QAction* p4 = pcAction->addAction(QString());
|
||||
p4->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionRemovePrefixChar"));
|
||||
p4->setObjectName(QString::fromLatin1("TechDraw_ExtensionRemovePrefixChar"));
|
||||
p4->setWhatsThis(QString::fromLatin1("TechDraw_ExtensionRemovePrefixChar"));
|
||||
|
||||
_pcAction = pcAction;
|
||||
languageChange();
|
||||
@@ -338,12 +402,19 @@ void CmdTechDrawExtensionInsertPrefixGroup::languageChange()
|
||||
- Click this tool"));
|
||||
arc2->setStatusTip(arc2->text());
|
||||
QAction* arc3 = a[2];
|
||||
arc3->setText(QApplication::translate("TechDraw_ExtensionremovePrefixChar", "Remove Prefix"));
|
||||
arc3->setToolTip(QApplication::translate("TechDraw_ExtensionremovePrefixChar",
|
||||
"Remove prefix symbols at the beginning of the dimension text:<br>\
|
||||
arc3->setText(QApplication::translate("CmdTechDrawExtensionInsertRepetition", "Insert 'n×' Prefix"));
|
||||
arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionInsertRepetition",
|
||||
"Insert repeated feature count at the beginning of the dimension text:<br>\
|
||||
- Select one or more dimensions<br>\
|
||||
- Click this tool"));
|
||||
arc3->setStatusTip(arc3->text());
|
||||
QAction* arc4 = a[3];
|
||||
arc4->setText(QApplication::translate("TechDraw_ExtensionremovePrefixChar", "Remove Prefix"));
|
||||
arc4->setToolTip(QApplication::translate("TechDraw_ExtensionremovePrefixChar",
|
||||
"Remove prefix symbols at the beginning of the dimension text:<br>\
|
||||
- Select one or more dimensions<br>\
|
||||
- Click this tool"));
|
||||
arc4->setStatusTip(arc4->text());
|
||||
}
|
||||
|
||||
bool CmdTechDrawExtensionInsertPrefixGroup::isActive()
|
||||
@@ -2391,6 +2462,7 @@ void CreateTechDrawCommandsExtensionDims()
|
||||
rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertPrefixGroup());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertDiameter());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertSquare());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertRepetition());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawExtensionRemovePrefixChar());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawExtensionIncreaseDecreaseGroup());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawExtensionIncreaseDecimal());
|
||||
|
||||
@@ -51,6 +51,11 @@ void DlgTemplateField::setFieldName(std::string name)
|
||||
ui->lblName->setText(qs);
|
||||
}
|
||||
|
||||
void DlgTemplateField::setFieldLength(int length)
|
||||
{
|
||||
ui->leInput->setMaxLength(length);
|
||||
}
|
||||
|
||||
void DlgTemplateField::setFieldContent(std::string content)
|
||||
{
|
||||
QString qs = QString::fromUtf8(content.data(), content.size());
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
~DlgTemplateField() override = default;
|
||||
|
||||
void setFieldName(std::string name);
|
||||
void setFieldLength(int length);
|
||||
void setFieldContent(std::string content);
|
||||
QString getFieldContent();
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
<file>icons/TechDraw_ExtensionHoleCircle.svg</file>
|
||||
<file>icons/TechDraw_ExtensionIncreaseDecimal.svg</file>
|
||||
<file>icons/TechDraw_ExtensionInsertDiameter.svg</file>
|
||||
<file>icons/TechDraw_ExtensionInsertRepetition.svg</file>
|
||||
<file>icons/TechDraw_ExtensionInsertSquare.svg</file>
|
||||
<file>icons/TechDraw_ExtensionLineParallel.svg</file>
|
||||
<file>icons/TechDraw_ExtensionLinePerpendicular.svg</file>
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 3.8 KiB |
@@ -150,6 +150,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
*tooldimensions << "Separator";
|
||||
*tooldimensions << "TechDraw_ExtensionInsertDiameter";
|
||||
*tooldimensions << "TechDraw_ExtensionInsertSquare";
|
||||
*tooldimensions << "TechDraw_ExtensionInsertRepetition";
|
||||
*tooldimensions << "TechDraw_ExtensionRemovePrefixChar";
|
||||
*tooldimensions << "Separator";
|
||||
*tooldimensions << "TechDraw_ExtensionIncreaseDecimal";
|
||||
|
||||
Reference in New Issue
Block a user