| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2004 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#include <boost/algorithm/string.hpp> |
| 25 |
#include <qglobal.h> |
| 26 |
|
| 27 |
#include <App/Application.h> |
| 28 |
|
| 29 |
#include "Window.h" |
| 30 |
|
| 31 |
|
| 32 |
using namespace Gui; |
| 33 |
|
| 34 |
//************************************************************************** |
| 35 |
//************************************************************************** |
| 36 |
// WindowParameter |
| 37 |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 38 |
|
| 39 |
|
| 40 |
//************************************************************************** |
| 41 |
// Construction/Destruction |
| 42 |
|
| 43 |
WindowParameter::WindowParameter(const char* name) |
| 44 |
{ |
| 45 |
// not allowed to use a Window without a name, see the constructor |
| 46 |
// of a DockWindow or a other QT Widget |
| 47 |
assert(name); |
| 48 |
|
| 49 |
// if string is empty do not create group |
| 50 |
if (strcmp(name, "") != 0) { |
| 51 |
_handle = getDefaultParameter()->GetGroup(name); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
WindowParameter::~WindowParameter() |
| 56 |
{ |
| 57 |
connParamChanged.disconnect(); |
| 58 |
} |
| 59 |
|
| 60 |
/** Sets the group of the window to \a name */ |
| 61 |
bool WindowParameter::setGroupName(const char* name) |
| 62 |
{ |
| 63 |
// cannot change parameter group |
| 64 |
if (_handle.isValid()) { |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
assert(name); |
| 69 |
|
| 70 |
std::string prefGroup = name; |
| 71 |
const auto& list = App::GetApplication().GetParameterSetList(); |
| 72 |
|
| 73 |
auto found = std::find_if(list.begin(), list.end(), [prefGroup](auto item) { |
| 74 |
return boost::starts_with(prefGroup, item.first); |
| 75 |
}); |
| 76 |
|
| 77 |
if (found != list.end()) { |
| 78 |
_handle = App::GetApplication().GetParameterGroupByPath(name); |
| 79 |
} |
| 80 |
else { |
| 81 |
_handle = getDefaultParameter()->GetGroup(name); |
| 82 |
} |
| 83 |
|
| 84 |
return true; |
| 85 |
} |
| 86 |
|
| 87 |
void WindowParameter::OnChange(Base::Subject<const char*>& rCaller, const char* sReason) |
| 88 |
{ |
| 89 |
Q_UNUSED(rCaller); |
| 90 |
Q_UNUSED(sReason); |
| 91 |
} |
| 92 |
|
| 93 |
ParameterGrp::handle WindowParameter::getWindowParameter() |
| 94 |
{ |
| 95 |
return _handle; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Returns a handle to the parameter group to the user parameter |
| 100 |
* under BaseApp/Preferences. |
| 101 |
*/ |
| 102 |
ParameterGrp::handle WindowParameter::getDefaultParameter() |
| 103 |
{ |
| 104 |
return App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences"); |
| 105 |
} |