Skip to content

Commit

Permalink
Start a swith to Qt Quick for the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed May 30, 2015
1 parent 0df1658 commit e242a16
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 216 deletions.
11 changes: 3 additions & 8 deletions src/Arbore-qt.pro
Expand Up @@ -4,9 +4,7 @@
#
#-------------------------------------------------

QT += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core network qml quick

CONFIG += c++11

Expand All @@ -15,7 +13,6 @@ TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
ipfs/ipfs.cpp \
ipfs/ipfsversion.cpp \
ipfs/ipfspin.cpp \
Expand All @@ -24,7 +21,6 @@ SOURCES += main.cpp\
ipfs/ipfspeer.cpp \
ipfs/ipfsget.cpp \
share.cpp \
sharedelegate.cpp \
sharemodel.cpp \
ipfs/ipfsls.cpp \
ipfs/ipfshash.cpp \
Expand All @@ -34,7 +30,7 @@ SOURCES += main.cpp\
ipfs/ipfsrefs.cpp \
ipfs/ipfsstats.cpp

HEADERS += mainwindow.h \
HEADERS += \
ipfs/ipfs.h \
ipfs/ipfsversion.h \
ipfs/ipfspin.h \
Expand All @@ -49,9 +45,8 @@ HEADERS += mainwindow.h \
file.h \
object.h \
share.h \
sharedelegate.h \
sharemodel.h \
ipfs/ipfsrefs.h \
ipfs/ipfsstats.h

FORMS += mainwindow.ui
RESOURCES += ui/resources.qrc
24 changes: 15 additions & 9 deletions src/main.cpp
@@ -1,15 +1,21 @@
#include "mainwindow.h"
#include "ipfs/ipfs.h"
#include <QApplication>
#include <QDebug>
#include <QTime>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

#include "sharemodel.h"



int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;

ShareModel shareModel;
engine.rootContext()->setContextProperty("shareModel", &shareModel);

engine.load(QUrl(QStringLiteral("qrc:/mainWindow.qml")));

return a.exec();
return app.exec();
}
40 changes: 0 additions & 40 deletions src/mainwindow.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions src/mainwindow.h

This file was deleted.

4 changes: 1 addition & 3 deletions src/share.h
Expand Up @@ -21,12 +21,12 @@ enum ShareState {
class Share : public QObject
{
Q_OBJECT

public:
explicit Share(QObject *parent = 0);
explicit Share(QString name, const IpfsHash &hash, QObject *parent = 0);
virtual ~Share() {}


const QString& name() const;

ShareState state() const;
Expand Down Expand Up @@ -67,8 +67,6 @@ class Share : public QObject
QString name_;
ShareState state_;
QList<Object*> objects_;

};
Q_DECLARE_METATYPE(const Share*)

#endif // SHARE_H
83 changes: 0 additions & 83 deletions src/sharedelegate.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions src/sharedelegate.h

This file was deleted.

44 changes: 30 additions & 14 deletions src/sharemodel.cpp
Expand Up @@ -12,6 +12,19 @@ ShareModel::ShareModel(QObject *parent) :
shares_.append(new Share("Example 3", IpfsHash("QmX6gcmX2vy2gs5dWB45w8aUNynEiqGhLayXySGb7RF2TM"), this));
}

QHash<int, QByteArray> ShareModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[ProgressRole] = "progress";
roles[SizeTotalRole] = "sizeTotal";
roles[SizeLocalRole] = "sizeLocal";
roles[BlockTotalRole] = "blockTotal";
roles[BlockLocalRole] = "blockLocal";
roles[FileTotalRole] = "fileTotal";
roles[FileLocalRole] = "fileLocal";
return roles;
}

int ShareModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
Expand All @@ -20,22 +33,25 @@ int ShareModel::rowCount(const QModelIndex &parent) const

QVariant ShareModel::data(const QModelIndex &index, int role) const
{
QVariant var;

// Check that the index is valid and within the correct range first:
if (!index.isValid())
return var;
if (index.row() >= shares_.size())
return var;

const Share *dl = shares_.value(index.row(), 0);
switch(role)
{
case Qt::UserRole: // complex gui display
var.setValue(dl); break;
case Qt::DisplayRole: // text display
var.setValue(dl->name()); break;
case NameRole:
return dl->name();
case ProgressRole:
return dl->progress();
case SizeTotalRole:
return dl->size_total();
case SizeLocalRole:
return dl->size_local();
case BlockTotalRole:
return dl->block_total();
case BlockLocalRole:
return dl->block_local();
case FileTotalRole:
return dl->file_total();
case FileLocalRole:
return dl->file_local();
}

return var;
return QVariant();
}
21 changes: 16 additions & 5 deletions src/sharemodel.h
Expand Up @@ -2,26 +2,37 @@
#define SHAREMODEL_H

#include <QAbstractListModel>
#include <QHash>
#include <QByteArray>

class Share;

class ShareModel : public QAbstractListModel
{
Q_OBJECT
public:
enum ShareRoles {
NameRole = Qt::UserRole + 1,
ProgressRole,
StateRole,
SizeTotalRole,
SizeLocalRole,
BlockTotalRole,
BlockLocalRole,
FileTotalRole,
FileLocalRole
};

explicit ShareModel(QObject *parent = 0);
virtual ~ShareModel() {}


QHash<int, QByteArray> roleNames() const;
int rowCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;

private:
QVector<Share*> shares_;

signals:

public slots:

};

#endif // SHAREMODEL_H
Expand Down
Binary file added src/ui/arbore.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/ui/contactIcon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e242a16

Please sign in to comment.