Skip to content

Commit

Permalink
completed file system pie chart
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhaninan committed Apr 23, 2019
1 parent bf348d3 commit e9b18b5
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 22 deletions.
23 changes: 22 additions & 1 deletion stacer-core/Info/disk_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,42 @@ void DiskInfo::updateDiskInfo()
disks.clear();

QList<QStorageInfo> storageInfoList = QStorageInfo::mountedVolumes();

for(const QStorageInfo &info: storageInfoList) {
if (info.isValid()) {
qDebug()<< "type: " <<info.subvolume();
Disk *disk = new Disk;
disk->name = info.displayName();
disk->device = info.device();
disk->size = info.bytesTotal();
disk->used = info.bytesTotal() - info.bytesFree();
disk->free = info.bytesFree();
disk->fileSystemType = info.fileSystemType();

disks << disk;
}
}
}

QList<QString> DiskInfo::devices()
{
QSet<QString> set;
for(const QStorageInfo &info: QStorageInfo::mountedVolumes()) {
if (info.isValid()) set.insert(info.device());
}

return set.toList();
}

QList<QString> DiskInfo::fileSystemTypes()
{
QSet<QString> set;
for(const QStorageInfo &info: QStorageInfo::mountedVolumes()) {
if (info.isValid()) set.insert(info.fileSystemType());
}

return set.toList();
}

QList<quint64> DiskInfo::getDiskIO() const
{
static QString diskName = getDiskName();
Expand Down
4 changes: 4 additions & 0 deletions stacer-core/Info/disk_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Utils/command_util.h"
#include "Utils/file_util.h"
#include <QStorageInfo>
#include <QSet>
#include "stacer-core_global.h"

#define PROC_MOUNTS "/proc/mounts"
Expand All @@ -17,6 +18,8 @@ class STACERCORESHARED_EXPORT DiskInfo
void updateDiskInfo();
QList<quint64> getDiskIO() const;
QString getDiskName() const;
QList<QString> fileSystemTypes();
QList<QString> devices();

private:
QList<Disk*> disks;
Expand All @@ -26,6 +29,7 @@ class Disk {
public:
QString name;
QString device;
QString fileSystemType;
quint64 size;
quint64 free;
quint64 used;
Expand Down
10 changes: 10 additions & 0 deletions stacer/Managers/info_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ QList<quint64> InfoManager::getDiskIO()
return di.getDiskIO();
}

QList<QString> InfoManager::getFileSystemTypes()
{
return di.fileSystemTypes();
}

QList<QString> InfoManager::getDevices()
{
return di.devices();
}

/********************
* Network Provider
*******************/
Expand Down
2 changes: 2 additions & 0 deletions stacer/Managers/info_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class InfoManager
QStringList getUserList() const;
QStringList getGroupList() const;

QList<QString> getDevices();
QList<QString> getFileSystemTypes();
private:
static InfoManager *instance;

Expand Down
91 changes: 70 additions & 21 deletions stacer/Pages/Resources/resources_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,36 @@ void ResourcesPage::init()
initDiskPieChart();
}

void ResourcesPage::initDiskPieChart()
void ResourcesPage::diskPieSeriesCustomize()
{
QPieSeries *series = new QPieSeries();

for (const Disk *disk : InfoManager::ins()->getDisks()) {
series->append(disk->name, disk->size);
}

for (int i = 0; i < series->count(); ++i) {
QPieSlice *slice = series->slices().at(i);
for (int i = 0; i < mDiskPieSeries->count(); ++i) {
QPieSlice *slice = mDiskPieSeries->slices().at(i);
slice->setBrush(QColor((i < chartColors.count() ? chartColors.at(i) : i - chartColors.count())));
slice->setBorderColor(QColor(Qt::white));
slice->setBorderColor(QColor(Qt::lightGray));
connect(slice, &QPieSlice::hovered, this, [=](bool show) {
slice->setExploded(show);
slice->setLabelVisible(show);
slice->setLabel(QString::number(slice->value()));
mChartDiskPie->setTitle(QString("%1 (%2) (%3)")
.arg(slice->label())
.arg(FormatUtil::formatBytes(slice->value()))
.arg(QString().sprintf("%1.2f%%", slice->percentage() * 100)));
});
}
}

void ResourcesPage::initDiskPieChart()
{
mDiskPieSeries = new QPieSeries();

for (const Disk *disk : InfoManager::ins()->getDisks()) {
mDiskPieSeries->append(disk->name, disk->size);
}

diskPieSeriesCustomize();

mChartDiskPie->legend()->hide();
mChartDiskPie->setAnimationOptions(QChart::AllAnimations);
mChartDiskPie->legend()->setVisible(true);
mChartDiskPie->legend()->setAlignment(Qt::AlignRight);
mChartDiskPie->addSeries(series);
mChartDiskPie->setMinimumHeight(400);
mChartDiskPie->addSeries(mDiskPieSeries);
mChartDiskPie->setMinimumHeight(500);

QChartView *mChartViewDiskPie = new QChartView(mChartDiskPie);
mChartViewDiskPie->setRenderHint(QPainter::Antialiasing);
Expand All @@ -91,11 +97,11 @@ void ResourcesPage::initDiskPieChart()
gridWidgetDiskPie->setLayout(gridLayoutDiskPie);
gridLayoutDiskPie->setContentsMargins(0,0,0,0);
gridLayoutDiskPie->setHorizontalSpacing(10);
gridLayoutDiskPie->setVerticalSpacing(0);
gridLayoutDiskPie->setVerticalSpacing(5);

QLabel *lblChartTitle = new QLabel(gridWidgetDiskPie);
lblChartTitle->setObjectName("lblHistoryTitle");
lblChartTitle->setText(tr("Disks"));
lblChartTitle->setText(tr("File System"));

QCheckBox *checkHistoryTitle = new QCheckBox(gridWidgetDiskPie);
checkHistoryTitle->setObjectName("checkHistoryTitle");
Expand All @@ -110,12 +116,55 @@ void ResourcesPage::initDiskPieChart()
gridWidgetDiskPie->show();
});

QComboBox *cmbFileSystemType = new QComboBox(gridWidgetDiskPie);
cmbFileSystemType->addItem(tr("File System Type"), -1);
cmbFileSystemType->addItems(InfoManager::ins()->getFileSystemTypes());
connect(cmbFileSystemType, &QComboBox::currentTextChanged, this, [=](const QString text) {
mChartDiskPie->removeSeries(mDiskPieSeries);
mDiskPieSeries = new QPieSeries();

for (const Disk *disk : InfoManager::ins()->getDisks()) {
if (cmbFileSystemType->currentIndex() != 0 && disk->fileSystemType == text) {
mDiskPieSeries->append(disk->name, disk->size);
} else if(cmbFileSystemType->currentIndex() == 0) {
mDiskPieSeries->append(disk->name, disk->size);
}
}
diskPieSeriesCustomize();
emit SignalMapper::ins()->sigChangedAppTheme();

mChartDiskPie->addSeries(mDiskPieSeries);
});

QComboBox *cmbDevice = new QComboBox(gridWidgetDiskPie);
cmbDevice->addItem(tr("Device"));
cmbDevice->addItems(InfoManager::ins()->getDevices());
connect(cmbDevice, &QComboBox::currentTextChanged, this, [=](const QString text) {
mChartDiskPie->removeSeries(mDiskPieSeries);
mDiskPieSeries = new QPieSeries();

for (const Disk *disk : InfoManager::ins()->getDisks()) {
if (cmbDevice->currentIndex() != 0 && disk->device == text) {
mDiskPieSeries->append(disk->name, disk->size);
} else if(cmbDevice->currentIndex() == 0) {
mDiskPieSeries->append(disk->name, disk->size);
}
}
diskPieSeriesCustomize();
emit SignalMapper::ins()->sigChangedAppTheme();

mChartDiskPie->addSeries(mDiskPieSeries);
});

QSpacerItem *horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);

gridLayoutDiskPie->addWidget(lblChartTitle, 0, 0);
gridLayoutDiskPie->addWidget(checkHistoryTitle, 0, 1);
gridLayoutDiskPie->addItem(horizontalSpacer, 0, 2);
gridLayoutDiskPie->addWidget(mChartViewDiskPie, 1, 0, 1, 3);
gridLayoutDiskPie->addWidget(cmbDevice, 0, 3);
gridLayoutDiskPie->addWidget(cmbFileSystemType, 0, 4);

gridLayoutDiskPie->addWidget(mChartViewDiskPie, 1, 0, 1, 5);

ui->chartsLayout->addWidget(gridWidgetDiskPie);

Expand All @@ -125,8 +174,8 @@ void ResourcesPage::initDiskPieChart()
QString chartGridColor = AppManager::ins()->getStyleValues()->value("@chartGridColor").toString();
QString historyChartBackground = AppManager::ins()->getStyleValues()->value("@historyChartBackgroundColor").toString();

for (int i = 0; i < series->count(); ++i) {
series->slices().at(i)->setLabelBrush(QColor(chartGridColor));
for (int i = 0; i < mDiskPieSeries->count(); ++i) {
mDiskPieSeries->slices().at(i)->setLabelBrush(QColor(chartGridColor));
}

mChartDiskPie->setBackgroundBrush(QColor(historyChartBackground));
Expand Down
2 changes: 2 additions & 0 deletions stacer/Pages/Resources/resources_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private slots:
void updateMemoryChart();
void updateNetworkChart();
void initDiskPieChart();
void diskPieSeriesCustomize();

private:
void init();
Expand All @@ -48,6 +49,7 @@ private slots:

QWidget *gridWidgetDiskPie;
QGridLayout *gridLayoutDiskPie;
QPieSeries *mDiskPieSeries;

QList<int> chartColors;

Expand Down

0 comments on commit e9b18b5

Please sign in to comment.