Merge branch 'master' into sketcherMoveColorsToPrefs

This commit is contained in:
Chris Hennes
2021-10-11 12:31:08 -05:00
committed by GitHub
129 changed files with 7990 additions and 3614 deletions

View File

@@ -30,6 +30,7 @@
#include <Gui/Command.h>
#include <exception>
#include <type_traits>
#include <typeinfo>
#include <boost/format.hpp>
namespace Gui {
@@ -40,11 +41,24 @@ public:
static std::string str(const std::string& s) {
return s;
}
static std::string str(const char* s) {
return s;
}
static std::string str(const QString& s) {
return s.toStdString();
}
static std::string str(const std::stringstream& s) {
return s.str();
}
static std::string str(const std::ostringstream& s) {
return s.str();
}
static std::string str(const std::ostream& s) {
return dynamic_cast<const std::ostringstream&>(s).str();
if (typeid(s) == typeid(std::ostringstream))
return dynamic_cast<const std::ostringstream&>(s).str();
else if (typeid(s) == typeid(std::stringstream))
return dynamic_cast<const std::stringstream&>(s).str();
throw Base::TypeError("Not a std::stringstream or std::ostringstream");
}
static std::string toStr(boost::format& f) {
return f.str();
@@ -152,6 +166,39 @@ inline void cmdAppDocument(const App::DocumentObject* obj, T&& cmd) {
_cmdDocument(Gui::Command::Doc, obj, "App", std::forward<T>(cmd));
}
/** Runs a command for accessing a document's attribute or method
* @param doc: pointer to a Document
* @param cmd: command string, supporting printf like formatter
*
* Example:
* @code{.cpp}
* cmdAppDocumentArgs(obj, "addObject('%s')", "Part::Feature");
* @endcode
*
* Translates to command (assuming obj's document name is 'DocName':
* @code{.py}
* App.getDocument('DocName').addObject('Part::Feature')
* @endcode
*/
template<typename...Args>
void cmdAppDocumentArgs(const App::Document* doc, const std::string& cmd, Args&&... args) {
std::string _cmd;
try {
boost::format fmt(cmd);
_cmd = FormatString::toStr(fmt, std::forward<Args>(args)...);
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s",
doc->getName(), _cmd.c_str());
}
catch (const std::exception& e) {
Base::Console().Error("%s: %s\n", e.what(), cmd.c_str());
}
catch (const Base::Exception&) {
Base::Console().Error("App.getDocument('%s').%s\n",
doc->getName(), _cmd.c_str());
throw;
}
}
/** Runs a command for accessing an object's Gui::Document attribute or method
* This function is an alternative to FCMD_VOBJ_DOC_CMD
* @param obj: pointer to a DocumentObject

View File

@@ -2824,7 +2824,7 @@ static std::vector<std::string> getBoxSelection(
continue;
std::vector<Base::Vector3d> points;
std::vector<Data::ComplexGeoData::Line> lines;
data->getLinesFromSubelement(segment.get(),points,lines);
data->getLinesFromSubElement(segment.get(),points,lines);
if(lines.empty()) {
if(points.empty())
continue;

View File

@@ -633,24 +633,27 @@ bool MainWindow::closeAllDocuments (bool close)
auto docs = App::GetApplication().getDocuments();
try {
docs = App::Document::getDependentDocuments(docs, true);
}catch(Base::Exception &e) {
}
catch(Base::Exception &e) {
e.ReportException();
}
bool checkModify = true;
bool saveAll = false;
int failedSaves = 0;
for(auto doc : docs) {
for (auto doc : docs) {
auto gdoc = Application::Instance->getDocument(doc);
if(!gdoc)
if (!gdoc)
continue;
if(!gdoc->canClose(false))
if (!gdoc->canClose(false))
return false;
if(!gdoc->isModified()
if (!gdoc->isModified()
|| doc->testStatus(App::Document::PartialDoc)
|| doc->testStatus(App::Document::TempDoc))
continue;
bool save = saveAll;
if(!save && checkModify) {
if (!save && checkModify) {
int res = confirmSave(doc->Label.getStrValue().c_str(), this, docs.size()>1);
switch (res)
{
@@ -658,6 +661,7 @@ bool MainWindow::closeAllDocuments (bool close)
return false;
case ConfirmSaveResult::SaveAll:
saveAll = true;
/* FALLTHRU */
case ConfirmSaveResult::Save:
save = true;
break;
@@ -666,7 +670,7 @@ bool MainWindow::closeAllDocuments (bool close)
}
}
if(save && !gdoc->save())
if (save && !gdoc->save())
failedSaves++;
}
@@ -681,9 +685,9 @@ bool MainWindow::closeAllDocuments (bool close)
return false;
}
if(close)
if (close)
App::GetApplication().closeAllDocuments();
// d->mdiArea->closeAllSubWindows();
return true;
}

View File

@@ -505,14 +505,14 @@ void AboutDialog::showLibraryInformation()
// Coin3D
li.name = QLatin1String("Coin3D");
li.href = baseurl + QLatin1String("#_TocCoin3D");
li.url = QLatin1String("https://bitbucket.org/Coin3D/coin/");
li.url = QLatin1String("https://coin3d.github.io");
li.version = QLatin1String(COIN_VERSION);
libInfo << li;
// Eigen3
li.name = QLatin1String("Eigen3");
li.href = baseurl + QLatin1String("#_TocEigen3");
li.url = QLatin1String("http://eigen.tuxfamily.org/");
li.url = QLatin1String("http://eigen.tuxfamily.org");
li.version = QString::fromLatin1(FC_EIGEN3_VERSION);
libInfo << li;

View File

@@ -250,6 +250,11 @@ void ToolBarManager::setup(ToolBarItem* toolBarItems)
(*it)->hide();
(*it)->toggleViewAction()->setVisible(false);
}
hPref = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("General");
bool lockToolBars = hPref->GetBool("LockToolBars", false);
setMovable(!lockToolBars);
}
void ToolBarManager::setup(ToolBarItem* item, QToolBar* toolbar) const
@@ -314,6 +319,12 @@ void ToolBarManager::restoreState() const
toolbar->setVisible(hPref->GetBool(toolbarName.constData(), toolbar->isVisible()));
}
}
hPref = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("General");
bool lockToolBars = hPref->GetBool("LockToolBars", false);
setMovable(!lockToolBars);
}
void ToolBarManager::retranslate() const
@@ -327,6 +338,13 @@ void ToolBarManager::retranslate() const
}
}
void Gui::ToolBarManager::setMovable(bool moveable) const
{
for (auto& tb : toolBars()) {
tb->setMovable(moveable);
}
}
QToolBar* ToolBarManager::findToolBar(const QList<QToolBar*>& toolbars, const QString& item) const
{
for (QList<QToolBar*>::ConstIterator it = toolbars.begin(); it != toolbars.end(); ++it) {

View File

@@ -80,6 +80,8 @@ public:
void restoreState() const;
void retranslate() const;
void setMovable(bool movable) const;
protected:
void setup(ToolBarItem*, QToolBar*) const;
/** Returns a list of all currently existing toolbars. */

View File

@@ -26,6 +26,7 @@
# include <QAction>
# include <QColorDialog>
# include <QDesktopWidget>
# include <QDesktopServices>
# include <QDialogButtonBox>
# include <QDrag>
# include <QEventLoop>
@@ -594,6 +595,7 @@ struct ColorButtonP
bool allowChange;
bool autoChange;
bool drawFrame;
bool allowTransparency;
bool modal;
bool dirty;
@@ -602,6 +604,7 @@ struct ColorButtonP
, allowChange(true)
, autoChange(false)
, drawFrame(true)
, allowTransparency(false)
, modal(true)
, dirty(true)
{
@@ -671,6 +674,21 @@ bool ColorButton::drawFrame() const
return d->drawFrame;
}
void Gui::ColorButton::setAllowTransparency(bool allow)
{
d->allowTransparency = allow;
if (d->cd)
d->cd->setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel, allow);
}
bool Gui::ColorButton::allowTransparency() const
{
if (d->cd)
return d->cd->testOption(QColorDialog::ColorDialogOption::ShowAlphaChannel);
else
return d->allowTransparency;
}
void ColorButton::setModal(bool b)
{
d->modal = b;
@@ -763,6 +781,7 @@ void ColorButton::onChooseColor()
QColor currentColor = d->col;
QColorDialog cd(d->col, this);
cd.setOptions(QColorDialog::DontUseNativeDialog);
cd.setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel, d->allowTransparency);
if (d->autoChange) {
connect(&cd, SIGNAL(currentColorChanged(const QColor &)),
@@ -788,6 +807,7 @@ void ColorButton::onChooseColor()
d->old = d->col;
d->cd = new QColorDialog(d->col, this);
d->cd->setOptions(QColorDialog::DontUseNativeDialog);
d->cd->setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel, d->allowTransparency);
d->cd->setAttribute(Qt::WA_DeleteOnClose);
connect(d->cd, SIGNAL(rejected()),
this, SLOT(onRejected()));
@@ -812,16 +832,15 @@ void ColorButton::onRejected()
// ------------------------------------------------------------------------------
UrlLabel::UrlLabel(QWidget * parent, Qt::WindowFlags f)
: QLabel(parent, f)
UrlLabel::UrlLabel(QWidget* parent, Qt::WindowFlags f)
: QLabel(parent, f)
, _url (QStringLiteral("http://localhost"))
, _launchExternal(true)
{
_url = QString::fromLatin1("http://localhost");
setToolTip(this->_url);
if (qApp->styleSheet().isEmpty()) {
setStyleSheet(QString::fromLatin1("Gui--UrlLabel {color: #0000FF;text-decoration: underline;}"));
}
setToolTip(this->_url);
setCursor(Qt::PointingHandCursor);
if (qApp->styleSheet().isEmpty())
setStyleSheet(QStringLiteral("Gui--UrlLabel {color: #0000FF;text-decoration: underline;}"));
}
UrlLabel::~UrlLabel()
@@ -833,40 +852,10 @@ void Gui::UrlLabel::setLaunchExternal(bool l)
_launchExternal = l;
}
void UrlLabel::enterEvent ( QEvent * )
{
setCursor(Qt::PointingHandCursor);
}
void UrlLabel::leaveEvent ( QEvent * )
{
setCursor(Qt::ArrowCursor);
}
void UrlLabel::mouseReleaseEvent (QMouseEvent *)
void UrlLabel::mouseReleaseEvent(QMouseEvent*)
{
if (_launchExternal) {
// The webbrowser Python module allows to start the system browser in an OS-independent way
Base::PyGILStateLocker lock;
PyObject* module = PyImport_ImportModule("webbrowser");
if (module) {
// get the methods dictionary and search for the 'open' method
PyObject* dict = PyModule_GetDict(module);
PyObject* func = PyDict_GetItemString(dict, "open");
if (func) {
PyObject* args = Py_BuildValue("(s)", (const char*)this->_url.toLatin1());
#if PY_VERSION_HEX < 0x03090000
PyObject* result = PyEval_CallObject(func, args);
#else
PyObject* result = PyObject_CallObject(func, args);
#endif
// decrement the args and module reference
Py_XDECREF(result);
Py_DECREF(args);
Py_DECREF(module);
}
}
}
QDesktopServices::openUrl(this->_url);
else {
// Someone else will deal with it...
Q_EMIT linkClicked(_url);

View File

@@ -203,6 +203,7 @@ class GuiExport ColorButton : public QPushButton
Q_PROPERTY( QColor color READ color WRITE setColor )
Q_PROPERTY( bool allowChangeColor READ allowChangeColor WRITE setAllowChangeColor )
Q_PROPERTY( bool drawFrame READ drawFrame WRITE setDrawFrame )
Q_PROPERTY( bool allowTransparency READ allowTransparency WRITE setAllowTransparency)
public:
ColorButton(QWidget* parent = 0);
@@ -217,6 +218,9 @@ public:
void setDrawFrame(bool);
bool drawFrame() const;
void setAllowTransparency(bool);
bool allowTransparency() const;
void setModal(bool);
bool isModal() const;
@@ -272,8 +276,6 @@ public Q_SLOTS:
void setLaunchExternal(bool l);
protected:
void enterEvent ( QEvent * );
void leaveEvent ( QEvent * );
void mouseReleaseEvent ( QMouseEvent * );
private:

View File

@@ -562,7 +562,7 @@ void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
*item << "Separator" << "Std_SetAppearance" << "Std_ToggleVisibility"
<< "Std_ToggleSelectability" << "Std_TreeSelection"
<< "Std_RandomColor" << "Separator" << "Std_Delete"
<< "Std_SendToPythonConsole";
<< "Std_SendToPythonConsole" << "Std_TransformManip";
}
}
else if (strcmp(recipient,"Tree") == 0)