From 5cbf3b37cdfd3212a0545cf57d60012cafd85bd8 Mon Sep 17 00:00:00 2001 From: Andrei-Fabian-Pop Date: Fri, 22 Mar 2024 15:14:06 +0200 Subject: [PATCH] wip, small ui fixes Signed-off-by: Andrei-Fabian-Pop --- .../include/iiodebugplugin/detailsview.h | 11 ++++ .../iiodebugplugin/iiodebuginstrument.h | 2 - .../include/iiodebugplugin/iiomodel.h | 2 + .../include/iiodebugplugin/iiostandarditem.h | 2 + .../include/iiodebugplugin/watchlistentry.h | 19 +++++- .../include/iiodebugplugin/watchlistview.h | 2 +- plugins/iiodebugplugin/src/detailsview.cpp | 47 +++++++++++++- plugins/iiodebugplugin/src/guidetailsview.cpp | 4 +- .../iiodebugplugin/src/iiodebuginstrument.cpp | 25 +++----- plugins/iiodebugplugin/src/iiomodel.cpp | 16 +++-- .../iiodebugplugin/src/iiostandarditem.cpp | 64 +++++++++---------- plugins/iiodebugplugin/src/watchlistentry.cpp | 56 ++++++++++++---- plugins/iiodebugplugin/src/watchlistview.cpp | 18 ++++-- 13 files changed, 190 insertions(+), 78 deletions(-) diff --git a/plugins/iiodebugplugin/include/iiodebugplugin/detailsview.h b/plugins/iiodebugplugin/include/iiodebugplugin/detailsview.h index d32bf8476f..c1b50ffa61 100644 --- a/plugins/iiodebugplugin/include/iiodebugplugin/detailsview.h +++ b/plugins/iiodebugplugin/include/iiodebugplugin/detailsview.h @@ -18,6 +18,12 @@ class DetailsView : public QWidget void setIIOStandardItem(IIOStandardItem *item); void refreshIIOView(); + QPushButton *readBtn(); + QPushButton *addToWatchlistBtn(); + + // add:true = +, add:false = X + void setAddToWatchlistState(bool add); + private: void setupUi(); @@ -27,7 +33,12 @@ class DetailsView : public QWidget QTabWidget *m_tabWidget; QWidget *m_guiView; QWidget *m_iioView; + QWidget *m_titleContainer; QLabel *m_titleLabel; + + // TODO: make this an X/+ icon + QPushButton *m_readBtn; + QPushButton *m_addToWatchlistBtn; }; } // namespace scopy::iiodebugplugin diff --git a/plugins/iiodebugplugin/include/iiodebugplugin/iiodebuginstrument.h b/plugins/iiodebugplugin/include/iiodebugplugin/iiodebuginstrument.h index 4bb137fd97..fea6a6fd9d 100644 --- a/plugins/iiodebugplugin/include/iiodebugplugin/iiodebuginstrument.h +++ b/plugins/iiodebugplugin/include/iiodebugplugin/iiodebuginstrument.h @@ -60,8 +60,6 @@ private Q_SLOTS: IIOSortFilterProxyModel *m_proxyModel; WatchListView *m_watchListView; ApiObject *m_apiObject; - QPushButton *m_readBtn; - QPushButton *m_addToWatchlistBtn; IIOStandardItem *m_currentlySelectedItem; SaveContextSetup *m_saveContextSetup; diff --git a/plugins/iiodebugplugin/include/iiodebugplugin/iiomodel.h b/plugins/iiodebugplugin/include/iiodebugplugin/iiomodel.h index d62c178e82..39e04debba 100644 --- a/plugins/iiodebugplugin/include/iiodebugplugin/iiomodel.h +++ b/plugins/iiodebugplugin/include/iiodebugplugin/iiomodel.h @@ -20,6 +20,7 @@ class IIOModel : public QObject private: void iioTreeSetup(); + void setupCtx(); void generateCtxAttributes(); void setupCurrentDevice(); void generateDeviceAttributes(); @@ -46,6 +47,7 @@ class IIOModel : public QObject int m_currentDeviceIndex; int m_currentChannelIndex; + QList m_ctxList; QList m_devList; QList m_chnlList; }; diff --git a/plugins/iiodebugplugin/include/iiodebugplugin/iiostandarditem.h b/plugins/iiodebugplugin/include/iiodebugplugin/iiostandarditem.h index 1c26ef3a5b..97ffde124b 100644 --- a/plugins/iiodebugplugin/include/iiodebugplugin/iiostandarditem.h +++ b/plugins/iiodebugplugin/include/iiodebugplugin/iiostandarditem.h @@ -63,6 +63,8 @@ class IIOStandardItem : public QStandardItem bool isWatched(); void setWatched(bool isWatched); + QString typeString(); + private: void buildDetails(); void generateToolTip(); diff --git a/plugins/iiodebugplugin/include/iiodebugplugin/watchlistentry.h b/plugins/iiodebugplugin/include/iiodebugplugin/watchlistentry.h index a1ec441283..d761807dbf 100644 --- a/plugins/iiodebugplugin/include/iiodebugplugin/watchlistentry.h +++ b/plugins/iiodebugplugin/include/iiodebugplugin/watchlistentry.h @@ -19,24 +19,37 @@ class WatchListEntry : public QObject QTableWidgetItem *name(); void setName(QString name); - QTableWidgetItem *value(); - void setValue(QString value); + // QTableWidgetItem *value(); + // void setValue(QString value); QTableWidgetItem *path(); void setPath(QString path); IIOStandardItem *item(); + QTableWidgetItem *type() const; + void setType(QString type); + + // the value entry can only be lineedit or combo box, other options do not have enough space to look good + QWidget *valueUi() const; + void setValueUi(QWidget *newValueUi); + private Q_SLOTS: void setNewData(QString data, QString optionalData); private: void setupUi(); + void setupWidget(IIOWidget *widget); IIOStandardItem *m_item; QTableWidgetItem *m_name; - QTableWidgetItem *m_value; + // QTableWidgetItem *m_value; + QWidget *m_valueUi; + QTableWidgetItem *m_type; QTableWidgetItem *m_path; + + QComboBox *m_combo; + QLineEdit *m_lineedit; }; } // namespace scopy::iiodebugplugin diff --git a/plugins/iiodebugplugin/include/iiodebugplugin/watchlistview.h b/plugins/iiodebugplugin/include/iiodebugplugin/watchlistview.h index cfc7634258..917e358771 100644 --- a/plugins/iiodebugplugin/include/iiodebugplugin/watchlistview.h +++ b/plugins/iiodebugplugin/include/iiodebugplugin/watchlistview.h @@ -35,7 +35,7 @@ public Q_SLOTS: void resizeEvent(QResizeEvent *event) override; private: - QList m_offsets = {0, 0, 0, 0}; // TODO: prettify + QList m_offsets = {0, 0, 0, 0, 0}; // TODO: prettify ApiObject *m_apiObject; QMap m_entryObjects; diff --git a/plugins/iiodebugplugin/src/detailsview.cpp b/plugins/iiodebugplugin/src/detailsview.cpp index c47df77c2a..039cf46295 100644 --- a/plugins/iiodebugplugin/src/detailsview.cpp +++ b/plugins/iiodebugplugin/src/detailsview.cpp @@ -1,6 +1,9 @@ #include "detailsview.h" #include +#define ADD_ICON ":/gui/icons/launcher_add.svg" +#define REMOVE_ICON ":/gui/icons/close_hovered.svg" + using namespace scopy::iiodebugplugin; DetailsView::DetailsView(QWidget *parent) @@ -11,6 +14,9 @@ DetailsView::DetailsView(QWidget *parent) , m_tabWidget(new QTabWidget(this)) , m_guiView(new QWidget(this)) , m_iioView(new QWidget(this)) + , m_readBtn(new QPushButton("Read", this)) + , m_addToWatchlistBtn(new QPushButton(this)) + , m_titleContainer(new QWidget(this)) { setupUi(); } @@ -20,11 +26,20 @@ void DetailsView::setupUi() setLayout(new QVBoxLayout(this)); layout()->setContentsMargins(0, 6, 0, 0); + m_titleContainer->setLayout(new QHBoxLayout(this)); + m_titleContainer->layout()->setContentsMargins(0, 0, 0, 0); + m_titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_titleLabel->setStyleSheet("color: white;"); m_titleLabel->setAlignment(Qt::AlignCenter); m_titleLabel->setStyleSheet("font-size: 14pt"); + m_readBtn->setFixedWidth(50); + m_addToWatchlistBtn->setFixedWidth(50); + m_addToWatchlistBtn->setDisabled(true); + // m_addToWatchlistBtn->setIcon(QIcon(ADD_ICON)); + // m_addToWatchlistBtn->setIconSize(QSize(30, 30)); + m_guiView->setLayout(new QVBoxLayout(m_guiView)); m_iioView->setLayout(new QVBoxLayout(m_iioView)); @@ -38,12 +53,20 @@ void DetailsView::setupUi() m_tabWidget->addTab(m_iioView, "IIO View"); m_tabWidget->tabBar()->setDocumentMode(true); m_tabWidget->tabBar()->setExpanding(true); + // TODO: this will move to StyleHelper QString style = "QTabBar::tab:selected { border-bottom-color: &&ScopyBlue&&; }"; style.replace("&&ScopyBlue&&", StyleHelper::getColor("ScopyBlue")); m_tabWidget->setStyleSheet(style); + StyleHelper::BlueButton(m_readBtn, "ReadCurrentSelectionButton"); + StyleHelper::BlueButton(m_addToWatchlistBtn, "AddToWatchlistButton"); - layout()->addWidget(m_titleLabel); + m_titleContainer->layout()->addWidget(m_titleLabel); + m_titleContainer->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred)); + m_titleContainer->layout()->addWidget(m_addToWatchlistBtn); + m_titleContainer->layout()->addWidget(m_readBtn); + + layout()->addWidget(m_titleContainer); layout()->addWidget(m_tabWidget); } @@ -55,3 +78,25 @@ void DetailsView::setIIOStandardItem(IIOStandardItem *item) } void DetailsView::refreshIIOView() { m_cliDetailsView->refreshView(); } + +QPushButton *DetailsView::readBtn() +{ + return m_readBtn; +} + +QPushButton *DetailsView::addToWatchlistBtn() +{ + return m_addToWatchlistBtn; +} + +void DetailsView::setAddToWatchlistState(bool add) +{ + m_addToWatchlistBtn->setEnabled(true); + if (add) { + m_addToWatchlistBtn->setIcon(QIcon(ADD_ICON)); + m_addToWatchlistBtn->setIconSize(QSize(30, 30)); + } else { + m_addToWatchlistBtn->setIcon(QIcon(REMOVE_ICON)); + m_addToWatchlistBtn->setIconSize(QSize(15, 15)); + } +} diff --git a/plugins/iiodebugplugin/src/guidetailsview.cpp b/plugins/iiodebugplugin/src/guidetailsview.cpp index c87640fd24..9cae3802ae 100644 --- a/plugins/iiodebugplugin/src/guidetailsview.cpp +++ b/plugins/iiodebugplugin/src/guidetailsview.cpp @@ -28,7 +28,7 @@ void GuiDetailsView::setupUi() m_attrSeparator->getContentWidget()->layout()->addWidget(m_scrollArea); m_attrSeparator->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); - m_detailsSeparator->setLabel("Device info"); + m_detailsSeparator->setLabel("General info"); m_detailsSeparator->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); layout()->addWidget(m_attrSeparator); @@ -53,6 +53,8 @@ void GuiDetailsView::setIIOStandardItem(IIOStandardItem *item) m_detailsList.append(label); m_detailsSeparator->getContentWidget()->layout()->addWidget(label); } + + m_detailsSeparator->setLabel(m_currentItem->typeString() + " info"); } void GuiDetailsView::clearWidgets() diff --git a/plugins/iiodebugplugin/src/iiodebuginstrument.cpp b/plugins/iiodebugplugin/src/iiodebuginstrument.cpp index 9eb911da2e..bd7bcb083a 100644 --- a/plugins/iiodebugplugin/src/iiodebuginstrument.cpp +++ b/plugins/iiodebugplugin/src/iiodebuginstrument.cpp @@ -66,15 +66,13 @@ void IIODebugInstrument::setupUi() m_proxyModel = new IIOSortFilterProxyModel(this); m_treeView = new QTreeView(bottom_container); // m_saveContextSetup = new SaveContextSetup(m_treeView, bottom_container); - m_iioModel = new IIOModel(m_context, m_uri, m_treeView); + // m_iioModel = new IIOModel(m_context, m_uri, m_treeView); + + // TODO: see what to do with context0 when multiple simultaneous connections are available + m_iioModel = new IIOModel(m_context, "context0", m_treeView); m_searchBar = new SearchBar(m_iioModel->getEntries(), this); m_detailsView = new DetailsView(details_container); m_watchListView = new WatchListView(watch_list); - m_readBtn = new QPushButton("Read Current", this); - m_addToWatchlistBtn = new QPushButton("Add to Watchlist", this); - - m_readBtn->setFixedWidth(200); - m_addToWatchlistBtn->setFixedWidth(200); watch_list->layout()->setContentsMargins(0, 0, 0, 0); watch_list->layout()->addWidget(m_watchListView); @@ -86,9 +84,8 @@ void IIODebugInstrument::setupUi() StyleHelper::BackgroundPage(watch_list, "WatchListContainer"); StyleHelper::BackgroundPage(tree_view_container, "TreeViewContainer"); StyleHelper::BackgroundPage(search_bar_container, "SearchBarContainer"); - StyleHelper::BlueButton(m_readBtn, "ReadCurrentSelectionButton"); - StyleHelper::BlueButton(m_addToWatchlistBtn, "AddToWatchlistButton"); + // TODO: move this to stylehelper m_HSplitter->setStyleSheet( // "QSplitter::handle { background-color: transparent; }" "QSplitter::handle:horizontal { width: 6px; }" @@ -115,8 +112,6 @@ void IIODebugInstrument::setupUi() details_container->layout()->addWidget(m_detailsView); tree_view_container->layout()->addWidget(m_treeView); search_bar_container->layout()->addWidget(m_searchBar); - search_bar_container->layout()->addWidget(m_addToWatchlistBtn); - search_bar_container->layout()->addWidget(m_readBtn); layout()->addWidget(search_bar_container); layout()->addWidget(bottom_container); @@ -153,13 +148,13 @@ void IIODebugInstrument::connectSignalsAndSlots() m_detailsView->setIIOStandardItem(item); }); - QObject::connect(m_readBtn, &QPushButton::clicked, this, [this]() { + QObject::connect(m_detailsView->readBtn(), &QPushButton::clicked, this, [this]() { qInfo(CAT_IIODEBUGINSTRUMENT) << "Read button pressed."; triggerReadOnAllChildItems(m_currentlySelectedItem); m_detailsView->refreshIIOView(); }); - QObject::connect(m_addToWatchlistBtn, &QPushButton::clicked, this, [this]() { + QObject::connect(m_detailsView->addToWatchlistBtn(), &QPushButton::clicked, this, [this]() { if(m_currentlySelectedItem == nullptr) { qInfo(CAT_IIODEBUGINSTRUMENT) << "No item selected, doing nothing."; return; @@ -168,11 +163,11 @@ void IIODebugInstrument::connectSignalsAndSlots() if(m_currentlySelectedItem->isWatched()) { m_currentlySelectedItem->setWatched(false); m_watchListView->removeFromWatchlist(m_currentlySelectedItem); - m_addToWatchlistBtn->setText("Add to Watchlist"); + m_detailsView->setAddToWatchlistState(true); } else { m_currentlySelectedItem->setWatched(true); m_watchListView->addToWatchlist(m_currentlySelectedItem); - m_addToWatchlistBtn->setText("Remove from Watchlist"); + m_detailsView->setAddToWatchlistState(false); } }); } @@ -309,7 +304,7 @@ void IIODebugInstrument::applySelection(const QItemSelection &selected, const QI m_currentlySelectedItem = iioItem; if(iioItem) { - m_addToWatchlistBtn->setText(iioItem->isWatched() ? "Remove from Watchlist" : "Add to Watchlist"); + m_detailsView->setAddToWatchlistState(!iioItem->isWatched()); m_detailsView->setIIOStandardItem(iioItem); m_watchListView->currentTreeSelectionChanged(iioItem); } diff --git a/plugins/iiodebugplugin/src/iiomodel.cpp b/plugins/iiodebugplugin/src/iiomodel.cpp index ab0cf285da..701ba62367 100644 --- a/plugins/iiodebugplugin/src/iiomodel.cpp +++ b/plugins/iiodebugplugin/src/iiomodel.cpp @@ -24,13 +24,12 @@ QSet IIOModel::getEntries() { return m_entries; } void IIOModel::iioTreeSetup() { m_rootString = m_uri; - generateCtxAttributes(); + setupCtx(); // add all devices from context, dfs uint ctx_devices_count = iio_context_get_devices_count(m_ctx); for(m_currentDeviceIndex = 0; m_currentDeviceIndex < ctx_devices_count; ++m_currentDeviceIndex) { setupCurrentDevice(); - generateDeviceAttributes(); // add all channels to current device uint device_channels_count = iio_device_get_channels_count(m_currentDevice); @@ -41,22 +40,27 @@ void IIOModel::iioTreeSetup() // add channel to device m_currentDeviceItem->appendRow(m_currentChannelItem); } + generateDeviceAttributes(); // add device to ctx m_rootItem->appendRow(m_currentDeviceItem); } + generateCtxAttributes(); m_model->appendRow(m_rootItem); } -void IIOModel::generateCtxAttributes() +void IIOModel::setupCtx() { - QList ctxList = IIOWidgetFactory::buildAllAttrsForContext(m_ctx); - m_rootItem = new IIOStandardItem(ctxList, m_rootString, m_rootString, IIOStandardItem::Context); + m_ctxList = IIOWidgetFactory::buildAllAttrsForContext(m_ctx); + m_rootItem = new IIOStandardItem(m_ctxList, m_rootString, m_rootString, IIOStandardItem::Context); m_rootItem->setEditable(false); +} +void IIOModel::generateCtxAttributes() +{ // add attrs from context - for(IIOWidget *ctxWidget : ctxList) { + for(IIOWidget *ctxWidget : m_ctxList) { m_entries.insert(ctxWidget->getRecipe().data); auto *attrItem = new IIOStandardItem({ctxWidget}, ctxWidget->getRecipe().data, m_rootString + SEPARATOR + ctxWidget->getRecipe().data, diff --git a/plugins/iiodebugplugin/src/iiostandarditem.cpp b/plugins/iiodebugplugin/src/iiostandarditem.cpp index b41d8bc749..02b6bae9eb 100644 --- a/plugins/iiodebugplugin/src/iiostandarditem.cpp +++ b/plugins/iiodebugplugin/src/iiostandarditem.cpp @@ -25,7 +25,7 @@ IIOStandardItem::IIOStandardItem(QList widgets, QString name, QStri } IIOStandardItem::IIOStandardItem(QList widgets, QString name, QString id, QString path, Type type) - : QStandardItem((!id.isEmpty()) ? id + ": " + name : name) + : QStandardItem((!name.isEmpty()) ? id + ": " + name : id) , m_device(nullptr) , m_channel(nullptr) , m_iioWidgets(widgets) @@ -99,6 +99,35 @@ bool IIOStandardItem::isWatched() { return m_isWatched; } void IIOStandardItem::setWatched(bool isWatched) { m_isWatched = isWatched; } +QString IIOStandardItem::typeString() +{ + switch(m_type) { + case IIOStandardItem::Context: { + return "Context"; + } + case IIOStandardItem::ContextAttribute: { + return "Context Attribute"; + } + case IIOStandardItem::Trigger: { + return "Trigger"; + } + case IIOStandardItem::Device: { + return "Device"; + } + case IIOStandardItem::DeviceAttribute: { + return "Device Attribute"; + } + case IIOStandardItem::Channel: { + return "Channel"; + } + case IIOStandardItem::ChannelAttribute: { + return "Channel Attribute"; + } + default: + return ""; + } +} + void IIOStandardItem::buildDetails() { if(!m_iioWidgets.empty()) { @@ -121,38 +150,7 @@ void IIOStandardItem::buildDetails() void IIOStandardItem::generateToolTip() { - switch(m_type) { - case IIOStandardItem::Context: { - setToolTip("Context"); - break; - } - case IIOStandardItem::ContextAttribute: { - setToolTip("Context Attribute"); - break; - } - case IIOStandardItem::Trigger: { - setToolTip("Trigger"); - break; - } - case IIOStandardItem::Device: { - setToolTip("Device"); - break; - } - case IIOStandardItem::DeviceAttribute: { - setToolTip("Device Attribute"); - break; - } - case IIOStandardItem::Channel: { - setToolTip("Channel"); - break; - } - case IIOStandardItem::ChannelAttribute: { - setToolTip("Channel Attribute"); - break; - } - default: - break; - } + setToolTip(typeString()); } void IIOStandardItem::extractDataFromDevice() diff --git a/plugins/iiodebugplugin/src/watchlistentry.cpp b/plugins/iiodebugplugin/src/watchlistentry.cpp index bbfa391aab..37ae9957c2 100644 --- a/plugins/iiodebugplugin/src/watchlistentry.cpp +++ b/plugins/iiodebugplugin/src/watchlistentry.cpp @@ -8,24 +8,33 @@ WatchListEntry::WatchListEntry(IIOStandardItem *item, QObject *parent) : QObject(parent) , m_item(item) , m_name(new QTableWidgetItem()) - , m_value(new QTableWidgetItem()) + // , m_value(new QTableWidgetItem()) + , m_type(new QTableWidgetItem()) , m_path(new QTableWidgetItem()) { setupUi(); - m_name->setText(item->name()); + m_name->setText(item->text()); + m_type->setText(item->typeString()); m_path->setText(item->path()); + m_valueUi = nullptr; + m_combo = nullptr; + m_lineedit = nullptr; + IIOStandardItem::Type type = item->type(); if(type == IIOStandardItem::ContextAttribute || type == IIOStandardItem::DeviceAttribute || type == IIOStandardItem::ChannelAttribute) { // it is a leaf node so it has only 1 widget QList widgets = item->getIIOWidgets(); IIOWidget *widget = widgets[0]; - m_value->setText(widget->getDataStrategy()->data()); - QObject::connect(dynamic_cast(widget->getDataStrategy()), SIGNAL(sendData(QString, QString)), - this, SLOT(setNewData(QString, QString))); + setupWidget(widget); + // m_valueUi = widget->getUiStrategy()->ui(); + // m_value->setText(widget->getDataStrategy()->data()); + // QObject::connect(dynamic_cast(widget->getDataStrategy()), SIGNAL(sendData(QString, QString)), + // this, SLOT(setNewData(QString, QString))); } else { - m_value->setText("N/A"); + // m_value->setText("N/A"); + m_valueUi = new QLabel("N/A"); } } @@ -40,9 +49,9 @@ QTableWidgetItem *WatchListEntry::name() { return m_name; } void WatchListEntry::setName(QString name) { m_name->setText(name); } -QTableWidgetItem *WatchListEntry::value() { return m_value; } +// QTableWidgetItem *WatchListEntry::value() { return m_value; } -void WatchListEntry::setValue(QString value) { m_value->setText(value); } +// void WatchListEntry::setValue(QString value) { m_value->setText(value); } QTableWidgetItem *WatchListEntry::path() { return m_path; } @@ -53,13 +62,38 @@ IIOStandardItem *WatchListEntry::item() { return m_item; } void WatchListEntry::setNewData(QString data, QString optionalData) { Q_UNUSED(optionalData) - m_value->setText(data); + // m_value->setText(data); } void WatchListEntry::setupUi() { - // implement if needed m_name->setFlags(m_name->flags() ^ Qt::ItemIsEditable); - m_value->setFlags(m_value->flags() ^ Qt::ItemIsEditable); + // m_value->setFlags(m_value->flags() ^ Qt::ItemIsEditable); + m_type->setFlags(m_type->flags() ^ Qt::ItemIsEditable); m_path->setFlags(m_path->flags() ^ Qt::ItemIsEditable); } + +void WatchListEntry::setupWidget(IIOWidget *widget) +{ + +} + +QWidget *WatchListEntry::valueUi() const +{ + return m_valueUi; +} + +void WatchListEntry::setValueUi(QWidget *newValueUi) +{ + m_valueUi = newValueUi; +} + +QTableWidgetItem *WatchListEntry::type() const +{ + return m_type; +} + +void WatchListEntry::setType(QString type) +{ + m_type->setText(type); +} diff --git a/plugins/iiodebugplugin/src/watchlistview.cpp b/plugins/iiodebugplugin/src/watchlistview.cpp index 386f41a0bf..88dfb0aee0 100644 --- a/plugins/iiodebugplugin/src/watchlistview.cpp +++ b/plugins/iiodebugplugin/src/watchlistview.cpp @@ -7,9 +7,10 @@ #define NAME_POS 0 #define VALUE_POS 1 -#define PATH_POS 2 -#define CLOSE_BTN_POS 3 -#define DIVISION_REGION 4 +#define TYPE_POS 2 +#define PATH_POS 3 +#define CLOSE_BTN_POS 4 +#define DIVISION_REGION 5 Q_LOGGING_CATEGORY(CAT_WATCHLISTVIEW, "WatchListView") using namespace scopy::iiodebugplugin; @@ -25,7 +26,7 @@ WatchListView::WatchListView(QWidget *parent) void WatchListView::setupUi() { - QStringList headers = {"Name", "Value", "Path", ""}; + QStringList headers = {"Name", "Value", "Type", "Path", ""}; setColumnCount(headers.size()); setHorizontalHeaderLabels(headers); verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); @@ -40,6 +41,7 @@ void WatchListView::setupUi() header->setCascadingSectionResizes(true); header->setSectionResizeMode(NAME_POS, QHeaderView::Interactive); header->setSectionResizeMode(VALUE_POS, QHeaderView::Interactive); + header->setSectionResizeMode(TYPE_POS, QHeaderView::Interactive); header->setSectionResizeMode(PATH_POS, QHeaderView::Interactive); header->setSectionResizeMode(CLOSE_BTN_POS, QHeaderView::Interactive); @@ -108,13 +110,18 @@ void WatchListView::addToWatchlist(IIOStandardItem *item) int row = rowCount(); insertRow(row); setItem(row, NAME_POS, entry->name()); - setItem(row, VALUE_POS, entry->value()); + // setItem(row, VALUE_POS, entry->value()); + setCellWidget(row, VALUE_POS, entry->valueUi()); + setItem(row, TYPE_POS, entry->type()); setItem(row, PATH_POS, entry->path()); + selectRow(row); auto deleteButton = new QPushButton("X"); setCellWidget(row, CLOSE_BTN_POS, deleteButton); deleteButton->setContentsMargins(0, 0, 0, 0); QObject::connect(deleteButton, &QPushButton::clicked, this, [this, entry]() { + // TODO: also delete the value widget (or not cause it is an IIOWidget) + // TODO: move the creation of the delete button to WatchListEntry int row = -1; for(int i = 0; i < rowCount(); ++i) { if(this->item(i, PATH_POS)->text() == entry->path()->text()) { @@ -175,6 +182,7 @@ void WatchListView::resizeEvent(QResizeEvent *event) int sectionWidth = w / DIVISION_REGION; setColumnWidth(NAME_POS, sectionWidth + m_offsets[NAME_POS]); setColumnWidth(VALUE_POS, sectionWidth + m_offsets[VALUE_POS]); + setColumnWidth(TYPE_POS, sectionWidth + m_offsets[TYPE_POS]); setColumnWidth(PATH_POS, sectionWidth + m_offsets[PATH_POS]); setColumnWidth(CLOSE_BTN_POS, sectionWidth + m_offsets[CLOSE_BTN_POS]);