Big-Ugly Style Update (#278)
* Bulk replaced tabs with spaces * Bulk removed trailing whitespace from lines * Replaced c-style comments with c++-style comments in file banners * Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable * Cleanup ordering and spacing of include directives * Bulk renaming of header file extensions from '.h' to '.hpp'. * Update CODING-STYLE.md * Update target_compile_features from cxx_std_11 to cxx_std_20. * Refresh .clang-format file. Still needs a lot of tweaking.
This commit is contained in:
+260
-259
@@ -1,301 +1,302 @@
|
||||
/* File.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// File.cpp
|
||||
//
|
||||
// Copyright (C) 2014 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "File.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "SelectProductDialog.h"
|
||||
#include "TemplateDesigner.h"
|
||||
#include "File.hpp"
|
||||
|
||||
#include "model/FileUtil.h"
|
||||
#include "model/Model.h"
|
||||
#include "model/Settings.h"
|
||||
#include "model/XmlLabelParser.h"
|
||||
#include "model/XmlLabelCreator.h"
|
||||
#include "MainWindow.hpp"
|
||||
#include "SelectProductDialog.hpp"
|
||||
#include "TemplateDesigner.hpp"
|
||||
|
||||
#include "model/FileUtil.hpp"
|
||||
#include "model/Model.hpp"
|
||||
#include "model/Settings.hpp"
|
||||
#include "model/XmlLabelParser.hpp"
|
||||
#include "model/XmlLabelCreator.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Static data
|
||||
//
|
||||
QString File::mCwd = ".";
|
||||
//
|
||||
// Static data
|
||||
//
|
||||
QString File::mCwd = ".";
|
||||
|
||||
|
||||
///
|
||||
/// New Label Dialog
|
||||
///
|
||||
bool File::newLabel( MainWindow *window )
|
||||
{
|
||||
SelectProductDialog dialog( window );
|
||||
dialog.exec();
|
||||
///
|
||||
/// New Label Dialog
|
||||
///
|
||||
bool File::newLabel( MainWindow *window )
|
||||
{
|
||||
SelectProductDialog dialog( window );
|
||||
dialog.exec();
|
||||
|
||||
auto tmplate = dialog.tmplate();
|
||||
if ( !tmplate.isNull() )
|
||||
{
|
||||
auto* model = new model::Model();
|
||||
model->setTmplate( tmplate );
|
||||
|
||||
// Intelligently decide to rotate label by default
|
||||
auto frame = tmplate.frame();
|
||||
model->setRotate( frame->h() > frame->w() );
|
||||
auto tmplate = dialog.tmplate();
|
||||
if ( !tmplate.isNull() )
|
||||
{
|
||||
auto* model = new model::Model();
|
||||
model->setTmplate( tmplate );
|
||||
|
||||
model->clearModified();
|
||||
// Intelligently decide to rotate label by default
|
||||
auto frame = tmplate.frame();
|
||||
model->setRotate( frame->h() > frame->w() );
|
||||
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *newWindow = new MainWindow();
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
model->clearModified();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *newWindow = new MainWindow();
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Open File Dialog
|
||||
///
|
||||
void File::open( MainWindow *window )
|
||||
{
|
||||
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
|
||||
QString cwd = mCwd;
|
||||
if ( window->model() && !window->model()->fileName().isEmpty() )
|
||||
{
|
||||
QFileInfo fileInfo( window->model()->fileName() );
|
||||
if ( fileInfo.isFile() )
|
||||
{
|
||||
cwd = fileInfo.absolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
QString fileName =
|
||||
QFileDialog::getOpenFileName( window,
|
||||
tr("gLabels - Open Project"),
|
||||
cwd,
|
||||
tr("glabels files (*.glabels);;All files (*)")
|
||||
);
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
model::Model *model = model::XmlLabelParser::readFile( fileName );
|
||||
if ( model )
|
||||
{
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *newWindow = new MainWindow();
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
model::Settings::addToRecentFileList( model->fileName() );
|
||||
///
|
||||
/// Open File Dialog
|
||||
///
|
||||
void File::open( MainWindow *window )
|
||||
{
|
||||
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
|
||||
QString cwd = mCwd;
|
||||
if ( window->model() && !window->model()->fileName().isEmpty() )
|
||||
{
|
||||
QFileInfo fileInfo( window->model()->fileName() );
|
||||
if ( fileInfo.isFile() )
|
||||
{
|
||||
cwd = fileInfo.absolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( fileName ).absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
model::Settings::removeFromRecentFileList( fileName );
|
||||
QString fileName =
|
||||
QFileDialog::getOpenFileName( window,
|
||||
tr("gLabels - Open Project"),
|
||||
cwd,
|
||||
tr("glabels files (*.glabels);;All files (*)")
|
||||
);
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
model::Model *model = model::XmlLabelParser::readFile( fileName );
|
||||
if ( model )
|
||||
{
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *newWindow = new MainWindow();
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
model::Settings::addToRecentFileList( model->fileName() );
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
|
||||
msgBox.setStandardButtons( QMessageBox::Ok );
|
||||
msgBox.setDefaultButton( QMessageBox::Ok );
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( fileName ).absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
model::Settings::removeFromRecentFileList( fileName );
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
|
||||
msgBox.setStandardButtons( QMessageBox::Ok );
|
||||
msgBox.setDefaultButton( QMessageBox::Ok );
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Open file
|
||||
///
|
||||
void File::open( const QString& fileName, MainWindow *window )
|
||||
{
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
model::Model *model = model::XmlLabelParser::readFile( fileName );
|
||||
if ( model )
|
||||
{
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *newWindow = new MainWindow();
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
model::Settings::addToRecentFileList( model->fileName() );
|
||||
///
|
||||
/// Open file
|
||||
///
|
||||
void File::open( const QString& fileName, MainWindow *window )
|
||||
{
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
model::Model *model = model::XmlLabelParser::readFile( fileName );
|
||||
if ( model )
|
||||
{
|
||||
// Either apply to current window or open a new one
|
||||
if ( window->isEmpty() )
|
||||
{
|
||||
window->setModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *newWindow = new MainWindow();
|
||||
newWindow->setModel( model );
|
||||
newWindow->show();
|
||||
}
|
||||
model::Settings::addToRecentFileList( model->fileName() );
|
||||
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( fileName ).absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
model::Settings::removeFromRecentFileList( fileName );
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( fileName ).absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
model::Settings::removeFromRecentFileList( fileName );
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
|
||||
msgBox.setStandardButtons( QMessageBox::Ok );
|
||||
msgBox.setDefaultButton( QMessageBox::Ok );
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
|
||||
msgBox.setStandardButtons( QMessageBox::Ok );
|
||||
msgBox.setDefaultButton( QMessageBox::Ok );
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Save file
|
||||
///
|
||||
bool File::save( MainWindow *window )
|
||||
{
|
||||
if ( window->model()->fileName().isEmpty() )
|
||||
{
|
||||
return saveAs( window );
|
||||
}
|
||||
///
|
||||
/// Save file
|
||||
///
|
||||
bool File::save( MainWindow *window )
|
||||
{
|
||||
if ( window->model()->fileName().isEmpty() )
|
||||
{
|
||||
return saveAs( window );
|
||||
}
|
||||
|
||||
if ( !window->model()->isModified() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( !window->model()->isModified() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
model::XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
|
||||
model::Settings::addToRecentFileList( window->model()->fileName() );
|
||||
model::XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
|
||||
model::Settings::addToRecentFileList( window->model()->fileName() );
|
||||
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Save file as
|
||||
///
|
||||
bool File::saveAs( MainWindow *window )
|
||||
{
|
||||
// Either use the saved CWD from a previous open/save or grab it from the path
|
||||
// of the current file.
|
||||
QString cwd = mCwd;
|
||||
if ( window->model() && !window->model()->fileName().isEmpty() )
|
||||
{
|
||||
QFileInfo fileInfo( window->model()->fileName() );
|
||||
if ( fileInfo.isFile() )
|
||||
{
|
||||
cwd = fileInfo.filePath();
|
||||
}
|
||||
}
|
||||
|
||||
QString rawFileName =
|
||||
QFileDialog::getSaveFileName( window,
|
||||
tr("gLabels - Save Project As"),
|
||||
cwd,
|
||||
tr("glabels files (*.glabels);;All files (*)"),
|
||||
nullptr,
|
||||
QFileDialog::DontConfirmOverwrite );
|
||||
if ( !rawFileName.isEmpty() )
|
||||
{
|
||||
QString fileName = model::FileUtil::addExtension( rawFileName, ".glabels" );
|
||||
|
||||
|
||||
if ( QFileInfo::exists(fileName) )
|
||||
{
|
||||
QMessageBox msgBox( window );
|
||||
msgBox.setWindowTitle( tr("Save Label As") );
|
||||
msgBox.setIcon( QMessageBox::Warning );
|
||||
msgBox.setText( tr("%1 already exists.").arg(fileName) );
|
||||
msgBox.setInformativeText( tr("Do you want to replace it?") );
|
||||
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
|
||||
msgBox.setDefaultButton( QMessageBox::No );
|
||||
///
|
||||
/// Save file as
|
||||
///
|
||||
bool File::saveAs( MainWindow *window )
|
||||
{
|
||||
// Either use the saved CWD from a previous open/save or grab it from the path
|
||||
// of the current file.
|
||||
QString cwd = mCwd;
|
||||
if ( window->model() && !window->model()->fileName().isEmpty() )
|
||||
{
|
||||
QFileInfo fileInfo( window->model()->fileName() );
|
||||
if ( fileInfo.isFile() )
|
||||
{
|
||||
cwd = fileInfo.filePath();
|
||||
}
|
||||
}
|
||||
|
||||
if ( msgBox.exec() == QMessageBox::No )
|
||||
{
|
||||
return saveAs( window );
|
||||
}
|
||||
}
|
||||
|
||||
model::XmlLabelCreator::writeFile( window->model(), fileName );
|
||||
model::Settings::addToRecentFileList( window->model()->fileName() );
|
||||
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( fileName ).absolutePath();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
QString rawFileName =
|
||||
QFileDialog::getSaveFileName( window,
|
||||
tr("gLabels - Save Project As"),
|
||||
cwd,
|
||||
tr("glabels files (*.glabels);;All files (*)"),
|
||||
nullptr,
|
||||
QFileDialog::DontConfirmOverwrite );
|
||||
if ( !rawFileName.isEmpty() )
|
||||
{
|
||||
QString fileName = model::FileUtil::addExtension( rawFileName, ".glabels" );
|
||||
|
||||
|
||||
///
|
||||
/// Template Designer
|
||||
///
|
||||
void File::templateDesigner( MainWindow *window )
|
||||
{
|
||||
TemplateDesigner dialog( window );
|
||||
dialog.exec();
|
||||
}
|
||||
if ( QFileInfo::exists(fileName) )
|
||||
{
|
||||
QMessageBox msgBox( window );
|
||||
msgBox.setWindowTitle( tr("Save Label As") );
|
||||
msgBox.setIcon( QMessageBox::Warning );
|
||||
msgBox.setText( tr("%1 already exists.").arg(fileName) );
|
||||
msgBox.setInformativeText( tr("Do you want to replace it?") );
|
||||
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
|
||||
msgBox.setDefaultButton( QMessageBox::No );
|
||||
|
||||
if ( msgBox.exec() == QMessageBox::No )
|
||||
{
|
||||
return saveAs( window );
|
||||
}
|
||||
}
|
||||
|
||||
model::XmlLabelCreator::writeFile( window->model(), fileName );
|
||||
model::Settings::addToRecentFileList( window->model()->fileName() );
|
||||
|
||||
// Save CWD
|
||||
mCwd = QFileInfo( fileName ).absolutePath();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Close file
|
||||
///
|
||||
void File::close( MainWindow *window )
|
||||
{
|
||||
window->close();
|
||||
}
|
||||
///
|
||||
/// Template Designer
|
||||
///
|
||||
void File::templateDesigner( MainWindow *window )
|
||||
{
|
||||
TemplateDesigner dialog( window );
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Exit, closing all windows
|
||||
///
|
||||
void File::exit()
|
||||
{
|
||||
for ( QWidget* qwidget : QApplication::topLevelWidgets() )
|
||||
{
|
||||
if ( auto* window = qobject_cast<MainWindow*>(qwidget) )
|
||||
{
|
||||
window->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
///
|
||||
/// Close file
|
||||
///
|
||||
void File::close( MainWindow *window )
|
||||
{
|
||||
window->close();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Exit, closing all windows
|
||||
///
|
||||
void File::exit()
|
||||
{
|
||||
for ( QWidget* qwidget : QApplication::topLevelWidgets() )
|
||||
{
|
||||
if ( auto* window = qobject_cast<MainWindow*>(qwidget) )
|
||||
{
|
||||
window->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
|
||||
Reference in New Issue
Block a user