#include "ParametersPlugin_Parameter.h"
#include "ParametersPlugin_Validators.h"
+#include <Events_InfoMessage.h>
+
#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
+#include <ModelAPI_Expression.h>
#include <ModuleBase_Tools.h>
#include <QTimer>
#include <QEvent>
#include <QKeyEvent>
+#include <QDialogButtonBox>
enum ColumnType {
Col_Name,
/////////////////////////////////////////////////////////////////////////////////////////////////
ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData)
- : ModuleBase_ModelWidget(theParent, theData)
+ : ModuleBase_ModelDialogWidget(theParent, theData)
{
QVBoxLayout* aLayout = new QVBoxLayout(this);
ParametersPlugin_ExpressionValidator aValidator;
std::list<std::string> aArgs;
std::string aAttrId = ParametersPlugin_Parameter::VARIABLE_ID();
- std::string aErr;
+ Events_InfoMessage aErr;
int aId = 0;
foreach(FeaturePtr aFeature, myParametersList) {
if (!aValidator.isValid(aFeature->attribute(aAttrId), aArgs, aErr)) {
- QMessageBox::warning(this, tr("Warning"), aErr.c_str());
+ // TODO(spo): translate
+ QMessageBox::warning(this, tr("Warning"), aErr.messageString().c_str());
selectItemScroll(myParameters->child(aId));
return false;
}
void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
{
- updateItem(myFeatures, featuresItems(myParametersList));
+ QList<FeaturePtr> aFeatureList;
+ updateItem(myFeatures, featuresItems(myParametersList, aFeatureList));
}
void ParametersPlugin_WidgetParamsMgr::updateParametersPart()
{
updateItem(myParameters, parametersItems(myParametersList));
- bool aIsValid = checkIsValid();
+ bool aIsValid = isValid();
enableButtons(aIsValid);
}
QList<QStringList> ParametersPlugin_WidgetParamsMgr::
- featuresItems(const QList<FeaturePtr>& theFeatures) const
+ featuresItems(const QList<FeaturePtr>& theFeatures, QList<FeaturePtr>& theFeatureList) const
{
QList<QStringList> aItemsList;
ResultParameterPtr aParam;
- QList<FeaturePtr> aFeatures;
foreach(FeaturePtr aParameter, theFeatures) {
aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParameter->firstResult());
const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
// Find referenced feature Recursive
QList<FeaturePtr> aList;
aList.append(aReferenced);
- QList<QStringList> aItems = featuresItems(aList);
+ QList<QStringList> aItems = featuresItems(aList, theFeatureList);
aItemsList.append(aItems);
} else {
- if (!aFeatures.contains(aReferenced)) {
+ if (!theFeatureList.contains(aReferenced)) {
QStringList aValNames;
aValNames << aReferenced->data()->name().c_str();
}
}
aItemsList.append(aValNames);
- aFeatures.append(aReferenced);
+ theFeatureList.append(aReferenced);
}
}
}
aText.replace(" ", "");
}
if (hasName(aText)) {
- myMessage = tr("Name %1 already exists.").arg(aText);
+ myMessage = tr("Name '%1' already exists.").arg(aText);
QTimer::singleShot(50, this, SLOT(sendWarning()));
return;
}
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
- if (aColumn == Col_Equation)
+ if (aColumn != Col_Comment)
updateParametersPart();
updateFeaturesPart();
+
+ onSelectionChanged();
}
void ParametersPlugin_WidgetParamsMgr::updateItem(QTreeWidgetItem* theItem,
QObjectPtrList anObjects;
anObjects.append(aCurFeature);
- std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
- ModuleBase_Tools::findReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures);
+ std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
+ std::set<FeaturePtr> aFeatures;
+ ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
+ ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
- bool doDeleteReferences = true;
- if (ModuleBase_Tools::isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures,
- aIndirectRefFeatures, this, doDeleteReferences)) {
-
- std::set<FeaturePtr> aFeaturesToDelete;
- if (doDeleteReferences) {
- aFeaturesToDelete = aDirectRefFeatures;
- aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
- }
- aDoc->removeFeature(aCurFeature);
- std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin(),
- aLast = aFeaturesToDelete.end();
- for (; anIt != aLast; anIt++) {
- FeaturePtr aFeature = (*anIt);
- DocumentPtr aDoc = aFeature->document();
- aDoc->removeFeature(aFeature);
- }
+ std::set<FeaturePtr> aFeatureRefsToDelete;
+ if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, this, aFeatureRefsToDelete)) {
+ if (!aFeatureRefsToDelete.empty())
+ aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
+ ModelAPI_Tools::removeFeatures(aFeatures, false);
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
void ParametersPlugin_WidgetParamsMgr::sendWarning()
{
QMessageBox::warning(this, tr("Warning"), myMessage);
+ QTreeWidgetItem* aItem = myTable->currentItem();
+ if (aItem)
+ myTable->editItem(aItem);
}
void ParametersPlugin_WidgetParamsMgr::onSelectionChanged()
{
- bool isValid = checkIsValid();
- if (isValid) {
- QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
+ QList<QTreeWidgetItem*> aItemsList = myTable->selectedItems();
+ bool aIsValid = isValid();
+ if (aIsValid) {
bool isParameter = false;
foreach(QTreeWidgetItem* aItem, aItemsList) {
if (aItem->parent() == myParameters) {
}
}
myInsertBtn->setEnabled(isParameter);
- myRemoveBtn->setEnabled(isParameter);
+ //myRemoveBtn->setEnabled(isParameter);
myUpBtn->setEnabled(isParameter);
myDownBtn->setEnabled(isParameter);
} else {
myInsertBtn->setEnabled(false);
- myRemoveBtn->setEnabled(false);
+ //myRemoveBtn->setEnabled(false);
myUpBtn->setEnabled(false);
myDownBtn->setEnabled(false);
}
+ myRemoveBtn->setEnabled(!aItemsList.isEmpty());
}
void ParametersPlugin_WidgetParamsMgr::enableButtons(bool theEnable)
myUpBtn->setEnabled(theEnable);
myDownBtn->setEnabled(theEnable);
}
+ myOkCancelBtn->button(QDialogButtonBox::Ok)->setEnabled(theEnable);
}
-bool ParametersPlugin_WidgetParamsMgr::checkIsValid()
+bool ParametersPlugin_WidgetParamsMgr::isValid()
{
QTreeWidgetItem* aItem;
bool aIsValid = true;
for(int i = 0; i < myParameters->childCount(); i++) {
aItem = myParameters->child(i);
- if ((aItem->text(Col_Name) == NoName) || (aItem->text(Col_Equation) == NoValue)) {
+ if ((aItem->text(Col_Name) == NoName) ||
+ (aItem->text(Col_Equation) == NoValue) ||
+ (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {
aIsValid = false;
break;
}