25 #include <QAbstractListModel> 28 #include <QFileDialog> 29 #include <QModelIndex> 30 #include <QPixmapCache> 61 if ( role == Qt::DecorationRole )
68 double outlineWidth, fillOpacity, outlineOpacity;
69 bool fillParam, fillOpacityParam, outlineParam, outlineWidthParam, outlineOpacityParam;
70 bool hasDefaultFillColor =
false, hasDefaultFillOpacity =
false, hasDefaultOutlineColor =
false,
71 hasDefaultOutlineWidth =
false, hasDefaultOutlineOpacity =
false;
73 fillOpacityParam, hasDefaultFillOpacity, fillOpacity,
74 outlineParam, hasDefaultOutlineColor, outline,
75 outlineWidthParam, hasDefaultOutlineWidth, outlineWidth,
76 outlineOpacityParam, hasDefaultOutlineOpacity, outlineOpacity );
79 if ( !hasDefaultFillColor )
80 fill =
QColor( 200, 200, 200 );
81 fill.
setAlphaF( hasDefaultFillOpacity ? fillOpacity : 1.0 );
82 if ( !hasDefaultOutlineColor )
84 outline.
setAlphaF( hasDefaultOutlineOpacity ? outlineOpacity : 1.0 );
85 if ( !hasDefaultOutlineWidth )
96 else if ( role == Qt::UserRole || role == Qt::ToolTipRole )
113 for (
int i = 0; i < svgPaths.
size(); i++ )
115 QDir dir( svgPaths[i] );
136 createTree( baseGroup );
141 void QgsSvgSelectorGroupsModel::createTree(
QStandardItem* &parentGroup )
144 Q_FOREACH (
const QString&
item, parentDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
166 mGroupsTreeView->setHeaderHidden(
true );
170 this, SLOT( svgSelectionChanged(
const QModelIndex& ) ) );
172 this, SLOT( populateIcons(
const QModelIndex& ) ) );
176 || settings.value(
"/Windows/SvgSelectorWidget/RelativePath" ).toBool() );
177 mRelativePathChkBx->setChecked( useRelativePath );
183 settings.
setValue(
"/Windows/SvgSelectorWidget/RelativePath", mRelativePathChkBx->isChecked() );
191 if ( !svgPath.
contains(
"://" ) || ( svgPath.
contains(
"file://", Qt::CaseInsensitive ) ) )
194 if ( !resolvedPath.
isNull() )
196 updatedPath = resolvedPath;
200 mCurrentSvgPath = updatedPath;
202 mFileLineEdit->blockSignals(
true );
203 mFileLineEdit->setText( updatedPath );
204 mFileLineEdit->blockSignals(
false );
206 mImagesListView->selectionModel()->blockSignals(
true );
209 for (
int i = 0; i < m->
rowCount(); i++ )
214 selModel->
select( idx, QItemSelectionModel::SelectCurrent );
216 mImagesListView->scrollTo( idx );
220 mImagesListView->selectionModel()->blockSignals(
false );
225 if ( mRelativePathChkBx->isChecked() )
228 return mCurrentSvgPath;
236 void QgsSvgSelectorWidget::updateCurrentSvgPath(
const QString& svgPath )
238 mCurrentSvgPath = svgPath;
242 void QgsSvgSelectorWidget::svgSelectionChanged(
const QModelIndex& idx )
245 mFileLineEdit->setText( filePath );
246 updateCurrentSvgPath( filePath );
249 void QgsSvgSelectorWidget::populateIcons(
const QModelIndex& idx )
254 mImagesListView->setModel( m );
257 this, SLOT( svgSelectionChanged(
const QModelIndex& ) ) );
260 void QgsSvgSelectorWidget::on_mFilePushButton_clicked()
265 QString lineEditText = mFileLineEdit->text();
268 QFileInfo openDirFileInfo( lineEditText );
269 openDir = openDirFileInfo.
path();
273 tr(
"Select SVG file" ),
275 tr(
"SVG files" ) +
" (*.svg *.SVG)" );
285 updateCurrentSvgPath(
QString() );
286 updateLineEditFeedback(
false );
290 mFileLineEdit->setText( file );
291 updateCurrentSvgPath( file );
294 void QgsSvgSelectorWidget::updateLineEditFeedback(
bool ok,
const QString& tip )
297 mFileLineEdit->setStyleSheet(
QString( !ok ?
"QLineEdit{ color: rgb(225, 0, 0); }" :
"" ) );
298 mFileLineEdit->setToolTip( !ok ?
tr(
"File not found" ) : tip );
301 void QgsSvgSelectorWidget::on_mFileLineEdit_textChanged(
const QString& text )
304 bool validSVG = !resolvedPath.
isNull();
306 updateLineEditFeedback( validSVG, resolvedPath );
307 updateCurrentSvgPath( validSVG ? resolvedPath :
QString() );
313 mGroupsTreeView->setModel( g );
316 for (
int i = 0; i < rows; i++ )
323 mImagesListView->setModel( m );
330 Qt::Orientation orientation )
334 Q_UNUSED( orientation );
QgsSvgSelectorWidget * mSvgSelector
QByteArray toByteArray() const
virtual int rowCount(const QModelIndex &parent) const =0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
void setIcon(const QIcon &icon)
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
QStandardItem * invisibleRootItem() const
const T & at(int i) const
QgsSvgSelectorGroupsModel(QObject *parent)
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
static QStringList listSvgFilesAt(const QString &directory)
Return a list of svg files at the specified directory.
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual void setData(const QVariant &value, int role)
void containsParams(const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasOutlineParam, QColor &defaultOutlineColor, bool &hasOutlineWidthParam, double &defaultOutlineWidth) const
Tests if an svg file contains parameters for fill, outline color, outline width.
static QgsSvgCache * instance()
void setValue(const QString &key, const QVariant &value)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
const QImage & svgAsImage(const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, bool &fitsInCache)
Get SVG as QImage.
static QString symbolPathToName(QString path)
Get symbols's name from its path.
int count(const T &value) const
QModelIndex indexFromItem(const QStandardItem *item) const
QDialogButtonBox * mButtonBox
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
void appendRow(const QList< QStandardItem * > &items)
static QStringList listSvgFiles()
Return a list of all available svg files.
virtual void select(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
static QString symbolNameToPath(QString name)
Get symbol's path from its name.
virtual QVariant data(const QModelIndex &index, int role) const =0
QgsSvgSelectorDialog(QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags, const QDialogButtonBox::StandardButtons &buttons=QDialogButtonBox::Close|QDialogButtonBox::Ok, Qt::Orientation orientation=Qt::Horizontal)
QStandardItem * item(int row, int column) const
static QString pkgDataPath()
Returns the common root path of all application data directories.
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QgsSvgSelectorListModel(QObject *parent)
QVariant value(const QString &key, const QVariant &defaultValue) const
QVariant data(int role) const
static QgsProject * instance()
access to canonical QgsProject instance
QPixmap * find(const QString &key)
virtual int rowCount(const QModelIndex &parent) const
static QStringList svgPaths()
Returns the pathes to svg directories.
void setAlphaF(qreal alpha)
void setCurrentIndex(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
bool insert(const QString &key, const QPixmap &pixmap)
QString absolutePath() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setCheckable(bool checkable)
virtual QVariant data(int role) const
void setEditable(bool editable)