Skip to content

Commit 844dbc1

Browse files
committed
Adding new CSV view widget and modifing sub projects to work on linux
1 parent f532626 commit 844dbc1

14 files changed

+296
-17
lines changed

CsvViewer/CsvViewer.pro

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CONFIG += plugin debug_and_release
2+
TARGET = $$qtLibraryTarget(csvviewerplugin)
3+
TEMPLATE = lib
4+
5+
HEADERS = csvviewerplugin.h
6+
SOURCES = csvviewerplugin.cpp
7+
RESOURCES = icons.qrc
8+
LIBS += -L.
9+
10+
greaterThan(QT_MAJOR_VERSION, 4) {
11+
QT += designer
12+
} else {
13+
CONFIG += designer
14+
}
15+
16+
target.path = $$[QT_INSTALL_PLUGINS]/designer
17+
INSTALLS += target
18+
19+
include(csvviewer.pri)
20+
21+
unix {
22+
FILE=$$OUT_PWD/libcsvviewerplugin.so
23+
DEST=$$[QT_INSTALL_PLUGINS]/designer/
24+
QMAKE_POST_LINK += $$quote(cp $${FILE} $${DEST})
25+
}
26+
win32 {
27+
FILE=$$OUT_PWD/release/csvviewerplugin.dll
28+
FILE ~= s,/,\\,g
29+
DEST=$$[QT_INSTALL_PLUGINS]/designer
30+
DEST ~= s,/,\\,g
31+
system(mkdir $$DEST)
32+
33+
QMAKE_POST_LINK += \
34+
$$quote(cmd /c copy /Y $${FILE} $${DEST}$$escape_expand(\n\t))
35+
}
36+

CsvViewer/csv-file.png

5.45 KB
Loading

CsvViewer/csvviewer.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "csvviewer.h"
2+
#include "ui_csvviewer.h"
3+
#include <QDebug>
4+
#include <QFile>
5+
#include <QTextStream>
6+
7+
CsvViewer::CsvViewer(QWidget *parent) :
8+
QWidget(parent), m_ui(new Ui::CsvViewer), m_model(new QStandardItemModel)
9+
{
10+
m_ui->setupUi(this);
11+
m_ui->tableView->setModel(m_model);
12+
}
13+
QString CsvViewer::csvPath() const
14+
{
15+
return _csvPath;
16+
}
17+
void CsvViewer::setCsvPath(const QString &csvPath)
18+
{
19+
_csvPath = csvPath;
20+
this->loadCsv(_csvPath);
21+
}
22+
void CsvViewer::loadCsv(QString csvPath)
23+
{
24+
QFile file(csvPath);
25+
if (file.open(QIODevice::ReadOnly)) {
26+
int lineindex = 0; // file line counter
27+
QTextStream in(&file); // read to text stream
28+
29+
while (!in.atEnd()) {
30+
// read one line from textstream(separated by "\n")
31+
QString fileLine = in.readLine();
32+
33+
// parse the read line into separate pieces(tokens) with "," as the delimiter
34+
QStringList lineToken = fileLine.split(",", QString::SkipEmptyParts);
35+
36+
// load parsed data to model accordingly
37+
for (int j = 0; j < lineToken.size(); j++) {
38+
QString value = lineToken.at(j);
39+
QStandardItem *item = new QStandardItem(value);
40+
if (lineindex == 0){
41+
m_model->setHorizontalHeaderItem(j, item);
42+
} else {
43+
m_model->setItem(lineindex-1, j, item);
44+
}
45+
}
46+
47+
lineindex++;
48+
}
49+
50+
file.close();
51+
}
52+
}

CsvViewer/csvviewer.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef CSVVIEWER_H
2+
#define CSVVIEWER_H
3+
4+
#include <QWidget>
5+
#include <QStandardItemModel>
6+
#include <QTableView>
7+
8+
namespace Ui {
9+
class CsvViewer;
10+
}
11+
class CsvViewer : public QWidget
12+
{
13+
Q_OBJECT
14+
Q_PROPERTY(QString csvPath READ csvPath WRITE setCsvPath)
15+
16+
public:
17+
CsvViewer(QWidget *parent = 0);
18+
QString csvPath() const;
19+
void setCsvPath(const QString &csvPath);
20+
21+
private:
22+
Ui::CsvViewer *m_ui;
23+
QStandardItemModel *m_model;
24+
void loadCsv(QString csvPath);
25+
26+
protected:
27+
QString _csvPath;
28+
29+
};
30+
31+
#endif

CsvViewer/csvviewer.pri

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
HEADERS += csvviewer.h
2+
SOURCES += csvviewer.cpp
3+
4+
FORMS += \
5+
$$PWD/csvviewer.ui

CsvViewer/csvviewer.ui

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>CsvViewer</class>
4+
<widget class="QWidget" name="CsvViewer">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QTableView" name="tableView">
19+
<property name="sortingEnabled">
20+
<bool>true</bool>
21+
</property>
22+
</widget>
23+
</item>
24+
</layout>
25+
</widget>
26+
<resources/>
27+
<connections/>
28+
</ui>

CsvViewer/csvviewerplugin.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "csvviewer.h"
2+
#include "csvviewerplugin.h"
3+
4+
#include <QtPlugin>
5+
6+
CsvViewerPlugin::CsvViewerPlugin(QObject *parent)
7+
: QObject(parent)
8+
{
9+
m_initialized = false;
10+
}
11+
12+
void CsvViewerPlugin::initialize(QDesignerFormEditorInterface * /* core */)
13+
{
14+
if (m_initialized)
15+
return;
16+
17+
// Add extension registrations, etc. here
18+
19+
m_initialized = true;
20+
}
21+
22+
bool CsvViewerPlugin::isInitialized() const
23+
{
24+
return m_initialized;
25+
}
26+
27+
QWidget *CsvViewerPlugin::createWidget(QWidget *parent)
28+
{
29+
return new CsvViewer(parent);
30+
}
31+
32+
QString CsvViewerPlugin::name() const
33+
{
34+
return QLatin1String("CsvViewer");
35+
}
36+
37+
QString CsvViewerPlugin::group() const
38+
{
39+
return QLatin1String("Utilities");
40+
}
41+
42+
QIcon CsvViewerPlugin::icon() const
43+
{
44+
return QIcon(QLatin1String(":/csv-file.png"));
45+
}
46+
47+
QString CsvViewerPlugin::toolTip() const
48+
{
49+
return QLatin1String("This widget displays a CSV file in a table");
50+
}
51+
52+
QString CsvViewerPlugin::whatsThis() const
53+
{
54+
return QLatin1String("CsvViewer allows you to display CSV data on your UI");
55+
}
56+
57+
bool CsvViewerPlugin::isContainer() const
58+
{
59+
return false;
60+
}
61+
62+
QString CsvViewerPlugin::domXml() const
63+
{
64+
return QLatin1String("<widget class=\"CsvViewer\" name=\"csvViewer\">\n</widget>\n");
65+
}
66+
67+
QString CsvViewerPlugin::includeFile() const
68+
{
69+
return QLatin1String("csvviewer.h");
70+
}
71+
#if QT_VERSION < 0x050000
72+
Q_EXPORT_PLUGIN2(csvviewerplugin, CsvViewerPlugin)
73+
#endif // QT_VERSION < 0x050000

CsvViewer/csvviewerplugin.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef CSVVIEWERPLUGIN_H
2+
#define CSVVIEWERPLUGIN_H
3+
4+
#include <QtUiPlugin//QDesignerCustomWidgetInterface>
5+
6+
class CsvViewerPlugin : public QObject, public QDesignerCustomWidgetInterface
7+
{
8+
Q_OBJECT
9+
Q_INTERFACES(QDesignerCustomWidgetInterface)
10+
#if QT_VERSION >= 0x050000
11+
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
12+
#endif // QT_VERSION >= 0x050000
13+
14+
public:
15+
CsvViewerPlugin(QObject *parent = 0);
16+
17+
bool isContainer() const;
18+
bool isInitialized() const;
19+
QIcon icon() const;
20+
QString domXml() const;
21+
QString group() const;
22+
QString includeFile() const;
23+
QString name() const;
24+
QString toolTip() const;
25+
QString whatsThis() const;
26+
QWidget *createWidget(QWidget *parent);
27+
void initialize(QDesignerFormEditorInterface *core);
28+
29+
private:
30+
bool m_initialized;
31+
};
32+
33+
#endif

CsvViewer/icons.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/" >
3+
<file>csv-file.png</file>
4+
5+
</qresource>
6+
</RCC>

PingMonitor/PingMonitor.pro

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ INSTALLS += target
2020

2121
include(pingmonitor.pri)
2222

23-
FILE=$$OUT_PWD/release/pingmonitorplugin.dll
24-
FILE ~= s,/,\\,g
25-
DEST=$$[QT_INSTALL_PLUGINS]/designer
26-
DEST ~= s,/,\\,g
27-
system(mkdir $$DEST)
28-
29-
QMAKE_POST_LINK += \
23+
unix {
24+
FILE=$$OUT_PWD/libpingmonitorplugin.so
25+
DEST=$$[QT_INSTALL_PLUGINS]/designer/
26+
QMAKE_POST_LINK += $$quote(cp $${FILE} $${DEST})
27+
}
28+
win32 {
29+
FILE=$$OUT_PWD/release/pingmonitorplugin.dll
30+
FILE ~= s,/,\\,g
31+
DEST=$$[QT_INSTALL_PLUGINS]/designer
32+
DEST ~= s,/,\\,g
33+
system(mkdir $$DEST)
34+
35+
QMAKE_POST_LINK += \
3036
$$quote(cmd /c copy /Y $${FILE} $${DEST}$$escape_expand(\n\t))
31-
37+
}

PingMonitor/include/pingmonitorplugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef PINGMONITORPLUGIN_H
22
#define PINGMONITORPLUGIN_H
33

4-
#include <QDesignerCustomWidgetInterface>
4+
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
55

66
class PingMonitorPlugin : public QObject, public QDesignerCustomWidgetInterface
77
{

PortMonitor/PortMonitor.pro

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ target.path = $$[QT_INSTALL_PLUGINS]/designer
2020
INSTALLS += target
2121

2222
include(portmonitor.pri)
23+
unix {
24+
FILE=$$OUT_PWD/libportmonitorplugin.so
25+
DEST=$$[QT_INSTALL_PLUGINS]/designer
26+
QMAKE_POST_LINK += $$quote(cp $${FILE} $${DEST})
27+
}
28+
win32 {
29+
FILE=$$OUT_PWD/release/portmonitorplugin.dll
30+
FILE ~= s,/,\\,g
31+
DEST=$$[QT_INSTALL_PLUGINS]/designer
32+
DEST ~= s,/,\\,g
33+
system(mkdir $$DEST)
2334

24-
FILE=$$OUT_PWD/release/portmonitorplugin.dll
25-
FILE ~= s,/,\\,g
26-
DEST=$$[QT_INSTALL_PLUGINS]/designer
27-
DEST ~= s,/,\\,g
28-
system(mkdir $$DEST)
29-
30-
QMAKE_POST_LINK += \
35+
QMAKE_POST_LINK += \
3136
$$quote(cmd /c copy /Y $${FILE} $${DEST}$$escape_expand(\n\t))
37+
38+
}
39+

PortMonitor/include/portmonitorplugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef PORTMONITORPLUGIN_H
22
#define PORTMONITORPLUGIN_H
33

4-
#include <QDesignerCustomWidgetInterface>
4+
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
55

66
class PortMonitorPlugin : public QObject, public QDesignerCustomWidgetInterface
77
{

QtCustomDesignerWidgets.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
TEMPLATE = subdirs
22

33
SUBDIRS += \
4+
CsvViewer \
45
PingMonitor \
56
PortMonitor

0 commit comments

Comments
 (0)