Skip to content

Commit

Permalink
add export single to raw/to file
Browse files Browse the repository at this point in the history
  • Loading branch information
morsisko committed Jul 20, 2017
1 parent c4ff6d0 commit 7135ff6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Source/Ui/OnexTreeImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ void OnexTreeImage::onExportAll()
QMessageBox msgBox(QMessageBox::Information, tr("End of operation"), text);
msgBox.exec();
}

void OnexTreeImage::onExportSingle()
{
QString fileName = getSaveDirectory("PNG Image (*png)");

if (fileName.isEmpty())
return;

if (!fileName.endsWith(".png"))
fileName += ".png";

if (this->getImage().save(fileName, "PNG", 100))
QMessageBox::information(NULL, "Yeah", "Image exported");
else
QMessageBox::critical(NULL, "Woops", "Couldn't export that image");
}
1 change: 1 addition & 0 deletions Source/Ui/OnexTreeImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class OnexTreeImage : public OnexTreeZlibItem

private slots:
virtual void onExportAll();
virtual void onExportSingle();

};

Expand Down
41 changes: 39 additions & 2 deletions Source/Ui/OnexTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ QString OnexTreeItem::getSelectedDirectory()
return dir + "/";
}

QString OnexTreeItem::getSaveDirectory(QString filter)
{
return QFileDialog::getSaveFileName(0, tr("Save as..."), "", filter);
}

QByteArray OnexTreeItem::getContent()
{
return content;
Expand Down Expand Up @@ -45,6 +50,16 @@ QMenu *OnexTreeItem::getContextMenu()
contextMenu->addAction(exportAllAction);
QObject::connect(exportAllAction, SIGNAL(triggered(bool)), this, SLOT(onExportAll()));
}
else
{
QAction* exportSingleAction = new QAction(QObject::tr("Export"), contextMenu);
contextMenu->addAction(exportSingleAction);
QObject::connect(exportSingleAction, SIGNAL(triggered(bool)), this, SLOT(onExportSingle()));

QAction* exportSingleToRawAction = new QAction(QObject::tr("Export to raw"), contextMenu);
contextMenu->addAction(exportSingleToRawAction);
QObject::connect(exportSingleToRawAction, SIGNAL(triggered(bool)), this, SLOT(onExporSingleRaw()));
}

return contextMenu;
}
Expand All @@ -56,6 +71,28 @@ OnexTreeItem::~OnexTreeItem()

void OnexTreeItem::onExportAll()
{
QMessageBox msgBox(QMessageBox::Warning, QObject::tr("Not yet"), QObject::tr("This isn't implemented yet"));
msgBox.exec();
QMessageBox::warning(NULL, tr("Not yet"), tr("This isn't implemented yet"));
}

void OnexTreeItem::onExportSingle()
{
QMessageBox::warning(NULL, tr("Not yet"), tr("This isn't implemented yet"));
}

void OnexTreeItem::onExporSingleRaw()
{
QString fileName = getSaveDirectory("Raw data (*.rawdata)");
if (fileName.isEmpty())
return;

if (!fileName.endsWith(tr(".rawdata")))
fileName += ".rawdata";

QFile file(fileName);
file.open(QIODevice::WriteOnly);
if (file.write(this->getContent()) == -1)
QMessageBox::critical(NULL, tr("Woops"), tr("Couldn't save that file"));
else
QMessageBox::information(NULL, tr("Yeah"), tr("File exported"));
file.close();
}
4 changes: 4 additions & 0 deletions Source/Ui/OnexTreeItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class OnexTreeItem : public QObject, public QTreeWidgetItem
QString name;

QString getSelectedDirectory();
QString getSaveDirectory(QString filter);
QMessageBox getMsgBox(QString title, QString message, QMessageBox::Icon icon);
public:
OnexTreeItem(QString name, QByteArray content = QByteArray());
QByteArray getContent();
Expand All @@ -28,6 +30,8 @@ class OnexTreeItem : public QObject, public QTreeWidgetItem

private slots:
virtual void onExportAll();
virtual void onExportSingle();
virtual void onExporSingleRaw();
};

#endif // ONEXTREEITEM_H

0 comments on commit 7135ff6

Please sign in to comment.