Run clang-format
This commit is contained in:
parent
892d6a7fff
commit
1dc80b96d1
11 changed files with 378 additions and 356 deletions
|
@ -15,7 +15,9 @@
|
|||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
|
||||
ArtConfigWindow::ArtConfigWindow(const QString& filename, QWidget* parent) : QDialog(parent) {
|
||||
ArtConfigWindow::ArtConfigWindow(const QString &filename, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowModality(Qt::WindowModality::WindowModal);
|
||||
setWindowTitle(filename);
|
||||
|
||||
|
@ -51,12 +53,13 @@ ArtConfigWindow::ArtConfigWindow(const QString& filename, QWidget* parent) : QDi
|
|||
});
|
||||
bottomButtonLayout->addWidget(saveButton);
|
||||
|
||||
if(QFile::exists(filename)) {
|
||||
if (QFile::exists(filename)) {
|
||||
loadData(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void ArtConfigWindow::loadData(const QString& filename) {
|
||||
void ArtConfigWindow::loadData(const QString &filename)
|
||||
{
|
||||
qDebug() << "Loading data from" << filename;
|
||||
|
||||
QFile artFile(filename);
|
||||
|
@ -67,7 +70,8 @@ void ArtConfigWindow::loadData(const QString& filename) {
|
|||
m_commissionsOpen->setChecked(artJson[QStringLiteral("commissions")].toBool());
|
||||
}
|
||||
|
||||
void ArtConfigWindow::saveData(const QString& filename) {
|
||||
void ArtConfigWindow::saveData(const QString &filename)
|
||||
{
|
||||
qDebug() << "Saving data to" << filename;
|
||||
|
||||
QJsonObject object;
|
||||
|
@ -82,4 +86,3 @@ void ArtConfigWindow::saveData(const QString& filename) {
|
|||
|
||||
close();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,22 +6,23 @@
|
|||
|
||||
#include <QCheckBox>
|
||||
#include <QDateEdit>
|
||||
#include <QDialog>
|
||||
#include <QJsonObject>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QStringListModel>
|
||||
#include <QTextEdit>
|
||||
#include <QDialog>
|
||||
|
||||
class ArtConfigWindow : public QDialog {
|
||||
class ArtConfigWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ArtConfigWindow(const QString& filename, QWidget* parent = nullptr);
|
||||
explicit ArtConfigWindow(const QString &filename, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void loadData(const QString& filename);
|
||||
void saveData(const QString& filename);
|
||||
void loadData(const QString &filename);
|
||||
void saveData(const QString &filename);
|
||||
|
||||
QLineEdit* m_newBannerEdit = nullptr;
|
||||
QCheckBox* m_commissionsOpen = nullptr;
|
||||
QLineEdit *m_newBannerEdit = nullptr;
|
||||
QCheckBox *m_commissionsOpen = nullptr;
|
||||
};
|
|
@ -171,29 +171,30 @@ ArtDetailWindow::ArtDetailWindow(const QString &filename, const QDir &assetDirec
|
|||
});
|
||||
bottomButtonLayout->addWidget(saveButton);
|
||||
|
||||
if(QFile::exists(filename)) {
|
||||
if (QFile::exists(filename)) {
|
||||
loadData(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void ArtDetailWindow::loadData(const QString& filename) {
|
||||
void ArtDetailWindow::loadData(const QString &filename)
|
||||
{
|
||||
qDebug() << "Loading data from" << filename;
|
||||
|
||||
QFile artFile(filename);
|
||||
artFile.open(QFile::ReadOnly);
|
||||
QJsonDocument artJson = QJsonDocument::fromJson(artFile.readAll());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("title")))
|
||||
if (artJson.object().contains(QStringLiteral("title")))
|
||||
m_titleEdit->setText(artJson[QStringLiteral("title")].toString());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("alt_text")))
|
||||
if (artJson.object().contains(QStringLiteral("alt_text")))
|
||||
m_altTextEdit->setText(artJson[QStringLiteral("alt_text")].toString());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("description")))
|
||||
if (artJson.object().contains(QStringLiteral("description")))
|
||||
m_descriptionEdit->setText(artJson[QStringLiteral("description")].toString());
|
||||
|
||||
m_knowExactDateBox->setChecked(artJson[QStringLiteral("date")].toString().contains(QStringLiteral("-")));
|
||||
if(m_knowExactDateBox->isChecked()) {
|
||||
if (m_knowExactDateBox->isChecked()) {
|
||||
m_dateEdit->setDate(QDate::fromString(artJson[QStringLiteral("date")].toString(), QStringLiteral("yyyy-MM-dd")));
|
||||
m_dateEdit->setDisplayFormat(QStringLiteral("yyyy-MM-dd"));
|
||||
} else {
|
||||
|
@ -201,33 +202,33 @@ void ArtDetailWindow::loadData(const QString& filename) {
|
|||
m_dateEdit->setDisplayFormat(QStringLiteral("yyyy"));
|
||||
}
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("nsfw")))
|
||||
if (artJson.object().contains(QStringLiteral("nsfw")))
|
||||
m_nsfwBox->setChecked(artJson[QStringLiteral("nsfw")].toBool());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("mastodon_url")))
|
||||
if (artJson.object().contains(QStringLiteral("mastodon_url")))
|
||||
m_mastodonUrlEdit->setText(artJson[QStringLiteral("mastodon_url")].toString());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("pixiv_url")))
|
||||
if (artJson.object().contains(QStringLiteral("pixiv_url")))
|
||||
m_pixivUrlEdit->setText(artJson[QStringLiteral("pixiv_url")].toString());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("newgrounds_url")))
|
||||
if (artJson.object().contains(QStringLiteral("newgrounds_url")))
|
||||
m_newgroundsUrlEdit->setText(artJson[QStringLiteral("newgrounds_url")].toString());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("program")))
|
||||
if (artJson.object().contains(QStringLiteral("program")))
|
||||
m_programEdit->setText(artJson[QStringLiteral("program")].toString());
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("characters"))) {
|
||||
if (artJson.object().contains(QStringLiteral("characters"))) {
|
||||
QStringList list;
|
||||
for(auto character : artJson[QStringLiteral("characters")].toArray()) {
|
||||
for (auto character : artJson[QStringLiteral("characters")].toArray()) {
|
||||
list.append(character.toString());
|
||||
}
|
||||
|
||||
m_characterListModel->setStringList(list);
|
||||
}
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("tags"))) {
|
||||
if (artJson.object().contains(QStringLiteral("tags"))) {
|
||||
QStringList list;
|
||||
for(auto tag : artJson[QStringLiteral("tags")].toArray()) {
|
||||
for (auto tag : artJson[QStringLiteral("tags")].toArray()) {
|
||||
list.append(tag.toString());
|
||||
}
|
||||
|
||||
|
@ -235,47 +236,48 @@ void ArtDetailWindow::loadData(const QString& filename) {
|
|||
}
|
||||
}
|
||||
|
||||
void ArtDetailWindow::saveData(const QString& filename) {
|
||||
void ArtDetailWindow::saveData(const QString &filename)
|
||||
{
|
||||
qDebug() << "Saving data to" << filename;
|
||||
|
||||
QJsonObject object;
|
||||
if(!m_titleEdit->text().isEmpty())
|
||||
if (!m_titleEdit->text().isEmpty())
|
||||
object[QStringLiteral("title")] = m_titleEdit->text();
|
||||
|
||||
if(!m_altTextEdit->document()->isEmpty())
|
||||
if (!m_altTextEdit->document()->isEmpty())
|
||||
object[QStringLiteral("alt_text")] = m_altTextEdit->document()->toPlainText();
|
||||
|
||||
if(!m_descriptionEdit->document()->isEmpty())
|
||||
if (!m_descriptionEdit->document()->isEmpty())
|
||||
object[QStringLiteral("description")] = m_descriptionEdit->document()->toPlainText();
|
||||
|
||||
if(m_knowExactDateBox->isChecked()) {
|
||||
if (m_knowExactDateBox->isChecked()) {
|
||||
object[QStringLiteral("date")] = m_dateEdit->date().toString(QStringLiteral("yyyy-MM-dd"));
|
||||
} else {
|
||||
object[QStringLiteral("date")] = m_dateEdit->date().toString(QStringLiteral("yyyy"));
|
||||
}
|
||||
|
||||
if(m_nsfwBox->isChecked())
|
||||
if (m_nsfwBox->isChecked())
|
||||
object[QStringLiteral("nsfw")] = m_nsfwBox->isChecked();
|
||||
|
||||
if(!m_mastodonUrlEdit->text().isEmpty())
|
||||
if (!m_mastodonUrlEdit->text().isEmpty())
|
||||
object[QStringLiteral("mastodon_url")] = m_mastodonUrlEdit->text();
|
||||
|
||||
if(!m_pixivUrlEdit->text().isEmpty())
|
||||
if (!m_pixivUrlEdit->text().isEmpty())
|
||||
object[QStringLiteral("pixiv_url")] = m_pixivUrlEdit->text();
|
||||
|
||||
if(!m_newgroundsUrlEdit->text().isEmpty())
|
||||
if (!m_newgroundsUrlEdit->text().isEmpty())
|
||||
object[QStringLiteral("newgrounds_url")] = m_newgroundsUrlEdit->text();
|
||||
|
||||
if(!m_programEdit->text().isEmpty())
|
||||
if (!m_programEdit->text().isEmpty())
|
||||
object[QStringLiteral("program")] = m_programEdit->text();
|
||||
|
||||
auto tags = m_tagsListModel->stringList();
|
||||
if(!tags.isEmpty()) {
|
||||
if (!tags.isEmpty()) {
|
||||
object[QStringLiteral("tags")] = QJsonArray::fromStringList(tags);
|
||||
}
|
||||
|
||||
auto characters = m_characterListModel->stringList();
|
||||
if(!characters.isEmpty()) {
|
||||
if (!characters.isEmpty()) {
|
||||
object[QStringLiteral("characters")] = QJsonArray::fromStringList(characters);
|
||||
}
|
||||
|
||||
|
@ -287,4 +289,3 @@ void ArtDetailWindow::saveData(const QString& filename) {
|
|||
|
||||
close();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,15 +14,16 @@
|
|||
#include <QStringListModel>
|
||||
#include <QTextEdit>
|
||||
|
||||
class ArtDetailWindow : public QDialog {
|
||||
class ArtDetailWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ArtDetailWindow(const QString &filename, const QDir &assetDirectory, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void loadData(const QString& filename);
|
||||
void loadData(const QString &filename);
|
||||
|
||||
void saveData(const QString& filename);
|
||||
void saveData(const QString &filename);
|
||||
|
||||
QLineEdit *m_titleEdit;
|
||||
QTextEdit *m_altTextEdit;
|
||||
|
@ -33,8 +34,8 @@ private:
|
|||
QLineEdit *m_pixivUrlEdit;
|
||||
QLineEdit *m_mastodonUrlEdit;
|
||||
QLineEdit *m_programEdit;
|
||||
QCheckBox* m_nsfwBox;
|
||||
QCheckBox *m_nsfwBox;
|
||||
|
||||
QStringListModel* m_characterListModel;
|
||||
QStringListModel* m_tagsListModel;
|
||||
QStringListModel *m_characterListModel;
|
||||
QStringListModel *m_tagsListModel;
|
||||
};
|
|
@ -29,7 +29,7 @@ ArtModel::ArtModel(const QDir &definitionDirectory, const QDir &assetDirectory)
|
|||
QDirIterator it(definitionDirectory);
|
||||
while (it.hasNext()) {
|
||||
QFileInfo info(it.next());
|
||||
if(!info.isFile()) {
|
||||
if (!info.isFile()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ ArtModel::ArtModel(const QDir &definitionDirectory, const QDir &assetDirectory)
|
|||
endInsertRows();
|
||||
}
|
||||
|
||||
std::function<ArtPiece(const PieceInformation& info)> loadPiece = [this](const PieceInformation& info) -> ArtPiece {
|
||||
std::function<ArtPiece(const PieceInformation &info)> loadPiece = [this](const PieceInformation &info) -> ArtPiece {
|
||||
ArtPiece p;
|
||||
loadData(p, info.definition, info.asset);
|
||||
|
||||
|
@ -55,22 +55,25 @@ ArtModel::ArtModel(const QDir &definitionDirectory, const QDir &assetDirectory)
|
|||
piecesFuture->setFuture(QtConcurrent::mapped(pieceList, loadPiece));
|
||||
}
|
||||
|
||||
int ArtModel::rowCount(const QModelIndex &parent) const {
|
||||
int ArtModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return m_artPieces.size();
|
||||
}
|
||||
|
||||
int ArtModel::columnCount(const QModelIndex &parent) const {
|
||||
int ArtModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant ArtModel::data(const QModelIndex &index, int role) const {
|
||||
QVariant ArtModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return {};
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch(index.column()) {
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
return m_artPieces[index.row()].filename;
|
||||
case 1:
|
||||
|
@ -83,7 +86,7 @@ QVariant ArtModel::data(const QModelIndex &index, int role) const {
|
|||
} else if (role == Qt::UserRole) {
|
||||
return m_artPieces[index.row()].object;
|
||||
} else if (role == Qt::DecorationRole) {
|
||||
switch(index.column()) {
|
||||
switch (index.column()) {
|
||||
case 1:
|
||||
return m_artPieces[index.row()].thumbnail;
|
||||
case 3:
|
||||
|
@ -96,9 +99,10 @@ QVariant ArtModel::data(const QModelIndex &index, int role) const {
|
|||
return {};
|
||||
}
|
||||
|
||||
QVariant ArtModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
QVariant ArtModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Orientation::Horizontal && role == Qt::DisplayRole) {
|
||||
switch(section) {
|
||||
switch (section) {
|
||||
case 0:
|
||||
return i18nc("@title:column", "Filename");
|
||||
case 1:
|
||||
|
@ -115,8 +119,8 @@ QVariant ArtModel::headerData(int section, Qt::Orientation orientation, int role
|
|||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
|
||||
void ArtModel::loadData(ArtPiece& piece, const QString& filename, const QString& assetFilename) {
|
||||
void ArtModel::loadData(ArtPiece &piece, const QString &filename, const QString &assetFilename)
|
||||
{
|
||||
piece.jsonFilename = filename + ".json";
|
||||
piece.filename = assetFilename;
|
||||
|
||||
|
@ -124,7 +128,7 @@ void ArtModel::loadData(ArtPiece& piece, const QString& filename, const QString&
|
|||
artFile.open(QFile::ReadOnly);
|
||||
QJsonDocument artJson = QJsonDocument::fromJson(artFile.readAll());
|
||||
|
||||
if(artJson[QStringLiteral("date")].toString().contains(QStringLiteral("-"))) {
|
||||
if (artJson[QStringLiteral("date")].toString().contains(QStringLiteral("-"))) {
|
||||
piece.date = QDate::fromString(artJson[QStringLiteral("date")].toString(), QStringLiteral("yyyy-MM-dd"));
|
||||
} else {
|
||||
piece.date = QDate::fromString(artJson[QStringLiteral("date")].toString(), QStringLiteral("yyyy"));
|
||||
|
@ -134,19 +138,20 @@ void ArtModel::loadData(ArtPiece& piece, const QString& filename, const QString&
|
|||
piece.title = artJson.object()[QStringLiteral("title")].toString();
|
||||
}
|
||||
|
||||
if(artJson.object().contains(QStringLiteral("alt_text"))) {
|
||||
if (artJson.object().contains(QStringLiteral("alt_text"))) {
|
||||
piece.hasAltText = true;
|
||||
}
|
||||
}
|
||||
void ArtModel::pieceFinished(int row) {
|
||||
void ArtModel::pieceFinished(int row)
|
||||
{
|
||||
m_artPieces[row] = piecesFuture->resultAt(row);
|
||||
|
||||
Q_EMIT dataChanged(index(row, 0), index(row + 1, 0));
|
||||
}
|
||||
|
||||
void ArtModel::finished() {
|
||||
std::sort(m_artPieces.begin(), m_artPieces.end(), [](ArtPiece& a, ArtPiece& b)
|
||||
{
|
||||
void ArtModel::finished()
|
||||
{
|
||||
std::sort(m_artPieces.begin(), m_artPieces.end(), [](ArtPiece &a, ArtPiece &b) {
|
||||
return a.date > b.date;
|
||||
});
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ struct ArtPiece {
|
|||
bool hasAltText = false;
|
||||
};
|
||||
|
||||
class ArtModel : public QAbstractTableModel {
|
||||
class ArtModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ArtModel(const QDir &definitionDirectory, const QDir &assetDirectory);
|
||||
|
@ -33,12 +34,12 @@ public:
|
|||
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
private:
|
||||
void loadData(ArtPiece& piece, const QString& filename, const QString& assetFilename);
|
||||
void loadData(ArtPiece &piece, const QString &filename, const QString &assetFilename);
|
||||
|
||||
void pieceFinished(int index);
|
||||
void finished();
|
||||
|
||||
QFutureWatcher<ArtPiece>* piecesFuture;
|
||||
QFutureWatcher<ArtPiece> *piecesFuture;
|
||||
|
||||
QList<ArtPiece> m_artPieces;
|
||||
};
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
#include <QDir>
|
||||
#include <QMainWindow>
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(const QDir &definitionDirectory, const QDir &assetDirectory, const QDir &dataDirectory);
|
||||
|
|
|
@ -4,30 +4,37 @@
|
|||
|
||||
#include "imagelabel.h"
|
||||
|
||||
ImageLabel::ImageLabel(QWidget *parent) : QLabel(parent) {
|
||||
ImageLabel::ImageLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
this->setMinimumSize(1, 1);
|
||||
setScaledContents(false);
|
||||
}
|
||||
|
||||
void ImageLabel::setPixmap(const QPixmap &p) {
|
||||
void ImageLabel::setPixmap(const QPixmap &p)
|
||||
{
|
||||
pix = p;
|
||||
QLabel::setPixmap(scaledPixmap());
|
||||
}
|
||||
|
||||
int ImageLabel::heightForWidth(int width) const {
|
||||
return pix.isNull() ? this->height() : ((qreal) pix.height() * width) / pix.width();
|
||||
int ImageLabel::heightForWidth(int width) const
|
||||
{
|
||||
return pix.isNull() ? this->height() : ((qreal)pix.height() * width) / pix.width();
|
||||
}
|
||||
|
||||
QSize ImageLabel::sizeHint() const {
|
||||
QSize ImageLabel::sizeHint() const
|
||||
{
|
||||
const int w = this->width();
|
||||
return {w, heightForWidth(w)};
|
||||
}
|
||||
|
||||
QPixmap ImageLabel::scaledPixmap() const {
|
||||
QPixmap ImageLabel::scaledPixmap() const
|
||||
{
|
||||
return pix.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
void ImageLabel::resizeEvent(QResizeEvent *e) {
|
||||
void ImageLabel::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
if (!pix.isNull()) {
|
||||
QLabel::setPixmap(scaledPixmap());
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
#include <QLabel>
|
||||
|
||||
class ImageLabel : public QLabel {
|
||||
class ImageLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImageLabel(QWidget *parent = nullptr);
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
#include "MainWindow.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
|
|
Reference in a new issue