Cleanups and warning fixes in ManualDevices
This commit is contained in:
parent
ebfbb4b56f
commit
064bae7b87
2 changed files with 50 additions and 35 deletions
|
|
@ -1,11 +1,12 @@
|
|||
/*-----------------------------------------------------------------*\
|
||||
| ManualDevicesSettingsPage.cpp |
|
||||
| |
|
||||
| User interface for OpenRGB Manually Added Devices settings page |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*-----------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------*\
|
||||
| ManualDevicesSettingsPage.cpp |
|
||||
| |
|
||||
| User interface for OpenRGB Manually Added Devices |
|
||||
| settings page |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "ManualDevicesSettingsPage.h"
|
||||
#include "ui_ManualDevicesSettingsPage.h"
|
||||
|
|
@ -91,7 +92,7 @@ void ManualDevicesSettingsPage::saveSettings()
|
|||
| We wrap data into arrays by type (except Nanoleaf) |
|
||||
| Nanoleaf stores it's data as an object with "location" as key for some reason |
|
||||
\*-----------------------------------------------------------------------------*/
|
||||
for(size_t idx = 0; idx < entries.size(); ++idx)
|
||||
for(std::size_t idx = 0; idx < entries.size(); idx++)
|
||||
{
|
||||
std::string section = entries[idx]->getSettingsSection();
|
||||
if(section == "NanoleafDevices")
|
||||
|
|
@ -114,9 +115,8 @@ void ManualDevicesSettingsPage::saveSettings()
|
|||
| Use ALL possible settings entry names, so that those with |
|
||||
| all entries deleted are cleared properly |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
std::vector<ManualDeviceTypeBlock> blocks = ManualDevicesTypeManager::get()->getRegisteredTypes();
|
||||
for(int i = 0; i < blocks.size(); ++i)
|
||||
for(std::size_t i = 0; i < blocks.size(); i++)
|
||||
{
|
||||
sm->SetSettings(blocks[i].settingsSection, result[blocks[i].settingsSection]);
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ void ManualDevicesSettingsPage::reloadMenu()
|
|||
std::vector<std::string> names = ManualDevicesTypeManager::get()->getRegisteredTypeNames();
|
||||
|
||||
addDeviceMenu->clear();
|
||||
for(int i = 0; i < names.size(); ++i)
|
||||
for(std::size_t i = 0; i < names.size(); i++)
|
||||
{
|
||||
QAction* action = addDeviceMenu->addAction(qApp->translate("ManualDevice", names[i].c_str()));
|
||||
action->setData(QString::fromStdString(names[i]));
|
||||
|
|
@ -143,7 +143,7 @@ void ManualDevicesSettingsPage::reloadList()
|
|||
addDeviceMenu->clear();
|
||||
|
||||
std::vector<ManualDeviceTypeBlock> blocks = ManualDevicesTypeManager::get()->getRegisteredTypes();
|
||||
for(int i = 0; i < blocks.size(); ++i)
|
||||
for(std::size_t i = 0; i < blocks.size(); i++)
|
||||
{
|
||||
addEntries(blocks[i]);
|
||||
|
||||
|
|
@ -154,9 +154,9 @@ void ManualDevicesSettingsPage::reloadList()
|
|||
action->setData(QString::fromStdString(blocks[i].name));
|
||||
}
|
||||
|
||||
/*--------------------*\
|
||||
| Refresh button state |
|
||||
\*--------------------*/
|
||||
/*---------------------------------------------------------*\
|
||||
| Refresh button state |
|
||||
\*---------------------------------------------------------*/
|
||||
setUnsavedChanges(false);
|
||||
on_deviceList_itemSelectionChanged();
|
||||
}
|
||||
|
|
@ -172,10 +172,11 @@ void ManualDevicesSettingsPage::clearList()
|
|||
entries_copy.swap(entries);
|
||||
ui->deviceList->clear();
|
||||
|
||||
for(int i = 0; i < entries_copy.size(); ++i)
|
||||
for(std::size_t i = 0; i < entries_copy.size(); i++)
|
||||
{
|
||||
delete entries_copy[i];
|
||||
}
|
||||
|
||||
entries_copy.clear();
|
||||
setUnsavedChanges(true);
|
||||
}
|
||||
|
|
@ -184,6 +185,7 @@ void ManualDevicesSettingsPage::setUnsavedChanges(bool v)
|
|||
{
|
||||
unsavedChanges = v;
|
||||
ui->saveConfigurationButton->setEnabled(v && checkValidToSave());
|
||||
|
||||
if(v)
|
||||
{
|
||||
ui->saveConfigurationButton->setStyleSheet("font: bold");
|
||||
|
|
@ -196,13 +198,14 @@ void ManualDevicesSettingsPage::setUnsavedChanges(bool v)
|
|||
|
||||
bool ManualDevicesSettingsPage::checkValidToSave()
|
||||
{
|
||||
for(int i = 0; i < entries.size(); ++i)
|
||||
for(std::size_t i = 0; i < entries.size(); i++)
|
||||
{
|
||||
if(!entries[i]->isDataValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +222,7 @@ QListWidgetItem* ManualDevicesSettingsPage::addEntry(BaseManualDeviceEntry* entr
|
|||
| Validation mostly affects the "Save" button state |
|
||||
\*---------------------------------------------------------*/
|
||||
QList<QLineEdit*> textEditList = entry->findChildren<QLineEdit*>(QString(), Qt::FindChildrenRecursively);
|
||||
for(int i = 0; i < textEditList.size(); ++i)
|
||||
for(std::size_t i = 0; i < textEditList.size(); i++)
|
||||
{
|
||||
connect(textEditList[i], &QLineEdit::textChanged, this, &ManualDevicesSettingsPage::onTextEditChanged);
|
||||
}
|
||||
|
|
@ -287,11 +290,15 @@ void ManualDevicesSettingsPage::addEntries(const ManualDeviceTypeBlock& block)
|
|||
|
||||
void ManualDevicesSettingsPage::onAddDeviceItemSelected(QAction* action)
|
||||
{
|
||||
std::string entryName = action->data().toString().toStdString();
|
||||
BaseManualDeviceEntry* entry = ManualDevicesTypeManager::get()->spawnByTypeName(entryName, json());
|
||||
/*---------------------------------------------------*\
|
||||
| Note: spawn functions are allowed to return nullptr |
|
||||
\*---------------------------------------------------*/
|
||||
/*---------------------------------------------------------*\
|
||||
| Spawn new entry based on name |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string entryName = action->data().toString().toStdString();
|
||||
BaseManualDeviceEntry* entry = ManualDevicesTypeManager::get()->spawnByTypeName(entryName, json());
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Note: spawn functions are allowed to return nullptr |
|
||||
\*---------------------------------------------------------*/
|
||||
if(entry)
|
||||
{
|
||||
QListWidgetItem* item = addEntry(entry);
|
||||
|
|
@ -308,9 +315,12 @@ void ManualDevicesSettingsPage::onAddDeviceItemSelected(QAction* action)
|
|||
|
||||
void ManualDevicesSettingsPage::on_deviceList_itemSelectionChanged()
|
||||
{
|
||||
int cur_row = ui->deviceList->currentRow();
|
||||
/*---------------------------------------------------------*\
|
||||
| Enable Remove button if any entry is selected |
|
||||
\*---------------------------------------------------------*/
|
||||
int cur_row = ui->deviceList->currentRow();
|
||||
bool anySelected = (cur_row >= 0);
|
||||
|
||||
bool anySelected = (cur_row >= 0);
|
||||
ui->removeDeviceButton->setEnabled(anySelected);
|
||||
}
|
||||
|
||||
|
|
@ -322,9 +332,10 @@ void ManualDevicesSettingsPage::on_ActionSaveNoRescan_triggered()
|
|||
void ManualDevicesSettingsPage::on_ActionSaveAndRescan_triggered()
|
||||
{
|
||||
saveSettings();
|
||||
/*---------------*\
|
||||
| Trigger rescan |
|
||||
\*--------------*/
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Trigger rescan |
|
||||
\*---------------------------------------------------------*/
|
||||
ResourceManager::get()->DetectDevices();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,18 +13,20 @@
|
|||
|
||||
ManualDeviceTypeBlock::ManualDeviceTypeBlock(const std::string& _name, const std::string& _settingsSection, ManualDeviceEntrySpawnFunction _entrySpawnFunction)
|
||||
{
|
||||
name = _name;
|
||||
settingsSection = _settingsSection;
|
||||
entrySpawnFunction = _entrySpawnFunction;
|
||||
name = _name;
|
||||
settingsSection = _settingsSection;
|
||||
entrySpawnFunction = _entrySpawnFunction;
|
||||
}
|
||||
|
||||
BaseManualDeviceEntry* ManualDeviceTypeBlock::spawn(const json& data) const
|
||||
{
|
||||
BaseManualDeviceEntry* result = entrySpawnFunction(data);
|
||||
|
||||
if(result)
|
||||
{
|
||||
result->setSettingsSection(settingsSection);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +44,7 @@ ManualDevicesTypeManager *ManualDevicesTypeManager::get()
|
|||
|
||||
ManualDevicesTypeManager::ManualDevicesTypeManager()
|
||||
{
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
void ManualDevicesTypeManager::registerType(const std::string& name, const std::string& settingsSection, ManualDeviceEntrySpawnFunction entrySpawnFunction)
|
||||
|
|
@ -60,21 +62,23 @@ std::vector<std::string> ManualDevicesTypeManager::getRegisteredTypeNames()
|
|||
std::vector<std::string> result;
|
||||
result.resize(types.size());
|
||||
|
||||
for(int i = 0; i < types.size(); ++i)
|
||||
for(std::size_t i = 0; i < types.size(); i++)
|
||||
{
|
||||
result[i] = types[i].name;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BaseManualDeviceEntry* ManualDevicesTypeManager::spawnByTypeName(const std::string& typeName, const json& data)
|
||||
{
|
||||
for(int i = 0; i < types.size(); ++i)
|
||||
for(std::size_t i = 0; i < types.size(); i++)
|
||||
{
|
||||
if(types[i].name == typeName)
|
||||
{
|
||||
return types[i].spawn(data);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue