SelectionGate: add capability to display why not allowed.

This commit is contained in:
DeepSOIC 2015-07-09 22:03:32 +03:00 committed by Stefan Tröger
parent 3df305cc4e
commit cc89deccbf
3 changed files with 1342 additions and 6 deletions

View File

@ -485,13 +485,21 @@ bool SelectionSingleton::setPreselect(const char* pDocName, const char* pObjectN
if (pObjectName) {
App::DocumentObject* pObject = pDoc->getObject(pObjectName);
if (!ActiveGate->allow(pDoc,pObject,pSubName)) {
snprintf(buf,512,"Not allowed: %s.%s.%s ",pDocName
,pObjectName
,pSubName
QString msg;
if (ActiveGate->notAllowedReason.length() > 0){
msg = QObject::tr(ActiveGate->notAllowedReason.c_str());
} else {
msg = QCoreApplication::translate("SelectionFilter","Not allowed:");
}
msg.append(
QObject::tr(" %1.%2.%3 ")
.arg(QString::fromAscii(pDocName))
.arg(QString::fromAscii(pObjectName))
.arg(QString::fromAscii(pSubName))
);
if (getMainWindow()) {
getMainWindow()->showMessage(QString::fromLatin1(buf),3000);
getMainWindow()->showMessage(msg,3000);
Gui::MDIView* mdi = Gui::Application::Instance->activeDocument()->getActiveView();
mdi->setOverrideCursor(QCursor(Qt::ForbiddenCursor));
}
@ -665,10 +673,17 @@ bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectN
if (ActiveGate) {
if (!ActiveGate->allow(temp.pDoc,temp.pObject,pSubName)) {
if (getMainWindow()) {
getMainWindow()->showMessage(QString::fromLatin1("Selection not allowed by filter"),5000);
QString msg;
if (ActiveGate->notAllowedReason.length() > 0) {
msg = QObject::tr(ActiveGate->notAllowedReason.c_str());
} else {
msg = QCoreApplication::translate("SelectionFilter","Selection not allowed by filter");
}
getMainWindow()->showMessage(msg,5000);
Gui::MDIView* mdi = Gui::Application::Instance->activeDocument()->getActiveView();
mdi->setOverrideCursor(Qt::ForbiddenCursor);
}
ActiveGate->notAllowedReason.clear();
QApplication::beep();
return false;
}

1313
src/Gui/Selection.cpp.orig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -178,6 +178,14 @@ class GuiExport SelectionGate
public:
virtual ~SelectionGate(){}
virtual bool allow(App::Document*,App::DocumentObject*, const char*)=0;
/**
* @brief notAllowedReason is a string that sets the message to be
* displayed in statusbar for cluing the user on why is the selection not
* allowed. Set this variable in allow() implementation. Enclose the
* literal into QT_TR_NOOP() for translatability.
*/
std::string notAllowedReason;
};