Skip to content

Commit

Permalink
wip, small ui fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei-Fabian-Pop <[email protected]>
  • Loading branch information
Andrei-Fabian-Pop committed Mar 25, 2024
1 parent 08c1634 commit 5cbf3b3
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 78 deletions.
11 changes: 11 additions & 0 deletions plugins/iiodebugplugin/include/iiodebugplugin/detailsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions plugins/iiodebugplugin/include/iiodebugplugin/iiomodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IIOModel : public QObject

private:
void iioTreeSetup();
void setupCtx();
void generateCtxAttributes();
void setupCurrentDevice();
void generateDeviceAttributes();
Expand All @@ -46,6 +47,7 @@ class IIOModel : public QObject
int m_currentDeviceIndex;
int m_currentChannelIndex;

QList<IIOWidget *> m_ctxList;
QList<IIOWidget *> m_devList;
QList<IIOWidget *> m_chnlList;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class IIOStandardItem : public QStandardItem
bool isWatched();
void setWatched(bool isWatched);

QString typeString();

private:
void buildDetails();
void generateToolTip();
Expand Down
19 changes: 16 additions & 3 deletions plugins/iiodebugplugin/include/iiodebugplugin/watchlistentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Q_SLOTS:
void resizeEvent(QResizeEvent *event) override;

private:
QList<int> m_offsets = {0, 0, 0, 0}; // TODO: prettify
QList<int> m_offsets = {0, 0, 0, 0, 0}; // TODO: prettify

ApiObject *m_apiObject;
QMap<QString, WatchListEntry *> m_entryObjects;
Expand Down
47 changes: 46 additions & 1 deletion plugins/iiodebugplugin/src/detailsview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "detailsview.h"
#include <QVBoxLayout>

#define ADD_ICON ":/gui/icons/launcher_add.svg"
#define REMOVE_ICON ":/gui/icons/close_hovered.svg"

using namespace scopy::iiodebugplugin;

DetailsView::DetailsView(QWidget *parent)
Expand All @@ -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();
}
Expand All @@ -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));

Expand All @@ -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);
}

Expand All @@ -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));
}
}
4 changes: 3 additions & 1 deletion plugins/iiodebugplugin/src/guidetailsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down
25 changes: 10 additions & 15 deletions plugins/iiodebugplugin/src/iiodebuginstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; }"
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
});
}
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 10 additions & 6 deletions plugins/iiodebugplugin/src/iiomodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ QSet<QString> 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);
Expand All @@ -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<IIOWidget *> 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,
Expand Down
Loading

0 comments on commit 5cbf3b3

Please sign in to comment.