| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude 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 (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CConfigurationBase.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Config { |
| 27 |
|
| 28 |
|
| 29 |
CConfigurationBase::CConfigurationBase(CConfiguration *previousConfiguration, qint64 configurationID) |
| 30 |
: CConfiguration(previousConfiguration) { |
| 31 |
confID = configurationID; |
| 32 |
} |
| 33 |
|
| 34 |
CConfigurationBase::CConfigurationBase(CConfigurationBase *previousConfiguration, qint64 configurationID) |
| 35 |
: CConfiguration(previousConfiguration) { |
| 36 |
confID = configurationID; |
| 37 |
prevConfBase = previousConfiguration; |
| 38 |
} |
| 39 |
|
| 40 |
CConfigurationBase::CConfigurationBase(CConfigurationGroup *configGroup, qint64 configurationID) |
| 41 |
: CConfiguration(configGroup) { |
| 42 |
confID = configurationID; |
| 43 |
prevConfBase = 0; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
CConfigurationBase::~CConfigurationBase() { |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
qint64 CConfigurationBase::getConfigurationLevel() { |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
bool CConfigurationBase::isConfigLevelLocked(CConfigData *data) { |
| 56 |
if (data) { |
| 57 |
return data->getLevelLock() >= getConfigurationLevel(); |
| 58 |
} |
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
bool CConfigurationBase::isConfigLevelLocked(const QString &configName, bool defaultCompensation) { |
| 63 |
CConfigData *configData = getRelatedConfigChange(configName,defaultCompensation); |
| 64 |
return isConfigLevelLocked(configData); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
bool CConfigurationBase::isConfigLevelLocked(qint64 configIndex, bool defaultCompensation) { |
| 69 |
CConfigData *configData = getRelatedConfigChange(configIndex,defaultCompensation); |
| 70 |
return isConfigLevelLocked(configData); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
qint64 CConfigurationBase::getConfigurationID() { |
| 75 |
return confID; |
| 76 |
} |
| 77 |
|
| 78 |
bool CConfigurationBase::isSuccessor(qint64 configID) { |
| 79 |
return (confID == configID || (prevConfBase && prevConfBase->isSuccessor(configID))); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
bool CConfigurationBase::hasConfigChange(qint64 configIndex, qint64 prevConfID, CConfigData *configData) { |
| 84 |
if (configIndex >= 0 && configIndex < conData->count()) { |
| 85 |
if (confID >= prevConfID) { |
| 86 |
CConfigData *data = (*conData)[configIndex]; |
| 87 |
if (configData && data) { |
| 88 |
if (!configData->equals(data)) { |
| 89 |
return true; |
| 90 |
} |
| 91 |
} |
| 92 |
if (configData) { |
| 93 |
data = configData; |
| 94 |
} |
| 95 |
if (prevConfBase) { |
| 96 |
return prevConfBase->hasConfigChange(configIndex,prevConfID,data); |
| 97 |
} else if (prevConfID <= 0) { |
| 98 |
data = 0; |
| 99 |
if (prevConf) { |
| 100 |
data = prevConf->getLastConfigChange(configIndex); |
| 101 |
} else if (conGroup) { |
| 102 |
data = conGroup->getConfigDefaultData(configIndex); |
| 103 |
} |
| 104 |
if (configData && data) { |
| 105 |
if (!configData->equals(data)) { |
| 106 |
return true; |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
return false; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
CConfigData *CConfigurationBase::getRelatedConfigChange(const QString &configName, bool defaultCompensation) { |
| 117 |
CConfigData *data = 0; |
| 118 |
if (conGroup) { |
| 119 |
qint64 index = conGroup->getConfigIndex(configName); |
| 120 |
data = getRelatedConfigChange(index,defaultCompensation); |
| 121 |
} |
| 122 |
return data; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
CConfigData *CConfigurationBase::getRelatedConfigChange(qint64 configIndex, bool defaultCompensation) { |
| 127 |
CConfigData *data = getLastConfigChange(configIndex,defaultCompensation); |
| 128 |
return data; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
CConfigurationBase *CConfigurationBase::appendConfigurationsToList(QLinkedList<CConfigurationBase *> *configurationList) { |
| 133 |
if (configurationList) { |
| 134 |
configurationList->append(this); |
| 135 |
} |
| 136 |
return this; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
}; // end namespace Config |
| 141 |
|
| 142 |
}; // end namespace Konclude |