Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions plotjuggler_base/include/PlotJuggler/dialog_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef PJ_DIALOG_UTILS_H
#define PJ_DIALOG_UTILS_H

#include <QDialog>
#include <set>

namespace PJ
{

/**
* @brief Adjusts dialog size to fit contents after widget visibility changes
*
* This function resets dialog size constraints and forces the layout system
* to recalculate the optimal size. Useful when showing/hiding option widgets
* in plugin dialogs.
*
* @param dialog The dialog to resize
*/
inline void adjustDialogToContent(QDialog* dialog, const QString& selected_protocol)
{
if (!dialog)
{
return;
}
// Reset minimum height and resize dialog
dialog->setMinimumHeight(0);
dialog->layout()->invalidate();
dialog->layout()->activate();

QSize hint;
if (std::set<QString>{ "ros1msg", "ros2msg", "data_tamer", "Influx (Line protocol)" }.count(
selected_protocol))
{
hint = QSize(316, 341);
}
else
{
hint = dialog->sizeHint();
}
// Force recalculation of size hint
dialog->setMaximumHeight(hint.height());
dialog->resize(hint);
}

} // namespace PJ

#endif // PJ_DIALOG_UTILS_H
5 changes: 5 additions & 0 deletions plotjuggler_plugins/DataStreamMQTT/datastream_mqtt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "datastream_mqtt.h"
#include "ui_datastream_mqtt.h"
#include "PlotJuggler/dialog_utils.h"
#include <QMessageBox>
#include <QSettings>
#include <QDebug>
Expand Down Expand Up @@ -137,6 +138,10 @@ void DataStreamMQTT::onComboProtocolChanged(const QString& selected_protocol)
{
widget->setVisible(true);
}
_dialog->setMinimumHeight(0);
_dialog->layout()->invalidate();
_dialog->layout()->activate();
_dialog->resize(_dialog->sizeHint());
}

void DataStreamMQTT::onMessageReceived(const mosquitto_message* message)
Expand Down
5 changes: 4 additions & 1 deletion plotjuggler_plugins/DataStreamUDP/udp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ THE SOFTWARE.
#include <chrono>
#include <QNetworkDatagram>
#include <QNetworkInterface>
#include <set>

#include "ui_udp_server.h"
#include "PlotJuggler/dialog_utils.h"

class UdpServerDialog : public QDialog
{
Expand Down Expand Up @@ -110,7 +112,7 @@ bool UDP_Server::start(QStringList*)

ParserFactoryPlugin::Ptr parser_creator;

auto onComboChanged = [&](const QString& selected_protocol) {
auto onComboChanged = [this, &dialog, &parser_creator](const QString& selected_protocol) {
if (parser_creator)
{
if (auto prev_widget = parser_creator->optionsWidget())
Expand All @@ -124,6 +126,7 @@ bool UDP_Server::start(QStringList*)
{
widget->setVisible(true);
}
PJ::adjustDialogToContent(&dialog, selected_protocol);
};

connect(dialog.ui->comboBoxProtocol, qOverload<const QString&>(&QComboBox::currentIndexChanged),
Expand Down
5 changes: 4 additions & 1 deletion plotjuggler_plugins/DataStreamWebsocket/websocket_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ THE SOFTWARE.
#include <chrono>

#include "ui_websocket_server.h"
#include "PlotJuggler/dialog_utils.h"

class WebsocketDialog : public QDialog
{
Expand Down Expand Up @@ -105,7 +106,7 @@ bool WebsocketServer::start(QStringList*)
ParserFactoryPlugin::Ptr parser_creator;

connect(dialog->ui->comboBoxProtocol, qOverload<const QString&>(&QComboBox::currentIndexChanged),
this, [&](const QString& selected_protocol) {
this, [this, dialog, &parser_creator](const QString& selected_protocol) {
if (parser_creator)
{
if (auto prev_widget = parser_creator->optionsWidget())
Expand All @@ -119,6 +120,8 @@ bool WebsocketServer::start(QStringList*)
{
widget->setVisible(true);
}

PJ::adjustDialogToContent(dialog, selected_protocol);
});

dialog->ui->comboBoxProtocol->setCurrentText(protocol);
Expand Down
5 changes: 4 additions & 1 deletion plotjuggler_plugins/DataStreamZMQ/datastream_zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_datastream_zmq.h"

#include "PlotJuggler/messageparser_base.h"
#include "PlotJuggler/dialog_utils.h"
#include <QDebug>
#include <QDialog>
#include <QIntValidator>
Expand Down Expand Up @@ -106,7 +107,7 @@ bool DataStreamZMQ::start(QStringList*)
dialog->ui->lineEditTopics->setText(topics);

connect(dialog->ui->comboBoxProtocol, qOverload<const QString&>(&QComboBox::currentIndexChanged),
this, [&](const QString& selected_protocol) {
this, [this, dialog](const QString& selected_protocol) {
if (_parser_creator)
{
if (auto prev_widget = _parser_creator->optionsWidget())
Expand All @@ -120,6 +121,8 @@ bool DataStreamZMQ::start(QStringList*)
{
widget->setVisible(true);
}

PJ::adjustDialogToContent(dialog, selected_protocol);
});

dialog->ui->comboBoxProtocol->setCurrentText(protocol);
Expand Down
Loading