-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add metadata display core plugin
- Loading branch information
1 parent
50ed7c7
commit cde80f0
Showing
7 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2020-10-21T16:04:43.815Z | ||
# | ||
#------------------------------------------------- | ||
|
||
QT += widgets | ||
|
||
QT -= gui | ||
|
||
TARGET = Metadata | ||
TEMPLATE = lib | ||
|
||
DEFINES += METADATA_LIBRARY | ||
|
||
CONFIG += c++11 plugin | ||
CONFIG -= debug_and_release_target | ||
|
||
# The following define makes your compiler emit warnings if you use | ||
# any feature of Qt which has been marked as deprecated (the exact warnings | ||
# depend on your compiler). Please consult the documentation of the | ||
# deprecated API in order to know how to port your code away from it. | ||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
# You can also make your code fail to compile if you use deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
# You can also select to disable deprecated APIs only up to a certain version of Qt. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
SOURCES += metadata.cpp metadatawidget.cpp | ||
|
||
HEADERS += metadata.h metadatawidget.h | ||
|
||
FORMS += \ | ||
metadatawidget.ui | ||
|
||
DISTFILES += | ||
|
||
RESOURCES += | ||
|
||
LIBS += -L$$OUT_PWD/../../../hobbits-core/ -lhobbits-core | ||
LIBS += -L$$OUT_PWD/../../../hobbits-widgets/ -lhobbits-widgets | ||
INCLUDEPATH += $$PWD/../../../hobbits-core $$PWD/../../../hobbits-widgets | ||
DEPENDPATH += $$PWD/../../../hobbits-core $$PWD/../../../hobbits-widgets | ||
|
||
unix:!mac { | ||
QMAKE_LFLAGS_RPATH= | ||
QMAKE_LFLAGS += "-Wl,-rpath,'$$ORIGIN/../../lib:$$ORIGIN'" | ||
} | ||
|
||
mac { | ||
QMAKE_LFLAGS_RPATH= | ||
QMAKE_LFLAGS += "-Wl,-rpath,'@executable_path/../Frameworks'" | ||
} | ||
|
||
unix { | ||
target.path = $$(HOME)/.local/share/hobbits/plugins/displays | ||
INSTALLS += target | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "metadata.h" | ||
|
||
Metadata::Metadata() : | ||
m_displayWidget(nullptr) | ||
{ | ||
|
||
} | ||
|
||
DisplayInterface* Metadata::createDefaultDisplay() | ||
{ | ||
return new Metadata(); | ||
} | ||
|
||
QString Metadata::name() | ||
{ | ||
return "Metadata"; | ||
} | ||
|
||
QString Metadata::description() | ||
{ | ||
return "Displays bit container metadata"; | ||
} | ||
|
||
QStringList Metadata::tags() | ||
{ | ||
return {"Generic"}; | ||
} | ||
|
||
QWidget* Metadata::display(QSharedPointer<DisplayHandle> displayHandle) | ||
{ | ||
initialize(displayHandle); | ||
return m_displayWidget; | ||
} | ||
|
||
QWidget* Metadata::controls(QSharedPointer<DisplayHandle> displayHandle) | ||
{ | ||
initialize(displayHandle); | ||
return nullptr; | ||
} | ||
|
||
void Metadata::initialize(QSharedPointer<DisplayHandle> displayHandle) | ||
{ | ||
if (!m_displayWidget) { | ||
m_displayWidget = new MetadataWidget(displayHandle, this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef METADATA_H | ||
#define METADATA_H | ||
|
||
#include "displayinterface.h" | ||
#include "metadatawidget.h" | ||
|
||
class Metadata : public QObject, DisplayInterface | ||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA(IID "hobbits.DisplayInterface.Metadata") | ||
Q_INTERFACES(DisplayInterface) | ||
|
||
public: | ||
Metadata(); | ||
|
||
DisplayInterface* createDefaultDisplay() override; | ||
|
||
QString name() override; | ||
QString description() override; | ||
QStringList tags() override; | ||
|
||
QWidget* display(QSharedPointer<DisplayHandle> displayHandle) override; | ||
QWidget* controls(QSharedPointer<DisplayHandle> displayHandle) override; | ||
|
||
private: | ||
void initialize(QSharedPointer<DisplayHandle> displayHandle); | ||
MetadataWidget* m_displayWidget; | ||
}; | ||
|
||
#endif // METADATA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "metadatawidget.h" | ||
|
||
#include <QPainter> | ||
#include <QImage> | ||
#include "displayhelper.h" | ||
#include "ui_metadatawidget.h" | ||
#include <QLineEdit> | ||
#include <QPlainTextEdit> | ||
#include <QScrollBar> | ||
|
||
MetadataWidget::MetadataWidget( | ||
QSharedPointer<DisplayHandle> displayHandle, | ||
DisplayInterface *pluginRef, | ||
QWidget *parent) : | ||
QWidget(parent), | ||
ui(new Ui::MetadataWidget()), | ||
m_displayHandle(displayHandle), | ||
m_pluginRef(pluginRef) | ||
{ | ||
ui->setupUi(this); | ||
|
||
connect(m_displayHandle.data(), SIGNAL(containerChanged()), this, SLOT(adjustData())); | ||
connect(m_displayHandle.data(), | ||
SIGNAL(newFocusDisplays(QSet<DisplayInterface*>)), | ||
this, | ||
SLOT(checkFocus(QSet<DisplayInterface*>))); | ||
connect(m_displayHandle.data(), SIGNAL(newBitContainer()), this, SLOT(adjustData())); | ||
} | ||
|
||
void MetadataWidget::checkFocus(QSet<DisplayInterface *> displays) | ||
{ | ||
if (displays.contains(m_pluginRef)) { | ||
this->adjustData(); | ||
} | ||
} | ||
|
||
void MetadataWidget::adjustData() | ||
{ | ||
if (!m_displayHandle->getCurrentFocusDisplays().contains(m_pluginRef)) { | ||
return; | ||
} | ||
|
||
while (ui->formLayout->rowCount() > 0) { | ||
ui->formLayout->removeRow(0); | ||
} | ||
|
||
if (m_displayHandle->getCurrentFocusDisplays().size() == 1) { | ||
m_displayHandle->getHScroll()->setVisible(false); | ||
m_displayHandle->getVScroll()->setVisible(false); | ||
} | ||
|
||
auto container = m_displayHandle->getContainer(); | ||
if (container.isNull()) { | ||
return; | ||
} | ||
|
||
for (auto key: container->info()->metadataKeys()) { | ||
QVariant metadata = container->info()->metadata(key); | ||
QString s = metadata.toString(); | ||
if (s.size() < 100) { | ||
QLineEdit *lineEdit = new QLineEdit(); | ||
lineEdit->setText(s); | ||
lineEdit->setReadOnly(true); | ||
ui->formLayout->addRow(key, lineEdit); } | ||
else { | ||
auto textEdit = new QPlainTextEdit(); | ||
textEdit->setPlainText(s); | ||
textEdit->setReadOnly(true); | ||
ui->formLayout->addRow(key, textEdit); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef METADATAWIDGET_H | ||
#define METADATAWIDGET_H | ||
|
||
#include "displayhandle.h" | ||
#include <QWidget> | ||
|
||
namespace Ui | ||
{ | ||
class MetadataWidget; | ||
} | ||
class MetadataWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
MetadataWidget( | ||
QSharedPointer<DisplayHandle> displayHandle, | ||
DisplayInterface *pluginRef, | ||
QWidget *parent = nullptr); | ||
|
||
public slots: | ||
void checkFocus(QSet<DisplayInterface*>); | ||
void adjustData(); | ||
|
||
private: | ||
Ui::MetadataWidget *ui; | ||
QSharedPointer<DisplayHandle> m_displayHandle; | ||
DisplayInterface *m_pluginRef; | ||
}; | ||
|
||
#endif // METADATAWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MetadataWidget</class> | ||
<widget class="QWidget" name="MetadataWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>996</width> | ||
<height>1033</height> | ||
</rect> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<property name="leftMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="topMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="rightMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>0</number> | ||
</property> | ||
<item> | ||
<widget class="QScrollArea" name="scrollArea"> | ||
<property name="widgetResizable"> | ||
<bool>true</bool> | ||
</property> | ||
<widget class="QWidget" name="scrollAreaWidgetContents"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>994</width> | ||
<height>1031</height> | ||
</rect> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_2"> | ||
<item> | ||
<layout class="QFormLayout" name="formLayout"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ SUBDIRS += \ | |
FrequencyPlot \ | ||
HexView \ | ||
HilbertPlot \ | ||
Metadata \ | ||
Spectrogram \ | ||
SymbolRaster |