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 22, 2024
1 parent 08c1634 commit 7ef7d21
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 65 deletions.
8 changes: 8 additions & 0 deletions plugins/iiodebugplugin/include/iiodebugplugin/detailsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class DetailsView : public QWidget
void setIIOStandardItem(IIOStandardItem *item);
void refreshIIOView();

QPushButton *readBtn();
QPushButton *addToWatchlistBtn();

private:
void setupUi();

Expand All @@ -27,7 +30,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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class WatchListEntry : public QObject

IIOStandardItem *item();

QTableWidgetItem *type() const;
void setType(QString type);

private Q_SLOTS:
void setNewData(QString data, QString optionalData);

Expand All @@ -36,6 +39,7 @@ private Q_SLOTS:
IIOStandardItem *m_item;
QTableWidgetItem *m_name;
QTableWidgetItem *m_value;
QTableWidgetItem *m_type;
QTableWidgetItem *m_path;
};
} // 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
29 changes: 28 additions & 1 deletion plugins/iiodebugplugin/src/detailsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 +23,17 @@ 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_guiView->setLayout(new QVBoxLayout(m_guiView));
m_iioView->setLayout(new QVBoxLayout(m_iioView));

Expand All @@ -38,12 +47,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 +72,13 @@ void DetailsView::setIIOStandardItem(IIOStandardItem *item)
}

void DetailsView::refreshIIOView() { m_cliDetailsView->refreshView(); }

QPushButton *DetailsView::readBtn()
{
return m_readBtn;
}

QPushButton *DetailsView::addToWatchlistBtn()
{
return m_addToWatchlistBtn;
}
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->addToWatchlistBtn()->setText("+");
} else {
m_currentlySelectedItem->setWatched(true);
m_watchListView->addToWatchlist(m_currentlySelectedItem);
m_addToWatchlistBtn->setText("Remove from Watchlist");
m_detailsView->addToWatchlistBtn()->setText("X");
}
});
}
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->addToWatchlistBtn()->setText(iioItem->isWatched() ? "X" : "+");
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
64 changes: 31 additions & 33 deletions plugins/iiodebugplugin/src/iiostandarditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ IIOStandardItem::IIOStandardItem(QList<IIOWidget *> widgets, QString name, QStri
}

IIOStandardItem::IIOStandardItem(QList<IIOWidget *> 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)
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()
Expand Down
Loading

0 comments on commit 7ef7d21

Please sign in to comment.