Gui: Move ComboLink from PartDesign to Gui.

This commit is contained in:
paddle
2025-07-09 09:29:11 +02:00
parent 1eb05317ee
commit 66e186f396
8 changed files with 401 additions and 158 deletions

View File

@@ -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;
}