Skip to content

Commit

Permalink
Performing all plugins configuration in a single widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Jan 9, 2024
1 parent be0783b commit 400076e
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 55 deletions.
3 changes: 3 additions & 0 deletions app/cc_view/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function (bin_cc_view)
widget/MessageUpdateDialog.cpp
widget/PluginsListWidget.cpp
widget/PluginConfigDialog.cpp
widget/PluginConfigWrapWidget.cpp
widget/PluginConfigWrapsListWidget.cpp
widget/MsgCommentDialog.cpp
widget/field/FieldWidget.cpp
widget/MessagesFilterDialog.cpp
Expand Down Expand Up @@ -104,6 +106,7 @@ function (bin_cc_view)
ui/RawHexDataDialog.ui
ui/PluginsListWidget.ui
ui/PluginConfigDialog.ui
ui/PluginConfigWrapWidget.ui
ui/ShortIntValueFieldWidget.ui
ui/LongIntValueFieldWidget.ui
ui/LongLongIntValueFieldWidget.ui
Expand Down
18 changes: 9 additions & 9 deletions app/cc_view/src/ui/PluginConfigDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>298</width>
<width>304</width>
<height>249</height>
</rect>
</property>
Expand Down Expand Up @@ -48,7 +48,7 @@
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_8" stretch="3,0,7">
<layout class="QVBoxLayout" name="verticalLayout_8" stretch="3,0,8">
<item>
<widget class="QGroupBox" name="m_selectedGroupBox">
<property name="title">
Expand Down Expand Up @@ -88,26 +88,26 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="m_configGroupBox">
<widget class="QGroupBox" name="m_allConfigGroupBox">
<property name="title">
<string>Plugin Configuration</string>
<string>Plugins Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QScrollArea" name="m_configScrollArea">
<widget class="QScrollArea" name="m_allConfigScrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="m_configScrollAreaWidgetContents">
<widget class="QWidget" name="scrollAreaWidgetContents_4">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>125</width>
<width>131</width>
<height>83</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
<layout class="QVBoxLayout" name="verticalLayout_5"/>
</widget>
</widget>
</item>
Expand Down
29 changes: 29 additions & 0 deletions app/cc_view/src/ui/PluginConfigWrapWidget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PluginConfigWrapWidget</class>
<widget class="QWidget" name="PluginConfigWrapWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>102</width>
<height>54</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="m_wrapGroupBox">
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
56 changes: 11 additions & 45 deletions app/cc_view/src/widget/PluginConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ PluginConfigDialog::PluginConfigDialog(
m_applyButton = m_ui.m_buttonBox->button(QDialogButtonBox::Ok);
m_applyButton->setText(tr("Apply"));
refreshAll();

m_allConfigWidget = new PluginConfigWrapsListWidget(this);
m_ui.m_allConfigScrollArea->setWidget(m_allConfigWidget);
}

void PluginConfigDialog::accept()
Expand Down Expand Up @@ -204,6 +207,8 @@ void PluginConfigDialog::addClicked()
refreshAvailablePlugins();
refreshSelectedToolbar();
refreshButtonBox();

m_allConfigWidget->addPluginConfig(pluginInfoPtr);
}

void PluginConfigDialog::searchTextChanged([[maybe_unused]] const QString& text)
Expand Down Expand Up @@ -250,11 +255,6 @@ void PluginConfigDialog::loadClicked()
assert(m_selectedSocketsWidget->currentItem() == nullptr);
assert(m_selectedFiltersWidget->currentItem() == nullptr);
assert(m_selectedProtocolsWidget->currentItem() == nullptr);

if ((m_currentAvailableList == nullptr) ||
(m_currentAvailableList->currentItem() == nullptr)) {
clearConfiguration();
}
}

void PluginConfigDialog::saveClicked()
Expand Down Expand Up @@ -287,14 +287,18 @@ void PluginConfigDialog::removeClicked()
assert(m_currentSelectedList != nullptr);
auto* item = m_currentSelectedList->currentItem();
assert(item != nullptr);

auto pluginInfoPtr = getPluginInfo(item);
assert(pluginInfoPtr);
m_allConfigWidget->removePluginConfig(pluginInfoPtr);

delete item;
refreshAvailablePlugins();
refreshSelectedToolbar();
refreshButtonBox();

item = m_currentSelectedList->currentItem();
if (item == nullptr) {
clearConfiguration();
m_currentSelectedList = nullptr;
return;
}
Expand All @@ -304,20 +308,14 @@ void PluginConfigDialog::removeClicked()

void PluginConfigDialog::clearClicked()
{
bool displayingSelected =
(m_currentSelectedList != nullptr) &&
(m_currentSelectedList->currentItem() != nullptr);
m_selectedSocketsWidget->clear();
m_selectedFiltersWidget->clear();
m_selectedProtocolsWidget->clear();
m_allConfigWidget->removeAll();
m_currentSelectedList = nullptr;
refreshAvailablePlugins();
refreshSelectedToolbar();
refreshButtonBox();

if (displayingSelected) {
clearConfiguration();
}
}

void PluginConfigDialog::topClicked()
Expand Down Expand Up @@ -393,11 +391,6 @@ void PluginConfigDialog::availPluginClicked(
m_currentAvailableList->setCurrentItem(item);
assert(m_currentAvailableList->currentRow() == m_currentAvailableList->getRow(item));

clearConfiguration();

auto pluginInfoPtr = getPluginInfo(item);
assert(pluginInfoPtr);

refreshAvailableToolbar();
}

Expand Down Expand Up @@ -425,28 +418,6 @@ void PluginConfigDialog::selectedPluginClicked(
selectedList->setCurrentItem(item);
assert(selectedList->currentRow() == selectedList->getRow(item));

do {
auto clearGuard =
comms::util::makeScopeGuard(
[this]()
{
clearConfiguration();
});

auto* plugin = PluginMgrG::instanceRef().loadPlugin(*pluginInfoPtr);
if (plugin == nullptr) {
break;
}

auto* configWidget = plugin->createConfiguarionWidget();
if (configWidget == nullptr) {
break;
}

clearGuard.release();
m_ui.m_configScrollArea->setWidget(configWidget);
} while (false);

refreshSelectedToolbar();
}

Expand Down Expand Up @@ -846,11 +817,6 @@ void PluginConfigDialog::refreshBottomButton()
button->setEnabled(enabled);
}

void PluginConfigDialog::clearConfiguration()
{
m_ui.m_configScrollArea->setWidget(new QWidget());
}

void PluginConfigDialog::moveSelectedPlugin(int fromRow, int toRow)
{
assert(m_currentSelectedList != nullptr);
Expand Down
4 changes: 3 additions & 1 deletion app/cc_view/src/widget/PluginConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CC_ENABLE_WARNINGS()
#include "cc_tools_qt/PluginMgr.h"
#include "PluginsListWidget.h"
#include "ActionWrap.h"
#include "PluginConfigWrapsListWidget.h"

namespace cc_tools_qt
{
Expand Down Expand Up @@ -101,7 +102,6 @@ private slots:
void refreshUpBotton();
void refreshDownBotton();
void refreshBottomButton();
void clearConfiguration();
void moveSelectedPlugin(int fromRow, int toRow);

PluginInfoPtr getPluginInfo(QListWidgetItem* item) const;
Expand Down Expand Up @@ -131,6 +131,8 @@ private slots:
PluginsListWidget* m_selectedFiltersWidget = nullptr;
PluginsListWidget* m_selectedProtocolsWidget = nullptr;
PluginsListWidget* m_currentSelectedList = nullptr;

PluginConfigWrapsListWidget* m_allConfigWidget;
};

} // namespace cc_tools_qt
39 changes: 39 additions & 0 deletions app/cc_view/src/widget/PluginConfigWrapWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright 2024 - 2025 (C). Alex Robenko. All rights reserved.
//

// This file is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "PluginConfigWrapWidget.h"

#include <cassert>

namespace cc_tools_qt
{

PluginConfigWrapWidget::PluginConfigWrapWidget(PluginInfoPtr pluginInfo, QWidget* configWidget, QWidget* parentObj) :
Base(parentObj)
{
assert(configWidget != nullptr);
m_ui.setupUi(this);
auto* layout = qobject_cast<QVBoxLayout*>(m_ui.m_wrapGroupBox->layout());
layout->addWidget(configWidget);

m_ui.m_wrapGroupBox->setTitle(pluginInfo->getName());
m_pluginInfo = pluginInfo;
}

PluginConfigWrapWidget::~PluginConfigWrapWidget() = default;

} // namespace cc_tools_qt
54 changes: 54 additions & 0 deletions app/cc_view/src/widget/PluginConfigWrapWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Copyright 2024 - 2025 (C). Alex Robenko. All rights reserved.
//

// This file is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#pragma once

#include <QtWidgets/QWidget>

#include "cc_tools_qt/PluginMgr.h"

#include "ui_PluginConfigWrapWidget.h"

namespace cc_tools_qt
{

class PluginConfigWrapWidget: public QWidget
{
using Base = QWidget;

public:
using Type = PluginMgr::PluginInfo::Type;
using PluginInfoPtr = PluginMgr::PluginInfoPtr;
PluginConfigWrapWidget(PluginInfoPtr pluginInfo, QWidget* configWidget, QWidget* parentObj = nullptr);
~PluginConfigWrapWidget();

const QString& getIid() const
{
return m_pluginInfo->getIid();
}

Type getType() const
{
return m_pluginInfo->getType();
}

private:
Ui::PluginConfigWrapWidget m_ui;
PluginInfoPtr m_pluginInfo;
};

} // namespace cc_tools_qt
Loading

0 comments on commit 400076e

Please sign in to comment.