...
 
Commits (4)
......@@ -18,6 +18,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
widgetUploadQueue = new UploadQueueWidget(this);
widgetUploadQueue->layout()->setMargin(10);
ui->centralTabs->addTab(widgetUploadQueue, widgetUploadQueue->windowTitle());
loadSettings();
......
......@@ -57,6 +57,9 @@
<addaction name="menu_Help"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
......@@ -66,6 +69,9 @@
<addaction name="actionRefresh"/>
</widget>
<action name="action_Quit">
<property name="icon">
<iconset theme="application-exit"/>
</property>
<property name="text">
<string>&amp;Quit</string>
</property>
......@@ -82,6 +88,9 @@
</property>
</action>
<action name="action_Preferences">
<property name="icon">
<iconset theme="preferences"/>
</property>
<property name="text">
<string>&amp;Preferences</string>
</property>
......@@ -98,6 +107,9 @@
</property>
</action>
<action name="actionRefresh">
<property name="icon">
<iconset theme="view-refresh"/>
</property>
<property name="text">
<string>Refresh</string>
</property>
......
......@@ -5,10 +5,9 @@
#include <QVariant>
#include <QStringList>
#include <QSqlError>
#include <iostream>
Upload::Upload(QObject* parent) : QObject(parent)
{
}
Upload* Upload::find(qlonglong id)
......@@ -88,6 +87,11 @@ bool Upload::create(QString submissionType, int part, QString key,
return false;
}
auto upload = find(query.lastInsertId().toLongLong());
upload->setSortId(upload->id());
upload->save();
upload->deleteLater();
return true;
}
......@@ -181,8 +185,6 @@ bool Upload::save()
QSqlDatabase db = QSqlDatabase::database();
QSqlQuery query;
std::cout << queryStringList.join(" ").toStdString() << std::endl;
query.prepare(queryStringList.join(" "));
query.bindValue(":id", m_id);
......@@ -274,7 +276,15 @@ bool Upload::save()
bool ok = query.exec();
std::cout << query.lastError().text().toStdString() << std::endl;
return ok;
}
bool Upload::destroy()
{
QSqlQuery query;
query.prepare("DELETE FROM `uploads` WHERE `id` = :id");
query.bindValue(":id", m_id);
return query.exec();
}
......@@ -45,6 +45,8 @@ public:
bool save();
bool destroy();
qlonglong id() const
{
return m_id;
......
......@@ -4,7 +4,12 @@
#include "uploaddialog.h"
#include "models/upload.h"
#include <QAbstractItemModel>
#include <QSqlRecord>
#include <QSqlField>
#include <QSqlQuery>
#include <QSqlResult>
#include <QMessageBox>
UploadQueueWidget::UploadQueueWidget(QWidget *parent) :
......@@ -16,8 +21,12 @@ UploadQueueWidget::UploadQueueWidget(QWidget *parent) :
tableModel = new QSqlTableModel(this, QSqlDatabase::database());
tableModel->setTable("uploads");
tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
// 15 == sort_id
tableModel->setSort(15, Qt::AscendingOrder);
tableModel->select();
ui->qlvUploads->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->qlvUploads->setModel(tableModel);
ui->qlvUploads->setModelColumn(5);
}
UploadQueueWidget::~UploadQueueWidget()
......@@ -29,7 +38,7 @@ void UploadQueueWidget::on_qpbAdd_clicked()
{
UploadDialog ud;
ud.exec();
qobject_cast<QSqlTableModel*>(ui->qlvUploads->model())->select();
tableModel->select();
}
void UploadQueueWidget::on_qpbEdit_clicked()
......@@ -42,17 +51,49 @@ void UploadQueueWidget::on_qpbEdit_clicked()
return;
}
auto model = qobject_cast<QSqlTableModel*>(ui->qlvUploads->model());
UploadDialog ud;
ud.fetchUploadDetails(model->record(index.row()).value("id").toInt());
ud.exec();
model->select();
ud.fetchUploadDetails(tableModel->record(index.row()).value("id").toInt());
if (ud.exec())
{
tableModel->select();
ui->qlvUploads->selectionModel()
->setCurrentIndex(index, QItemSelectionModel::Select);
}
}
void UploadQueueWidget::on_qpbDelete_clicked()
{
auto index = ui->qlvUploads->currentIndex();
if (!index.isValid())
{
QMessageBox::warning(this, tr("Warning"), tr("You must select an item"));
return;
}
auto upload = Upload::find(tableModel->record(index.row()).value("id").toInt());
if (QMessageBox::question(
this,
tr("Really delete?"),
tr("Do you really want to delete “%1”?")
.arg(upload->title())) == QMessageBox::Yes)
{
upload->destroy();
tableModel->select();
ui->qpbMoveUp->setDisabled(true);
ui->qpbMoveDown->setDisabled(true);
}
upload->deleteLater();
}
void UploadQueueWidget::on_qlvUploads_clicked(const QModelIndex &index)
{
auto model = qobject_cast<QSqlTableModel*>(ui->qlvUploads->model());
auto upload = Upload::find(model->record(index.row()).value("id").toInt());
auto upload = Upload::find(tableModel->record(index.row()).value("id").toInt());
ui->qpbMoveUp->setDisabled(false);
ui->qpbMoveDown->setDisabled(false);
if (upload)
{
......@@ -62,3 +103,117 @@ void UploadQueueWidget::on_qlvUploads_clicked(const QModelIndex &index)
upload->deleteLater();
}
}
void UploadQueueWidget::on_qpbMoveUp_clicked()
{
auto index = ui->qlvUploads->currentIndex();
if (!index.isValid())
{
QMessageBox::warning(this, tr("Warning"), tr("You must select an item"));
return;
}
auto srcUpload = Upload::find(tableModel->record(index.row()).value("id").toInt());
if (srcUpload == nullptr)
{
return;
}
QSqlQuery q;
q.prepare("SELECT id FROM `uploads` WHERE `sort_id` < :move_id ORDER BY `sort_id` DESC LIMIT 1");
q.bindValue(":move_id", srcUpload->sortId());
q.exec();
if (!q.first())
{
// already on top --> no swap needed
srcUpload->deleteLater();
return;
}
auto dstUpload = Upload::find(q.value("id").toInt());
if (dstUpload == nullptr)
{
srcUpload->deleteLater();
return;
}
auto tmp = srcUpload->sortId();
srcUpload->setSortId(dstUpload->sortId());
dstUpload->setSortId(tmp);
srcUpload->save();
dstUpload->save();
srcUpload->deleteLater();
dstUpload->deleteLater();
tableModel->select();
auto newRow = index.row();
if (index.row() - 1 >= 0)
{
newRow--;
}
auto newIndex = tableModel->index(newRow, index.column());
ui->qlvUploads->selectionModel()
->setCurrentIndex(newIndex, QItemSelectionModel::Select);
}
void UploadQueueWidget::on_qpbMoveDown_clicked()
{
auto index = ui->qlvUploads->currentIndex();
if (!index.isValid())
{
QMessageBox::warning(this, tr("Warning"), tr("You must select an item"));
return;
}
auto srcUpload = Upload::find(tableModel->record(index.row()).value("id").toInt());
if (srcUpload == nullptr)
{
return;
}
QSqlQuery q;
q.prepare("SELECT id FROM `uploads` WHERE `sort_id` > :move_id ORDER BY `sort_id` ASC LIMIT 1");
q.bindValue(":move_id", srcUpload->sortId());
q.exec();
if (!q.first())
{
// already on bottom --> no swap needed
srcUpload->deleteLater();
return;
}
auto dstUpload = Upload::find(q.value("id").toInt());
if (dstUpload == nullptr)
{
srcUpload->deleteLater();
return;
}
auto tmp = srcUpload->sortId();
srcUpload->setSortId(dstUpload->sortId());
dstUpload->setSortId(tmp);
srcUpload->save();
dstUpload->save();
srcUpload->deleteLater();
dstUpload->deleteLater();
tableModel->select();
auto newRow = index.row();
if (index.row() + 1 < tableModel->rowCount())
{
newRow++;
}
auto newIndex = tableModel->index(newRow, index.column());
ui->qlvUploads->selectionModel()
->setCurrentIndex(newIndex, QItemSelectionModel::Select);
}
......@@ -21,8 +21,14 @@ private slots:
void on_qpbEdit_clicked();
void on_qpbDelete_clicked();
void on_qlvUploads_clicked(const QModelIndex &index);
void on_qpbMoveUp_clicked();
void on_qpbMoveDown_clicked();
private:
Ui::UploadQueueWidget *ui;
QSqlTableModel *tableModel;
......
......@@ -6,14 +6,26 @@
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>314</height>
<width>421</width>
<height>338</height>
</rect>
</property>
<property name="windowTitle">
<string>Upload Queue</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,0">
<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>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<item>
......@@ -45,6 +57,39 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="qpbMoveUp">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="go-up"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="qpbMoveDown">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="go-down"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
......@@ -121,6 +166,15 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>qlvUploads</tabstop>
<tabstop>qpbAdd</tabstop>
<tabstop>qpbEdit</tabstop>
<tabstop>qpbDelete</tabstop>
<tabstop>qpbMoveUp</tabstop>
<tabstop>qpbMoveDown</tabstop>
<tabstop>qcbUpload</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
......@@ -51,6 +51,12 @@
<property name="text">
<string>Back</string>
</property>
<property name="icon">
<iconset theme="go-previous"/>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
......@@ -58,6 +64,12 @@
<property name="text">
<string>Forward</string>
</property>
<property name="icon">
<iconset theme="go-next"/>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
......@@ -65,6 +77,12 @@
<property name="text">
<string>Reload</string>
</property>
<property name="icon">
<iconset theme="view-refresh"/>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
......@@ -107,7 +125,7 @@
</layout>
</item>
<item>
<widget class="QWebEngineView" name="webView" native="true"/>
<widget class="QWebEngineView" name="webView"/>
</item>
</layout>
</widget>
......@@ -115,7 +133,7 @@
<customwidget>
<class>QWebEngineView</class>
<extends>QWidget</extends>
<header>QWebEngineView</header>
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
<container>1</container>
</customwidget>
</customwidgets>
......