Gui: Move ComboLink from PartDesign to Gui.
This commit is contained in:
@@ -92,7 +92,7 @@ private:
|
||||
std::unique_ptr<Ui_TaskLinearPatternParameters> ui;
|
||||
QTimer* updateViewTimer = nullptr;
|
||||
|
||||
ComboLinks dirLinks;
|
||||
Gui::ComboLinks dirLinks;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
void getMirrorPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const;
|
||||
|
||||
private:
|
||||
ComboLinks planeLinks;
|
||||
Gui::ComboLinks planeLinks;
|
||||
std::unique_ptr<Ui_TaskMirroredParameters> ui;
|
||||
};
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ private:
|
||||
std::unique_ptr<Ui_TaskPolarPatternParameters> ui;
|
||||
QTimer* updateViewTimer = nullptr;
|
||||
|
||||
ComboLinks axesLinks;
|
||||
Gui::ComboLinks axesLinks;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -638,84 +638,3 @@ bool TaskDlgTransformedParameters::reject()
|
||||
|
||||
|
||||
#include "moc_TaskTransformedParameters.cpp"
|
||||
|
||||
|
||||
ComboLinks::ComboLinks(QComboBox& combo)
|
||||
: _combo(&combo)
|
||||
{
|
||||
_combo->clear();
|
||||
}
|
||||
|
||||
int ComboLinks::addLink(const App::PropertyLinkSub& lnk, QString const& itemText)
|
||||
{
|
||||
if (!_combo) {
|
||||
return 0;
|
||||
}
|
||||
_combo->addItem(itemText);
|
||||
this->linksInList.push_back(new App::PropertyLinkSub());
|
||||
App::PropertyLinkSub& newitem = *(linksInList[linksInList.size() - 1]);
|
||||
newitem.Paste(lnk);
|
||||
if (newitem.getValue() && !this->doc) {
|
||||
this->doc = newitem.getValue()->getDocument();
|
||||
}
|
||||
return linksInList.size() - 1;
|
||||
}
|
||||
|
||||
int ComboLinks::addLink(App::DocumentObject* linkObj,
|
||||
std::string const& linkSubname,
|
||||
QString const& itemText)
|
||||
{
|
||||
if (!_combo) {
|
||||
return 0;
|
||||
}
|
||||
_combo->addItem(itemText);
|
||||
this->linksInList.push_back(new App::PropertyLinkSub());
|
||||
App::PropertyLinkSub& newitem = *(linksInList[linksInList.size() - 1]);
|
||||
newitem.setValue(linkObj, std::vector<std::string>(1, linkSubname));
|
||||
if (newitem.getValue() && !this->doc) {
|
||||
this->doc = newitem.getValue()->getDocument();
|
||||
}
|
||||
return linksInList.size() - 1;
|
||||
}
|
||||
|
||||
void ComboLinks::clear()
|
||||
{
|
||||
for (size_t i = 0; i < this->linksInList.size(); i++) {
|
||||
delete linksInList[i];
|
||||
}
|
||||
if (this->_combo) {
|
||||
_combo->clear();
|
||||
}
|
||||
}
|
||||
|
||||
App::PropertyLinkSub& ComboLinks::getLink(int index) const
|
||||
{
|
||||
if (index < 0 || index > static_cast<int>(linksInList.size()) - 1) {
|
||||
throw Base::IndexError("ComboLinks::getLink:Index out of range");
|
||||
}
|
||||
if (linksInList[index]->getValue() && doc && !(doc->isIn(linksInList[index]->getValue()))) {
|
||||
throw Base::ValueError("Linked object is not in the document; it may have been deleted");
|
||||
}
|
||||
return *(linksInList[index]);
|
||||
}
|
||||
|
||||
App::PropertyLinkSub& ComboLinks::getCurrentLink() const
|
||||
{
|
||||
assert(_combo);
|
||||
return getLink(_combo->currentIndex());
|
||||
}
|
||||
|
||||
int ComboLinks::setCurrentLink(const App::PropertyLinkSub& lnk)
|
||||
{
|
||||
for (size_t i = 0; i < linksInList.size(); i++) {
|
||||
App::PropertyLinkSub& it = *(linksInList[i]);
|
||||
if (lnk.getValue() == it.getValue() && lnk.getSubValues() == it.getSubValues()) {
|
||||
bool wasBlocked = _combo->signalsBlocked();
|
||||
_combo->blockSignals(true);
|
||||
_combo->setCurrentIndex(i);
|
||||
_combo->blockSignals(wasBlocked);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
#ifndef GUI_TASKVIEW_TaskTransformedParameters_H
|
||||
#define GUI_TASKVIEW_TaskTransformedParameters_H
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
#include <Gui/ComboLinks.h>
|
||||
#include <Gui/DocumentObserver.h>
|
||||
#include <Gui/Selection/Selection.h>
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
@@ -55,78 +54,6 @@ namespace PartDesignGui
|
||||
|
||||
class TaskMultiTransformParameters;
|
||||
|
||||
/**
|
||||
* @brief The ComboLinks class is a helper class that binds to a combo box and
|
||||
* provides an interface to add links, retrieve links and select items by link
|
||||
* value
|
||||
*/
|
||||
class ComboLinks
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief ComboLinks constructor.
|
||||
* @param combo. It will be cleared as soon as it is bound. Don't add or
|
||||
* remove items from the combo directly, otherwise internal tracking list
|
||||
* will go out of sync, and crashes may result.
|
||||
*/
|
||||
explicit ComboLinks(QComboBox& combo);
|
||||
ComboLinks() = default;
|
||||
|
||||
void setCombo(QComboBox& combo)
|
||||
{
|
||||
assert(!_combo);
|
||||
this->_combo = &combo;
|
||||
_combo->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief addLink adds an item to the combo. Doesn't check for duplicates.
|
||||
* @param lnk can be a link to NULL, which is usually used for special item "Select Reference"
|
||||
* @param itemText
|
||||
* @return
|
||||
*/
|
||||
int addLink(const App::PropertyLinkSub& lnk, QString const& itemText);
|
||||
int addLink(App::DocumentObject* linkObj, std::string const& linkSubname, QString const& itemText);
|
||||
void clear();
|
||||
App::PropertyLinkSub& getLink(int index) const;
|
||||
|
||||
/**
|
||||
* @brief getCurrentLink
|
||||
* @return the link corresponding to the selected item. May be null link,
|
||||
* which is usually used to indicate a "Select reference..." special item.
|
||||
* Otherwise, the link is automatically tested for validity (oif an object
|
||||
* doesn't exist in the document, an exception will be thrown.)
|
||||
*/
|
||||
App::PropertyLinkSub& getCurrentLink() const;
|
||||
|
||||
/**
|
||||
* @brief setCurrentLink selects the item with the link that matches the
|
||||
* argument. If there is no such link in the list, -1 is returned and
|
||||
* selected item is not changed. Signals from combo are blocked in this
|
||||
* function.
|
||||
* @param lnk
|
||||
* @return the index of an item that was selected, -1 if link is not in the list yet.
|
||||
*/
|
||||
int setCurrentLink(const App::PropertyLinkSub& lnk);
|
||||
|
||||
QComboBox& combo() const
|
||||
{
|
||||
assert(_combo);
|
||||
return *_combo;
|
||||
}
|
||||
|
||||
~ComboLinks()
|
||||
{
|
||||
_combo = nullptr;
|
||||
clear();
|
||||
}
|
||||
|
||||
private:
|
||||
QComboBox* _combo = nullptr;
|
||||
App::Document* doc = nullptr;
|
||||
std::vector<App::PropertyLinkSub*> linksInList;
|
||||
};
|
||||
|
||||
/**
|
||||
The transformed subclasses will be used in two different modes:
|
||||
1. As a stand-alone feature
|
||||
|
||||
Reference in New Issue
Block a user