mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-06-11 21:53:14 +02:00
Add headless command-line export (PDF/PNG/SVG)
Implements the long-requested batch/headless export (bugtracker #171, GitHub #309): render a project's diagrams to files without opening the GUI. qelectrotech --export-pdf <project.qet> <output.pdf> one multi-page PDF qelectrotech --export-png <project.qet> <output_dir> one PNG per diagram qelectrotech --export-svg <project.qet> <output_dir> one SVG per diagram main.cpp detects an export request before SingleApplication is created (so the arguments are not forwarded to a running instance), spins up a plain QApplication for rendering, and exits with the export's status code. Rendering reuses Diagram::render() over BorderTitleBlock::borderAndTitleBlockRect(), the same geometry the GUI print/export path uses, so output matches the editor. Image files are named NN_Title.<ext>. New files: sources/cli_export.{h,cpp}, registered in cmake/qet_compilation_vars.cmake.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "cli_export.h"
|
||||
#include "machine_info.h"
|
||||
#include "qet.h"
|
||||
#include "qetapp.h"
|
||||
@@ -22,6 +23,8 @@
|
||||
#include "utils/macosxopenevent.h"
|
||||
#include "utils/qetsettings.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include <QStyleFactory>
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
@@ -194,6 +197,19 @@ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(QetSettings::hdpiScaleFacto
|
||||
#endif
|
||||
|
||||
|
||||
// Headless command-line export: render a project to PDF/PNG/SVG without
|
||||
// opening the GUI, then exit. Must be handled before SingleApplication
|
||||
// (which would forward the args to an already-running instance).
|
||||
{
|
||||
QStringList raw_args;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
raw_args << QString::fromLocal8Bit(argv[i]);
|
||||
if (CLIExport::isExportRequest(raw_args)) {
|
||||
QApplication export_app(argc, argv);
|
||||
return CLIExport::run(export_app.arguments());
|
||||
}
|
||||
}
|
||||
|
||||
SingleApplication app(argc, argv, true);
|
||||
#ifdef Q_OS_MACOS
|
||||
//Handle the opening of QET when user double click on a .qet .elmt .tbt file
|
||||
|
||||
Reference in New Issue
Block a user