@ -48,22 +48,26 @@ TQWeakPointer<UiGuiSettings> UiGuiSettings::_instance;
/*!
\ brief The constructor for the settings .
*/
UiGuiSettings : : UiGuiSettings ( ) : TQObject ( ) {
UiGuiSettings : : UiGuiSettings ( ) :
TQObject ( )
{
// Create the main application settings object from the UniversalIndentGUI.ini file.
_qsettings = new TQSettings ( SettingsPaths : : getSettingsPath ( ) + " /UniversalIndentGUI.ini " , TQSettings : : IniFormat , this ) ;
_qsettings = new TQSettings (
SettingsPaths : : getSettingsPath ( ) + " /UniversalIndentGUI.ini " , TQSettings : : IniFormat , this ) ;
_indenterDirctoryStr = SettingsPaths : : getGlobalFilesPath ( ) + " /indenters " ;
readAvailableTranslations ( ) ;
initSettings ( ) ;
}
/*!
\ brief Returns the instance of the settings class . If no instance exists , ONE will be created .
*/
TQSharedPointer < UiGuiSettings > UiGuiSettings : : getInstance ( ) {
TQSharedPointer < UiGuiSettings > UiGuiSettings : : getInstance ( )
{
TQSharedPointer < UiGuiSettings > sharedInstance = _instance . toStrongRef ( ) ;
if ( sharedInstance . isNull ( ) ) {
if ( sharedInstance . isNull ( ) )
{
// Create the settings object, which loads all UiGui settings from a file.
sharedInstance = TQSharedPointer < UiGuiSettings > ( new UiGuiSettings ( ) ) ;
_instance = sharedInstance . toWeakRef ( ) ;
@ -72,29 +76,32 @@ TQSharedPointer<UiGuiSettings> UiGuiSettings::getInstance() {
return sharedInstance ;
}
/*!
\ brief The destructor saves the settings to a file .
*/
UiGuiSettings : : ~ UiGuiSettings ( ) {
UiGuiSettings : : ~ UiGuiSettings ( )
{
// Convert the language setting from an integer index to a string.
int index = _qsettings - > value ( " UniversalIndentGUI/language " , 0 ) . toInt ( ) ;
if ( index < 0 | | index > = _availableTranslations . size ( ) )
{
index = 0 ;
}
_qsettings - > setValue ( " UniversalIndentGUI/language " , _availableTranslations . at ( index ) ) ;
}
/*!
\ brief Scans the translations directory for available translation files and
stores them in the TQList \ a _availableTranslations .
*/
void UiGuiSettings : : readAvailableTranslations ( ) {
void UiGuiSettings : : readAvailableTranslations ( )
{
TQString languageShort ;
TQStringList languageFileList ;
// English is the default language. A translation file does not exist but to have a menu entry, added here.
// English is the default language. A translation file does not exist but to have a menu entry,
// added here.
languageFileList < < " universalindent_en.qm " ;
// Find all translation files in the "translations" directory.
@ -102,7 +109,8 @@ void UiGuiSettings::readAvailableTranslations() {
languageFileList < < translationDirectory . entryList ( TQStringList ( " universalindent_*.qm " ) ) ;
// Loop for each found translation file
foreach ( languageShort , languageFileList ) {
foreach ( languageShort , languageFileList )
{
// Remove the leading string "universalindent_" from the filename.
languageShort . remove ( 0 , 16 ) ;
// Remove trailing file extension ".qm".
@ -112,25 +120,24 @@ void UiGuiSettings::readAvailableTranslations() {
}
}
/*!
\ brief Returns a list of the mnemonics of the available translations .
*/
TQStringList UiGuiSettings : : getAvailableTranslations ( ) {
TQStringList UiGuiSettings : : getAvailableTranslations ( )
{
return _availableTranslations ;
}
/*!
\ brief Returns the value of the by \ a settingsName defined setting as TQVariant .
If the named setting does not exist , 0 is being returned .
*/
TQVariant UiGuiSettings : : getValueByName ( TQString settingName ) {
TQVariant UiGuiSettings : : getValueByName ( TQString settingName )
{
return _qsettings - > value ( " UniversalIndentGUI/ " + settingName ) ;
}
/*!
\ brief Loads the settings for the main application .
@ -139,103 +146,136 @@ TQVariant UiGuiSettings::getValueByName(TQString settingName) {
bool UiGuiSettings : : initSettings ( )
{
// Read the version string saved in the settings file.
_qsettings - > setValue ( " UniversalIndentGUI/version " , _qsettings - > value ( " UniversalIndentGUI/version " , " " ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/version " ,
_qsettings - > value ( " UniversalIndentGUI/version " , " " ) ) ;
// Read windows last size and position from the settings file.
_qsettings - > setValue ( " UniversalIndentGUI/maximized " , _qsettings - > value ( " UniversalIndentGUI/maximized " , false ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/position " , _qsettings - > value ( " UniversalIndentGUI/position " , TQPoint ( 50 , 50 ) ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/size " , _qsettings - > value ( " UniversalIndentGUI/size " , TQSize ( 800 , 600 ) ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/maximized " ,
_qsettings - > value ( " UniversalIndentGUI/maximized " , false ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/position " ,
_qsettings - > value ( " UniversalIndentGUI/position " , TQPoint ( 50 , 50 ) ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/size " ,
_qsettings - > value ( " UniversalIndentGUI/size " , TQSize ( 800 , 600 ) ) ) ;
// Read last selected encoding for the opened source code file.
_qsettings - > setValue ( " UniversalIndentGUI/encoding " , _qsettings - > value ( " UniversalIndentGUI/encoding " , " UTF-8 " ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/encoding " ,
_qsettings - > value ( " UniversalIndentGUI/encoding " , " UTF-8 " ) ) ;
// Read maximum length of list for recently opened files.
_qsettings - > setValue ( " UniversalIndentGUI/recentlyOpenedListSize " , _qsettings - > value ( " UniversalIndentGUI/recentlyOpenedListSize " , 5 ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/recentlyOpenedListSize " ,
_qsettings - > value ( " UniversalIndentGUI/recentlyOpenedListSize " , 5 ) ) ;
// Read if last opened source code file should be loaded on startup.
_qsettings - > setValue ( " UniversalIndentGUI/loadLastSourceCodeFileOnStartup " , _qsettings - > value ( " UniversalIndentGUI/loadLastSourceCodeFileOnStartup " , true ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/loadLastSourceCodeFileOnStartup " ,
_qsettings - > value ( " UniversalIndentGUI/loadLastSourceCodeFileOnStartup " , true ) ) ;
// Read last opened source code file from the settings file.
_qsettings - > setValue ( " UniversalIndentGUI/lastSourceCodeFile " , _qsettings - > value ( " UniversalIndentGUI/lastSourceCodeFile " , _indenterDirctoryStr + " /example.cpp " ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/lastSourceCodeFile " ,
_qsettings - > value ( " UniversalIndentGUI/lastSourceCodeFile " ,
_indenterDirctoryStr + " /example.cpp " ) ) ;
// Read last selected indenter from the settings file.
int selectedIndenter = _qsettings - > value ( " UniversalIndentGUI/selectedIndenter " , 0 ) . toInt ( ) ;
if ( selectedIndenter < 0 ) {
if ( selectedIndenter < 0 )
{
selectedIndenter = 0 ;
}
_qsettings - > setValue ( " UniversalIndentGUI/selectedIndenter " , selectedIndenter ) ;
// Read if syntax highlighting is enabled.
_qsettings - > setValue ( " UniversalIndentGUI/SyntaxHighlightingEnabled " , _qsettings - > value ( " UniversalIndentGUI/SyntaxHighlightingEnabled " , true ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/SyntaxHighlightingEnabled " ,
_qsettings - > value ( " UniversalIndentGUI/SyntaxHighlightingEnabled " , true ) ) ;
// Read if white space characters should be displayed.
_qsettings - > setValue ( " UniversalIndentGUI/whiteSpaceIsVisible " , _qsettings - > value ( " UniversalIndentGUI/whiteSpaceIsVisible " , false ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/whiteSpaceIsVisible " ,
_qsettings - > value ( " UniversalIndentGUI/whiteSpaceIsVisible " , false ) ) ;
// Read if indenter parameter tool tips are enabled.
_qsettings - > setValue ( " UniversalIndentGUI/indenterParameterTooltipsEnabled " , _qsettings - > value ( " UniversalIndentGUI/indenterParameterTooltipsEnabled " , true ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/indenterParameterTooltipsEnabled " ,
_qsettings - > value ( " UniversalIndentGUI/indenterParameterTooltipsEnabled " , true ) ) ;
// Read the tab width from the settings file.
_qsettings - > setValue ( " UniversalIndentGUI/tabWidth " , _qsettings - > value ( " UniversalIndentGUI/tabWidth " , 4 ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/tabWidth " ,
_qsettings - > value ( " UniversalIndentGUI/tabWidth " , 4 ) ) ;
// Read the last selected language and stores the index it has in the list of available translations.
_qsettings - > setValue ( " UniversalIndentGUI/language " , _availableTranslations . indexOf ( _qsettings - > value ( " UniversalIndentGUI/language " , " " ) . toString ( ) ) ) ;
// Read the last selected language and stores the index it has in the list of available
// translations.
_qsettings - > setValue ( " UniversalIndentGUI/language " ,
_availableTranslations . indexOf ( _qsettings - > value ( " UniversalIndentGUI/language " ,
" " ) . toString ( ) ) ) ;
// Read the update check settings from the settings file.
_qsettings - > setValue ( " UniversalIndentGUI/CheckForUpdate " , _qsettings - > value ( " UniversalIndentGUI/CheckForUpdate " , false ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/LastUpdateCheck " , _qsettings - > value ( " UniversalIndentGUI/LastUpdateCheck " , TQDate ( 1900 , 1 , 1 ) ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/CheckForUpdate " ,
_qsettings - > value ( " UniversalIndentGUI/CheckForUpdate " , false ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/LastUpdateCheck " ,
_qsettings - > value ( " UniversalIndentGUI/LastUpdateCheck " , TQDate ( 1900 , 1 , 1 ) ) ) ;
// Read the main window state.
_qsettings - > setValue ( " UniversalIndentGUI/MainWindowState " , _qsettings - > value ( " UniversalIndentGUI/MainWindowState " , TQByteArray ( ) ) ) ;
_qsettings - > setValue ( " UniversalIndentGUI/MainWindowState " ,
_qsettings - > value ( " UniversalIndentGUI/MainWindowState " , TQByteArray ( ) ) ) ;
return true ;
}
/*!
\ brief Register the by \ a propertyName defined property of \ a obj to be connected to the setting defined by \ a settingName .
The \ a propertyName must be one of those that are listed in the TQt " Properties " documentation section of a TQt Object .
All further needed info is retrieved via the \ a obj ' s MetaObject , like the to the property bound signal .
*/
bool UiGuiSettings : : registerObjectProperty ( TQObject * obj , const TQString & propertyName , const TQString & settingName )
bool UiGuiSettings : : registerObjectProperty ( TQObject * obj , const TQString & propertyName ,
const TQString & settingName )
{
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
bool connectSuccess = false ;
// Connect to the objects destroyed signal, so that it will be correctly unregistered.
connectSuccess = connect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this , SLOT ( unregisterObjectProperty ( TQObject * ) ) ) ;
connectSuccess =
connect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this ,
SLOT ( unregisterObjectProperty ( TQObject * ) ) ) ;
int indexOfProp = metaObject - > indexOfProperty ( qPrintable ( propertyName ) ) ;
if ( connectSuccess & & indexOfProp > - 1 ) {
if ( connectSuccess & & indexOfProp > - 1 )
{
TQMetaProperty mProp = metaObject - > property ( indexOfProp ) ;
// Connect to the property's value changed signal.
if ( mProp . hasNotifySignal ( ) ) {
if ( mProp . hasNotifySignal ( ) )
{
TQMetaMethod signal = mProp . notifySignal ( ) ;
//TQString teststr = qPrintable(SIGNAL() + TQString(signal.signature()));
// The command "SIGNAL() + TQString(signal.signature())" assembles the signal methods signature to a valid TQt SIGNAL.
connectSuccess = connect ( obj , qPrintable ( SIGNAL ( ) + TQString ( signal . signature ( ) ) ) , this , SLOT ( handleObjectPropertyChange ( ) ) ) ;
// The command "SIGNAL() + TQString(signal.signature())" assembles the signal methods
// signature to a valid TQt SIGNAL.
connectSuccess =
connect ( obj , qPrintable ( SIGNAL ( ) + TQString ( signal . signature ( ) ) ) , this ,
SLOT ( handleObjectPropertyChange ( ) ) ) ;
}
if ( connectSuccess ) {
if ( connectSuccess )
{
_registeredObjectProperties [ obj ] = TQStringList ( ) < < propertyName < < settingName ;
}
else {
else
{
//TODO: Write a debug warning to the log.
disconnect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this , SLOT ( unregisterObjectProperty ( TQObject * ) ) ) ;
disconnect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this ,
SLOT ( unregisterObjectProperty ( TQObject * ) ) ) ;
return false ;
}
// If setting already exists, set the objects property to the setting value.
if ( _qsettings - > contains ( " UniversalIndentGUI/ " + settingName ) ) {
if ( _qsettings - > contains ( " UniversalIndentGUI/ " + settingName ) )
{
mProp . write ( obj , _qsettings - > value ( " UniversalIndentGUI/ " + settingName ) ) ;
}
// Otherwise add the setting and set it to the value of the objects property.
else {
else
{
_qsettings - > setValue ( " UniversalIndentGUI/ " + settingName , mProp . read ( obj ) ) ;
}
}
else {
else
{
//TODO: Write a debug warning to the log.
disconnect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this , SLOT ( unregisterObjectProperty ( TQObject * ) ) ) ;
return false ;
@ -244,7 +284,6 @@ bool UiGuiSettings::registerObjectProperty( TQObject *obj, const TQString &prope
return true ;
}
/*!
\ brief Searches the child TQObjects of \ a obj for a property name and setting name definition within
their custom properties and registers this property name to that setting name if both were found .
@ -257,36 +296,41 @@ bool UiGuiSettings::registerObjectProperty( TQObject *obj, const TQString &prope
Returns true , if all found property and setting definitions could be successfully registered .
Returns false , if any of those registrations fails .
*/
bool UiGuiSettings : : registerObjectPropertyRecursive ( TQObject * obj ) {
bool UiGuiSettings : : registerObjectPropertyRecursive ( TQObject * obj )
{
return checkCustomPropertiesAndCallFunction ( obj , & UiGuiSettings : : registerObjectProperty ) ;
}
/*!
\ brief Assigns the by \ a settingName defined setting value to the by \ a propertyName defined property of \ a obj .
Returns true , if the value could be assigned , otherwise returns false , which is the case if settingName doesn ' t exist
within the settings or if the mentioned propertyName wasn ' t found for the \ a obj .
*/
bool UiGuiSettings : : setObjectPropertyToSettingValue ( TQObject * obj , const TQString & propertyName , const TQString & settingName )
bool UiGuiSettings : : setObjectPropertyToSettingValue ( TQObject * obj , const TQString & propertyName ,
const TQString & settingName )
{
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
int indexOfProp = metaObject - > indexOfProperty ( qPrintable ( propertyName ) ) ;
if ( indexOfProp > - 1 ) {
if ( indexOfProp > - 1 )
{
TQMetaProperty mProp = metaObject - > property ( indexOfProp ) ;
// If setting already exists, set the objects property to the setting value.
if ( _qsettings - > contains ( " UniversalIndentGUI/ " + settingName ) ) {
if ( _qsettings - > contains ( " UniversalIndentGUI/ " + settingName ) )
{
mProp . write ( obj , _qsettings - > value ( " UniversalIndentGUI/ " + settingName ) ) ;
}
// The setting didn't exist so return that setting the objects property failed.
else {
else
{
//TODO: Write a debug warning to the log.
return false ;
}
}
else {
else
{
//TODO: Write a debug warning to the log.
return false ;
}
@ -294,7 +338,6 @@ bool UiGuiSettings::setObjectPropertyToSettingValue( TQObject *obj, const TQStri
return true ;
}
/*!
\ brief Searches the child TQObjects of \ a obj for a property name and setting name definition within
their custom properties and sets each property to settings value .
@ -306,11 +349,11 @@ bool UiGuiSettings::setObjectPropertyToSettingValue( TQObject *obj, const TQStri
Returns true , if all found property and setting definitions could be successfully registered .
Returns false , if any of those registrations fails .
*/
bool UiGuiSettings : : setObjectPropertyToSettingValueRecursive ( TQObject * obj ) {
bool UiGuiSettings : : setObjectPropertyToSettingValueRecursive ( TQObject * obj )
{
return checkCustomPropertiesAndCallFunction ( obj , & UiGuiSettings : : setObjectPropertyToSettingValue ) ;
}
/*!
\ brief Assigns the by \ a propertyName defined property ' s value of \ a obj to the by \ a settingName defined setting .
@ -319,17 +362,20 @@ bool UiGuiSettings::setObjectPropertyToSettingValueRecursive(TQObject *obj) {
Returns true , if the value could be assigned , otherwise returns false , which is the case if the mentioned
propertyName wasn ' t found for the \ a obj .
*/
bool UiGuiSettings : : setSettingToObjectPropertyValue ( TQObject * obj , const TQString & propertyName , const TQString & settingName )
bool UiGuiSettings : : setSettingToObjectPropertyValue ( TQObject * obj , const TQString & propertyName ,
const TQString & settingName )
{
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
int indexOfProp = metaObject - > indexOfProperty ( qPrintable ( propertyName ) ) ;
if ( indexOfProp > - 1 ) {
if ( indexOfProp > - 1 )
{
TQMetaProperty mProp = metaObject - > property ( indexOfProp ) ;
setValueByName ( settingName , mProp . read ( obj ) ) ;
}
else {
else
{
//TODO: Write a debug warning to the log.
return false ;
}
@ -337,7 +383,6 @@ bool UiGuiSettings::setSettingToObjectPropertyValue( TQObject *obj, const TQStri
return true ;
}
/*!
\ brief Searches the child TQObjects of \ a obj for a property name and setting name definition within
their custom properties and sets each setting to the property value .
@ -350,27 +395,32 @@ bool UiGuiSettings::setSettingToObjectPropertyValue( TQObject *obj, const TQStri
Returns true , if all found property and setting definitions could be successfully registered .
Returns false , if any of those registrations fails .
*/
bool UiGuiSettings : : setSettingToObjectPropertyValueRecursive ( TQObject * obj ) {
bool UiGuiSettings : : setSettingToObjectPropertyValueRecursive ( TQObject * obj )
{
return checkCustomPropertiesAndCallFunction ( obj , & UiGuiSettings : : setSettingToObjectPropertyValue ) ;
}
/*!
\ brief Iterates over all \ a objs child TQObjects and checks whether they have the custom properties
" connectedPropertyName " and " connectedSettingName " set . If both are set , it invokes the \ a callBackFunc
with both .
*/
bool UiGuiSettings : : checkCustomPropertiesAndCallFunction ( TQObject * obj , bool ( UiGuiSettings : : * callBackFunc ) ( TQObject * obj , const TQString & propertyName , const TQString & settingName ) ) {
bool UiGuiSettings : : checkCustomPropertiesAndCallFunction ( TQObject * obj , bool ( UiGuiSettings : : * callBackFunc ) (
TQObject * obj , const TQString & propertyName ,
const TQString & settingName ) )
{
bool success = true ;
// Find all widgets that have PropertyName and SettingName defined in their style sheet.
TQList < TQObject * > allObjects = obj - > findChildren < TQObject * > ( ) ;
foreach ( TQObject * object , allObjects ) {
foreach ( TQObject * object , allObjects )
{
TQString propertyName = object - > property ( " connectedPropertyName " ) . toString ( ) ;
TQString settingName = object - > property ( " connectedSettingName " ) . toString ( ) ;
// If property and setting name were found, register that widget with the settings.
if ( ! propertyName . isEmpty ( ) & & ! settingName . isEmpty ( ) ) {
if ( ! propertyName . isEmpty ( ) & & ! settingName . isEmpty ( ) )
{
success & = ( this - > * callBackFunc ) ( object , propertyName , settingName ) ;
}
}
@ -378,33 +428,37 @@ bool UiGuiSettings::checkCustomPropertiesAndCallFunction(TQObject *obj, bool (Ui
return success ;
}
/*!
\ brief The with a certain property registered \ a obj gets unregistered .
*/
void UiGuiSettings : : unregisterObjectProperty ( TQObject * obj ) {
if ( _registeredObjectProperties . contains ( obj ) ) {
void UiGuiSettings : : unregisterObjectProperty ( TQObject * obj )
{
if ( _registeredObjectProperties . contains ( obj ) )
{
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
TQString propertyName = _registeredObjectProperties [ obj ] . first ( ) ;
TQString settingName = _registeredObjectProperties [ obj ] . last ( ) ;
bool connectSuccess = false ;
int indexOfProp = metaObject - > indexOfProperty ( qPrintable ( propertyName ) ) ;
if ( indexOfProp > - 1 ) {
if ( indexOfProp > - 1 )
{
TQMetaProperty mProp = metaObject - > property ( indexOfProp ) ;
// Disconnect to the property's value changed signal.
if ( mProp . hasNotifySignal ( ) ) {
if ( mProp . hasNotifySignal ( ) )
{
TQMetaMethod signal = mProp . notifySignal ( ) ;
// The command "SIGNAL() + TQString(signal.signature())" assembles the signal methods signature to a valid TQt SIGNAL.
connectSuccess = disconnect ( obj , qPrintable ( SIGNAL ( ) + TQString ( signal . signature ( ) ) ) , this , SLOT ( handleObjectPropertyChange ( ) ) ) ;
// The command "SIGNAL() + TQString(signal.signature())" assembles the signal methods
// signature to a valid TQt SIGNAL.
connectSuccess = disconnect ( obj , qPrintable ( SIGNAL ( ) + TQString (
signal . signature ( ) ) ) , this , SLOT ( handleObjectPropertyChange ( ) ) ) ;
}
}
_registeredObjectProperties . remove ( obj ) ;
}
}
/*!
\ brief Registers a slot form the \ a obj by its \ a slotName to be invoked , if the by \ a settingName defined
setting changes .
@ -413,33 +467,39 @@ void UiGuiSettings::unregisterObjectProperty(TQObject *obj) {
\ a settingName changes the slot gets tried to be invoked with the settings value as parameter . This only works ,
if the slot parameter is of the same type as the setting .
*/
bool UiGuiSettings : : registerObjectSlot ( TQObject * obj , const TQString & slotName , const TQString & settingName ) {
bool UiGuiSettings : : registerObjectSlot ( TQObject * obj , const TQString & slotName ,
const TQString & settingName )
{
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
bool connectSuccess = false ;
// Connect to the objects destroyed signal, so that it will be correctly unregistered.
connectSuccess = connect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this , SLOT ( unregisterObjectSlot ( TQObject * ) ) ) ;
connectSuccess =
connect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this , SLOT ( unregisterObjectSlot ( TQObject * ) ) ) ;
TQString normalizedSlotName = TQMetaObject : : normalizedSignature ( qPrintable ( slotName ) ) ;
int indexOfMethod = metaObject - > indexOfMethod ( qPrintable ( normalizedSlotName ) ) ;
if ( connectSuccess & & indexOfMethod > - 1 ) {
if ( connectSuccess & & indexOfMethod > - 1 )
{
TQMetaMethod mMethod = metaObject - > method ( indexOfMethod ) ;
//TQMetaMethod::Access access = mMethod.access();
//TQMetaMethod::MethodType methType = mMethod.methodType();
// Since the method can at maximum be invoked with the setting value as argument,
// only methods taking max one argument are allowed.
if ( mMethod . parameterTypes ( ) . size ( ) < = 1 ) {
if ( mMethod . parameterTypes ( ) . size ( ) < = 1 )
{
_registeredObjectSlots . insert ( obj , TQStringList ( ) < < normalizedSlotName < < settingName ) ;
}
else {
else
{
//TODO: Write a debug warning to the log.
disconnect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this , SLOT ( unregisterObjectSlot ( TQObject * ) ) ) ;
return false ;
}
}
else {
else
{
//TODO: Write a debug warning to the log.
disconnect ( obj , SIGNAL ( destroyed ( TQObject * ) ) , this , SLOT ( unregisterObjectSlot ( TQObject * ) ) ) ;
return false ;
@ -448,30 +508,36 @@ bool UiGuiSettings::registerObjectSlot(TQObject *obj, const TQString &slotName,
return true ;
}
/*!
\ brief If \ a obj , \ a slotName and \ a settingName are given , that certain connection is unregistered .
If only \ a obj is given , all to this object registered slot - setting connections are unregistered .
*/
void UiGuiSettings : : unregisterObjectSlot ( TQObject * obj , const TQString & slotName , const TQString & settingName ) {
void UiGuiSettings : : unregisterObjectSlot ( TQObject * obj , const TQString & slotName ,
const TQString & settingName )
{
//const TQMetaObject *metaObject = obj->metaObject();
TQString normalizedSlotName = TQMetaObject : : normalizedSignature ( qPrintable ( slotName ) ) ;
TQMutableMapIterator < TQObject * , TQStringList > it ( _registeredObjectSlots ) ;
while ( it . hasNext ( ) ) {
while ( it . hasNext ( ) )
{
it . next ( ) ;
if ( it . key ( ) = = obj & & slotName . isEmpty ( ) & & settingName . isEmpty ( ) )
{
it . remove ( ) ;
}
else if ( it . key ( ) = = obj & & it . value ( ) . first ( ) = = slotName & & it . value ( ) . last ( ) = = settingName )
{
it . remove ( ) ;
}
}
}
/*!
\ brief This private slot gets invoked whenever a registered objects property changes
and distributes the new value to all other to the same settingName registered objects .
*/
void UiGuiSettings : : handleObjectPropertyChange ( ) {
void UiGuiSettings : : handleObjectPropertyChange ( )
{
TQObject * obj = TQObject : : sender ( ) ;
TQString className = obj - > metaObject ( ) - > className ( ) ;
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
@ -479,13 +545,13 @@ void UiGuiSettings::handleObjectPropertyChange() {
TQString settingName = _registeredObjectProperties [ obj ] . last ( ) ;
int indexOfProp = metaObject - > indexOfProperty ( qPrintable ( propertyName ) ) ;
if ( indexOfProp > - 1 ) {
if ( indexOfProp > - 1 )
{
TQMetaProperty mProp = metaObject - > property ( indexOfProp ) ;
setValueByName ( settingName , mProp . read ( obj ) ) ;
}
}
/*!
\ brief Sets the setting defined by \ a settingName to \ a value .
@ -493,20 +559,26 @@ void UiGuiSettings::handleObjectPropertyChange() {
the changed value set too .
If the \ a settingName didn ' t exist yet , it will be created .
*/
void UiGuiSettings : : setValueByName ( const TQString & settingName , const TQVariant & value ) {
void UiGuiSettings : : setValueByName ( const TQString & settingName , const TQVariant & value )
{
// Do the updating only, if the setting was really changed.
if ( _qsettings - > value ( " UniversalIndentGUI/ " + settingName ) ! = value ) {
if ( _qsettings - > value ( " UniversalIndentGUI/ " + settingName ) ! = value )
{
_qsettings - > setValue ( " UniversalIndentGUI/ " + settingName , value ) ;
// Set the new value for all registered object properties for settingName.
for ( TQMap < TQObject * , TQStringList > : : ConstIterator it = _registeredObjectProperties . begin ( ) ; it ! = _registeredObjectProperties . end ( ) ; + + it ) {
if ( it . value ( ) . last ( ) = = settingName ) {
for ( TQMap < TQObject * , TQStringList > : : ConstIterator it = _registeredObjectProperties . begin ( ) ;
it ! = _registeredObjectProperties . end ( ) ; + + it )
{
if ( it . value ( ) . last ( ) = = settingName )
{
TQObject * obj = it . key ( ) ;
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
TQString propertyName = it . value ( ) . first ( ) ;
int indexOfProp = metaObject - > indexOfProperty ( qPrintable ( propertyName ) ) ;
if ( indexOfProp > - 1 ) {
if ( indexOfProp > - 1 )
{
TQMetaProperty mProp = metaObject - > property ( indexOfProp ) ;
mProp . write ( obj , value ) ;
}
@ -514,14 +586,18 @@ void UiGuiSettings::setValueByName(const TQString &settingName, const TQVariant
}
// Invoke all registered object methods for settingName.
for ( TQMap < TQObject * , TQStringList > : : ConstIterator it = _registeredObjectSlots . begin ( ) ; it ! = _registeredObjectSlots . end ( ) ; + + it ) {
if ( it . value ( ) . last ( ) = = settingName ) {
for ( TQMap < TQObject * , TQStringList > : : ConstIterator it = _registeredObjectSlots . begin ( ) ;
it ! = _registeredObjectSlots . end ( ) ; + + it )
{
if ( it . value ( ) . last ( ) = = settingName )
{
TQObject * obj = it . key ( ) ;
const TQMetaObject * metaObject = obj - > metaObject ( ) ;
TQString slotName = it . value ( ) . first ( ) ;
int indexOfMethod = metaObject - > indexOfMethod ( qPrintable ( slotName ) ) ;
if ( indexOfMethod > - 1 ) {
if ( indexOfMethod > - 1 )
{
TQMetaMethod mMethod = metaObject - > method ( indexOfMethod ) ;
//TQMetaMethod::Access access = mMethod.access();
//TQMetaMethod::MethodType methType = mMethod.methodType();
@ -529,17 +605,21 @@ void UiGuiSettings::setValueByName(const TQString &settingName, const TQVariant
bool success = false ;
// Handle registered slots taking one parameter.
if ( mMethod . parameterTypes ( ) . size ( ) = = 1 ) {
if ( mMethod . parameterTypes ( ) . first ( ) = = value . typeName ( ) ) {
if ( mMethod . parameterTypes ( ) . size ( ) = = 1 )
{
if ( mMethod . parameterTypes ( ) . first ( ) = = value . typeName ( ) )
{
success = invokeMethodWithValue ( obj , mMethod , value ) ;
}
}
// Handle registered slots taking zero parameters.
else {
else
{
success = mMethod . invoke ( obj , TQt : : DirectConnection ) ;
}
if ( success = = false ) {
if ( success = = false )
{
// TODO: Write a warning to the log if no success.
}
}
@ -548,7 +628,6 @@ void UiGuiSettings::setValueByName(const TQString &settingName, const TQVariant
}
}
# include <tntqbitarray.h>
# include <tntqbitmap.h>
# include <tntqbrush.h>
@ -571,118 +650,284 @@ void UiGuiSettings::setValueByName(const TQString &settingName, const TQVariant
bool UiGuiSettings : : invokeMethodWithValue ( TQObject * obj , TQMetaMethod mMethod , TQVariant value )
{
switch ( value . type ( ) ) {
switch ( value . type ( ) )
{
case TQVariant : : BitArray :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQBitArray , value . toBitArray ( ) ) ) ;
}
case TQVariant : : Bitmap :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQBitmap , value . value < TQBitmap > ( ) ) ) ;
}
case TQVariant : : Bool :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( bool , value . toBool ( ) ) ) ;
}
case TQVariant : : Brush :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQBrush , value . value < TQBrush > ( ) ) ) ;
}
case TQVariant : : ByteArray :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQByteArray , value . toByteArray ( ) ) ) ;
}
case TQVariant : : Char :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQChar , value . toChar ( ) ) ) ;
}
case TQVariant : : Color :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQColor , value . value < TQColor > ( ) ) ) ;
}
case TQVariant : : Cursor :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQCursor , value . value < TQCursor > ( ) ) ) ;
}
case TQVariant : : Date :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQDate , value . toDate ( ) ) ) ;
}
case TQVariant : : DateTime :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQDateTime , value . toDateTime ( ) ) ) ;
}
case TQVariant : : Double :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( double , value . toDouble ( ) ) ) ;
}
case TQVariant : : Font :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQFont , value . value < TQFont > ( ) ) ) ;
}
case TQVariant : : Hash :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQVariantHash , value . toHash ( ) ) ) ;
}
case TQVariant : : Icon :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQIcon , value . value < TQIcon > ( ) ) ) ;
}
case TQVariant : : Image :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQImage , value . value < TQImage > ( ) ) ) ;
}
case TQVariant : : Int :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( int , value . toInt ( ) ) ) ;
}
case TQVariant : : KeySequence :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQKeySequence , value . value < TQKeySequence > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQKeySequence ,
value . value < TQKeySequence > ( ) ) ) ;
}
case TQVariant : : Line :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQLine , value . toLine ( ) ) ) ;
}
case TQVariant : : LineF :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQLineF , value . toLineF ( ) ) ) ;
}
case TQVariant : : List :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQVariantList , value . toList ( ) ) ) ;
}
case TQVariant : : Locale :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQLocale , value . toLocale ( ) ) ) ;
}
case TQVariant : : LongLong :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( qlonglong , value . toLongLong ( ) ) ) ;
}
case TQVariant : : Map :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQVariantMap , value . toMap ( ) ) ) ;
}
case TQVariant : : Matrix :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQMatrix , value . value < TQMatrix > ( ) ) ) ;
}
case TQVariant : : Transform :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQTransform , value . value < TQTransform > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection ,
Q_ARG ( TQTransform , value . value < TQTransform > ( ) ) ) ;
}
# if TQT_VERSION >= 0x040600
case TQVariant : : Matrix4x4 :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQMatrix4x4 , value . value < TQMatrix4x4 > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection ,
Q_ARG ( TQMatrix4x4 , value . value < TQMatrix4x4 > ( ) ) ) ;
}
# endif
case TQVariant : : Palette :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQPalette , value . value < TQPalette > ( ) ) ) ;
}
case TQVariant : : Pen :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQPen , value . value < TQPen > ( ) ) ) ;
}
case TQVariant : : Pixmap :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQPixmap , value . value < TQPixmap > ( ) ) ) ;
}
case TQVariant : : Point :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQPoint , value . toPoint ( ) ) ) ;
}
// case TQVariant::PointArray :
// return Q_ARG(TQPointArray, value.value<TQPointArray>()) );
case TQVariant : : PointF :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQPointF , value . toPointF ( ) ) ) ;
}
case TQVariant : : Polygon :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQPolygon , value . value < TQPolygon > ( ) ) ) ;
}
# if TQT_VERSION >= 0x040600
case TQVariant : : Quaternion :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQQuaternion , value . value < TQQuaternion > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQQuaternion ,
value . value < TQQuaternion > ( ) ) ) ;
}
# endif
case TQVariant : : Rect :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQRect , value . toRect ( ) ) ) ;
}
case TQVariant : : RectF :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQRectF , value . toRectF ( ) ) ) ;
}
case TQVariant : : RegExp :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQRegExp , value . toRegExp ( ) ) ) ;
}
case TQVariant : : Region :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQRegion , value . value < TQRegion > ( ) ) ) ;
}
case TQVariant : : Size :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQSize , value . toSize ( ) ) ) ;
}
case TQVariant : : SizeF :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQSizeF , value . toSizeF ( ) ) ) ;
}
case TQVariant : : SizePolicy :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQSizePolicy , value . value < TQSizePolicy > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQSizePolicy ,
value . value < TQSizePolicy > ( ) ) ) ;
}
case TQVariant : : String :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQString , value . toString ( ) ) ) ;
}
case TQVariant : : StringList :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQStringList , value . toStringList ( ) ) ) ;
}
case TQVariant : : TextFormat :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQTextFormat , value . value < TQTextFormat > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQTextFormat ,
value . value < TQTextFormat > ( ) ) ) ;
}
case TQVariant : : TextLength :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQTextLength , value . value < TQTextLength > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQTextLength ,
value . value < TQTextLength > ( ) ) ) ;
}
case TQVariant : : Time :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQTime , value . toTime ( ) ) ) ;
}
case TQVariant : : UInt :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( uint , value . toUInt ( ) ) ) ;
}
case TQVariant : : ULongLong :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( qulonglong , value . toULongLong ( ) ) ) ;
}
case TQVariant : : Url :
{
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQUrl , value . toUrl ( ) ) ) ;
}
# if TQT_VERSION >= 0x040600
case TQVariant : : Vector2D :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQVector2D , value . value < TQVector2D > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection ,
Q_ARG ( TQVector2D , value . value < TQVector2D > ( ) ) ) ;
}
case TQVariant : : Vector3D :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQVector3D , value . value < TQVector3D > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection ,
Q_ARG ( TQVector3D , value . value < TQVector3D > ( ) ) ) ;
}
case TQVariant : : Vector4D :
return mMethod . invoke ( obj , TQt : : DirectConnection , Q_ARG ( TQVector4D , value . value < TQVector4D > ( ) ) ) ;
{
return mMethod . invoke ( obj , TQt : : DirectConnection ,
Q_ARG ( TQVector4D , value . value < TQVector4D > ( ) ) ) ;
}
# endif
default :
{
return false ;
}
}
}