Skip to content

Commit

Permalink
+ support units in pocket panel
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jul 22, 2014
1 parent a5e2744 commit ea6c540
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
44 changes: 23 additions & 21 deletions src/Mod/PartDesign/Gui/TaskPocketParameters.cpp
Expand Up @@ -62,9 +62,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);

ui->doubleSpinBox->setDecimals(Base::UnitsApi::getDecimals());

connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
connect(ui->pocketLength, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
this, SLOT(onMidplaneChanged(bool)));
Expand All @@ -82,7 +80,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
this->groupLayout()->addWidget(proxy);

// Temporarily prevent unnecessary feature recomputes
ui->doubleSpinBox->blockSignals(true);
ui->pocketLength->blockSignals(true);
ui->checkBoxMidplane->blockSignals(true);
ui->checkBoxReversed->blockSignals(true);
ui->buttonFace->blockSignals(true);
Expand All @@ -105,9 +103,9 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
}

// Fill data into dialog elements
ui->doubleSpinBox->setMinimum(0);
ui->doubleSpinBox->setMaximum(INT_MAX);
ui->doubleSpinBox->setValue(l);
ui->pocketLength->setMinimum(0);
ui->pocketLength->setMaximum(INT_MAX);
ui->pocketLength->setValue(l);
ui->checkBoxMidplane->setChecked(midplane);
ui->checkBoxReversed->setChecked(reversed);
ui->lineFaceName->setText(faceId >= 0 ?
Expand All @@ -122,7 +120,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
ui->changeMode->setCurrentIndex(index);
ui->checkBoxMidplane->setChecked(midplane);

ui->doubleSpinBox->blockSignals(false);
ui->pocketLength->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
ui->buttonFace->blockSignals(false);
Expand All @@ -145,9 +143,9 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
void TaskPocketParameters::updateUI(int index)
{
if (index == 0) { // Only this option requires a numeric value // Dimension
ui->doubleSpinBox->setEnabled(true);
ui->doubleSpinBox->selectAll();
QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection);
ui->pocketLength->setEnabled(true);
ui->pocketLength->selectAll();
QMetaObject::invokeMethod(ui->pocketLength, "setFocus", Qt::QueuedConnection);
ui->checkBoxMidplane->setEnabled(true);
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked()); // Will flip direction of dimension
ui->buttonFace->setEnabled(false);
Expand All @@ -156,12 +154,12 @@ void TaskPocketParameters::updateUI(int index)
} else if (index == 1) { // Through all
ui->checkBoxMidplane->setEnabled(true);
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked()); // Will flip direction of through all
ui->doubleSpinBox->setEnabled(false);
ui->pocketLength->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 2) { // Neither value nor face required // To First
ui->doubleSpinBox->setEnabled(false);
ui->pocketLength->setEnabled(false);
ui->checkBoxMidplane->setEnabled(false); // Can't have a midplane to a single face
ui->checkBoxReversed->setEnabled(false); // Will change the direction it seeks for its first face?
// Doesnt work so is currently disabled. Fix probably lies
Expand All @@ -170,7 +168,7 @@ void TaskPocketParameters::updateUI(int index)
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 3) { // Only this option requires to select a face // Up to face
ui->doubleSpinBox->setEnabled(false);
ui->pocketLength->setEnabled(false);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false); // No need for reverse since user-chosen face will dtermine direction
ui->buttonFace->setEnabled(true);
Expand Down Expand Up @@ -263,7 +261,7 @@ void TaskPocketParameters::onModeChanged(int index)
if (oldLength < Precision::Confusion())
oldLength = 5.0;
pcPocket->Length.setValue(oldLength);
ui->doubleSpinBox->setValue(oldLength);
ui->pocketLength->setValue(oldLength);
break;
case 1:
oldLength = pcPocket->Length.getValue();
Expand All @@ -279,7 +277,7 @@ void TaskPocketParameters::onModeChanged(int index)
oldLength = pcPocket->Length.getValue();
pcPocket->Type.setValue("UpToFace");
pcPocket->Length.setValue(0.0);
ui->doubleSpinBox->setValue(0.0);
ui->pocketLength->setValue(0.0);
break;
default:
pcPocket->Type.setValue("Length");
Expand Down Expand Up @@ -360,7 +358,7 @@ void TaskPocketParameters::onUpdateView(bool on)

double TaskPocketParameters::getLength(void) const
{
return ui->doubleSpinBox->value();
return ui->pocketLength->value().getValue();
}

int TaskPocketParameters::getMode(void) const
Expand All @@ -387,7 +385,7 @@ void TaskPocketParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->doubleSpinBox->blockSignals(true);
ui->pocketLength->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
int index = ui->changeMode->currentIndex();
Expand All @@ -408,7 +406,7 @@ void TaskPocketParameters::changeEvent(QEvent *e)
ui->lineFaceName->setText(ok ?
tr("Face") + QString::number(faceId) :
tr("No face selected"));
ui->doubleSpinBox->blockSignals(false);
ui->pocketLength->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
}
Expand Down Expand Up @@ -438,12 +436,16 @@ TaskDlgPocketParameters::~TaskDlgPocketParameters()

void TaskDlgPocketParameters::open()
{

// a transaction is already open at creation time of the pad
if (!Gui::Command::hasPendingCommand()) {
QString msg = tr("Edit pocket");
Gui::Command::openCommand((const char*)msg.toUtf8());
}
}

void TaskDlgPocketParameters::clicked(int)
{

}

bool TaskDlgPocketParameters::accept()
Expand Down
16 changes: 13 additions & 3 deletions src/Mod/PartDesign/Gui/TaskPocketParameters.ui
Expand Up @@ -56,9 +56,12 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="maximum">
<double>999999999.000000000000000</double>
<widget class="Gui::QuantitySpinBox" name="pocketLength">
<property name="unit" stdset="0">
<string>mm</string>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -117,6 +120,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit ea6c540

Please sign in to comment.