mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-20 11:38:26 -06:00
add conversions for reading and writing node paths to settings
This commit is contained in:
parent
928a031208
commit
e85db68cb9
@ -20,6 +20,10 @@ QVariant fromAssignmentArgument(TuxClocker::Device::AssignmentArgument arg) {
|
||||
return QVariant{};
|
||||
}
|
||||
|
||||
NodePath fromSettingsPath(QString path) { return path.replace('-', '/'); }
|
||||
|
||||
QString toSettingsPath(NodePath path) { return path.replace('/', '-'); }
|
||||
|
||||
void traverseModel(
|
||||
const ModelTraverseCallback &cb, QAbstractItemModel *model, const QModelIndex &parent) {
|
||||
// Run callback on the index itself
|
||||
@ -57,11 +61,11 @@ void writeAssignableDefaults(DeviceModel &model) {
|
||||
settings.beginGroup("assignableDefaults");
|
||||
|
||||
// QSettings doesn't want us to use slashes for keys
|
||||
auto dbusPath = assProxy->dbusPath().replace('/', '-');
|
||||
auto settingsPath = toSettingsPath(assProxy->dbusPath());
|
||||
// Don't set again, so the program can be closed
|
||||
// with assignables changed, and defaults still be set
|
||||
if (!settings.contains(dbusPath))
|
||||
settings.setValue(dbusPath, currentValueV);
|
||||
if (!settings.contains(settingsPath))
|
||||
settings.setValue(settingsPath, currentValueV);
|
||||
|
||||
settings.endGroup();
|
||||
}
|
||||
|
@ -6,6 +6,11 @@ namespace Utils {
|
||||
|
||||
using ModelTraverseCallback =
|
||||
std::function<std::optional<QModelIndex>(QAbstractItemModel *, const QModelIndex &, int)>;
|
||||
using NodePath = QString;
|
||||
|
||||
// Conversion for saving in settings
|
||||
NodePath fromSettingsPath(QString);
|
||||
QString toSettingsPath(NodePath);
|
||||
|
||||
void traverseModel(
|
||||
const ModelTraverseCallback &, QAbstractItemModel *, const QModelIndex &parent = QModelIndex());
|
||||
|
@ -175,7 +175,7 @@ bool DeviceModelDelegate::subtreeHasAssignableDefaults(
|
||||
auto name = model->index(row, DeviceModel::NameColumn, index).data();
|
||||
if (assProxyV.isValid()) {
|
||||
auto nodePath = qvariant_cast<AssignableProxy *>(assProxyV)->dbusPath();
|
||||
if (settings.contains(nodePath.replace('/', '-'))) {
|
||||
if (settings.contains(Utils::toSettingsPath(nodePath))) {
|
||||
// This stops traversing model
|
||||
hasDefaults = true;
|
||||
return std::nullopt;
|
||||
|
Loading…
Reference in New Issue
Block a user