Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMYK] Properties widget #58110

Merged
merged 8 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/PyQt6/core/auto_generated/qgscolorutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ message
.. versionadded:: 3.40
%End

static QString saveIccProfile( const QColorSpace &colorSpace, const QString &iccProfileFilePath );
%Docstring
Save color space ``colorSpace`` to an ICC profile file ``iccProfileFilePath``.

:return: error message if an error occurred else empty string.

.. versionadded:: 3.40
%End





Expand Down
10 changes: 10 additions & 0 deletions python/core/auto_generated/qgscolorutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ message
.. versionadded:: 3.40
%End

static QString saveIccProfile( const QColorSpace &colorSpace, const QString &iccProfileFilePath );
%Docstring
Save color space ``colorSpace`` to an ICC profile file ``iccProfileFilePath``.

:return: error message if an error occurred else empty string.

.. versionadded:: 3.40
%End





Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12595,6 +12595,7 @@ QMap< QString, QString > QgisApp::projectPropertiesPagesMap()
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "CRS" ), QStringLiteral( "mProjOptsCRS" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Transformations" ), QStringLiteral( "mProjTransformations" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Styles" ), QStringLiteral( "mProjOptsSymbols" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Colors" ), QStringLiteral( "mTabColors" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Data Sources" ), QStringLiteral( "mTab_DataSources" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Relations" ), QStringLiteral( "mTabRelations" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Variables" ), QStringLiteral( "mTab_Variables" ) );
Expand Down
93 changes: 93 additions & 0 deletions src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgis.h"
#include "qgscolorutils.h"
#include "qgscoordinatetransform.h"
#include "qgsdatumtransformtablewidget.h"
#include "qgslayoutmanager.h"
Expand Down Expand Up @@ -134,6 +135,11 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
connect( mButtonNewStyleDatabase, &QAbstractButton::clicked, this, &QgsProjectProperties::newStyleDatabase );
connect( mCoordinateDisplayComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, [ = ]( int ) { updateGuiForCoordinateType(); } );
connect( mCoordinateCrs, &QgsProjectionSelectionWidget::crsChanged, this, [ = ]( const QgsCoordinateReferenceSystem & ) { updateGuiForCoordinateCrs(); } );
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
connect( mAddIccProfile, &QToolButton::clicked, this, static_cast<void ( QgsProjectProperties::* )()>( &QgsProjectProperties::addIccProfile ) );
connect( mRemoveIccProfile, &QToolButton::clicked, this, &QgsProjectProperties::removeIccProfile );
connect( mSaveIccProfile, &QToolButton::clicked, this, &QgsProjectProperties::saveIccProfile );
#endif

// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
Expand Down Expand Up @@ -1025,6 +1031,20 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
// Random colors
cbxStyleRandomColors->setChecked( QgsProject::instance()->styleSettings()->randomizeDefaultSymbolColor() );

mColorModel->addItem( tr( "RGB" ), QVariant::fromValue( Qgis::ColorModel::Rgb ) );
mColorModel->addItem( tr( "CMYK" ), QVariant::fromValue( Qgis::ColorModel::Cmyk ) );
mColorModel->setCurrentIndex( mColorModel->findData( QVariant::fromValue( QgsProject::instance()->styleSettings()->colorModel() ) ) );

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
mColorSpace = QgsProject::instance()->styleSettings()->colorSpace();
updateColorSpaceWidgets();
#else
mIccProfileLabel->setVisible( false );
mColorSpaceName->setVisible( false );
mAddIccProfile->setVisible( false );
mRemoveIccProfile->setVisible( false );
mSaveIccProfile->setVisible( false );
#endif
// Default alpha transparency
mDefaultOpacityWidget->setOpacity( QgsProject::instance()->styleSettings()->defaultSymbolOpacity() );

Expand Down Expand Up @@ -1733,6 +1753,8 @@ void QgsProjectProperties::apply()
QgsProject::instance()->styleSettings()->setDefaultTextFormat( mStyleTextFormat->textFormat() );
QgsProject::instance()->styleSettings()->setRandomizeDefaultSymbolColor( cbxStyleRandomColors->isChecked() );
QgsProject::instance()->styleSettings()->setDefaultSymbolOpacity( mDefaultOpacityWidget->opacity() );
QgsProject::instance()->styleSettings()->setColorModel( mColorModel->currentData().value<Qgis::ColorModel>() );
QgsProject::instance()->styleSettings()->setColorSpace( mColorSpace );

{
QStringList styleDatabasePaths;
Expand Down Expand Up @@ -2680,6 +2702,77 @@ void QgsProjectProperties::removeStyleDatabase()
delete mListStyleDatabases->takeItem( currentRow );
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)

void QgsProjectProperties::addIccProfile()
{
const QString iccProfileFilePath = QFileDialog::getOpenFileName(
this,
tr( "Load ICC Profile" ),
QDir::homePath(),
tr( "ICC Profile" ) + QStringLiteral( " (*.icc)" ) );

addIccProfile( iccProfileFilePath );
}

void QgsProjectProperties::addIccProfile( const QString &iccProfileFilePath )
{
if ( iccProfileFilePath.isEmpty() )
return;

QString errorMsg;
QColorSpace colorSpace = QgsColorUtils::iccProfile( iccProfileFilePath, errorMsg );
if ( !colorSpace.isValid() )
{
QMessageBox::warning( this, tr( "Load ICC Profile" ), errorMsg );
return;
}

mColorSpace = colorSpace;
updateColorSpaceWidgets();
}

void QgsProjectProperties::removeIccProfile()
{
mColorSpace = QColorSpace();
updateColorSpaceWidgets();
}

void QgsProjectProperties::saveIccProfile()
{
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save ICC Profile" ), QDir::homePath(),
tr( "ICC profile files (*.icc *.ICC)" ) );

if ( fileName.isEmpty() )
return;

fileName = QgsFileUtils::ensureFileNameHasExtension( fileName, { QStringLiteral( "icc" ) } );
const QString error = QgsColorUtils::saveIccProfile( mColorSpace, fileName );
nyalldawson marked this conversation as resolved.
Show resolved Hide resolved
if ( !error.isEmpty() )
{
QMessageBox::warning( this, tr( "Save ICC profile" ), error );
}
}


void QgsProjectProperties::updateColorSpaceWidgets()
{
mColorSpaceName->setText( mColorSpace.isValid() ? mColorSpace.description() : tr( "<i>None</i>" ) );
mRemoveIccProfile->setEnabled( mColorSpace.isValid() );
mSaveIccProfile->setEnabled( mColorSpace.isValid() );

// force color model index according to color space one
if ( mColorSpace.isValid() )
{
const Qgis::ColorModel colorModel = QgsColorUtils::toColorModel( mColorSpace.colorModel() );
mColorModel->setCurrentIndex( mColorModel->findData( QVariant::fromValue( colorModel ) ) );
}

mColorModel->setEnabled( !mColorSpace.isValid() );
}

#endif

QListWidgetItem *QgsProjectProperties::addScaleToScaleList( const double newScaleDenominator )
{
// TODO QGIS3: Rework the scale list widget to be a reusable piece of code, see PR #2558
Expand Down
31 changes: 31 additions & 0 deletions src/app/qgsprojectproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "qgis_app.h"

#include <QList>
#include <QColorSpace>

class QgsMapCanvas;
class QgsRelationManagerDialog;
Expand Down Expand Up @@ -204,6 +205,35 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
void removeStyleDatabase();
void newStyleDatabase();

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)

/**
* Called whenever user select the add ICC profile button
*/
void addIccProfile();

/**
* load \a iccProfileFilePath and set resulting color space to project
*/
void addIccProfile( const QString &iccProfileFilePath );

/**
* Called whenever user select the remove ICC profile button
*/
void removeIccProfile();

/**
* Called whenever user select the save ICC profile button
*/
void saveIccProfile();

/**
* Update color space widget according to current project color space
*/
void updateColorSpaceWidgets();

#endif

private:

/**
Expand Down Expand Up @@ -240,6 +270,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
QList<EllipsoidDefs> mEllipsoidList;
int mEllipsoidIndex;
bool mBlockCrsUpdates = false;
QColorSpace mColorSpace;

QList< QgsOptionsPageWidget * > mAdditionalProjectPropertiesWidgets;

Expand Down
16 changes: 16 additions & 0 deletions src/core/qgscolorutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ QColorSpace QgsColorUtils::iccProfile( const QString &iccProfileFilePath, QStrin
return colorSpace;
}


QString QgsColorUtils::saveIccProfile( const QColorSpace &colorSpace, const QString &iccProfileFilePath )
{
if ( !colorSpace.isValid() )
return QObject::tr( "Invalid ICC profile" );

QFile iccProfile( iccProfileFilePath );
if ( !iccProfile.open( QIODevice::WriteOnly ) )
return QObject::tr( "File access error '%1'" ).arg( iccProfileFilePath );

if ( iccProfile.write( colorSpace.iccProfile() ) < 0 )
return QObject::tr( "Error while writing to file '%1'" ).arg( iccProfileFilePath );

return QString();
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)

Qgis::ColorModel QgsColorUtils::toColorModel( QColorSpace::ColorModel colorModel, bool *ok )
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgscolorutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ class CORE_EXPORT QgsColorUtils
*/
static QColorSpace iccProfile( const QString &iccProfileFilePath, QString &errorMsg SIP_OUT );

/**
* Save color space \a colorSpace to an ICC profile file \a iccProfileFilePath.
* \returns error message if an error occurred else empty string.
*
* \since QGIS 3.40
*/
static QString saveIccProfile( const QColorSpace &colorSpace, const QString &iccProfileFilePath );


#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)

/**
Expand Down
Loading
Loading