QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgscolorschemelist.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorschemelist.cpp
3  ----------------------
4  Date : August 2014
5  Copyright : (C) 2014 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgscolorschemelist.h"
17 #include "qgsapplication.h"
18 #include "qgslogger.h"
19 #include "qgssymbollayerv2utils.h"
20 #include "qgscolordialog.h"
21 #include <QPainter>
22 #include <QColorDialog>
23 #include <QMimeData>
24 #include <QClipboard>
25 #include <QKeyEvent>
26 
27 #ifdef ENABLE_MODELTEST
28 #include "modeltest.h"
29 #endif
30 
31 QgsColorSchemeList::QgsColorSchemeList( QWidget *parent, QgsColorScheme *scheme, const QString &context, const QColor &baseColor )
32  : QTreeView( parent )
33  , mScheme( scheme )
34 {
35  mModel = new QgsColorSchemeModel( scheme, context, baseColor, this );
36 #ifdef ENABLE_MODELTEST
37  new ModelTest( mModel, this );
38 #endif
39  setModel( mModel );
40 
41  mSwatchDelegate = new QgsColorSwatchDelegate( this );
42  setItemDelegateForColumn( 0, mSwatchDelegate );
43 
44  setRootIsDecorated( false );
45  setSelectionMode( QAbstractItemView::ExtendedSelection );
46  setSelectionBehavior( QAbstractItemView::SelectRows );
47  setDragEnabled( true );
48  setAcceptDrops( true );
49  setDragDropMode( QTreeView::DragDrop );
50  setDropIndicatorShown( true );
51  setDefaultDropAction( Qt::CopyAction );
52 }
53 
55 {
56 
57 }
58 
59 void QgsColorSchemeList::setScheme( QgsColorScheme *scheme, const QString &context, const QColor &baseColor )
60 {
61  mScheme = scheme;
62  mModel->setScheme( scheme, context, baseColor );
63 }
64 
66 {
67  if ( !mScheme || !mScheme->isEditable() )
68  {
69  return false;
70  }
71 
72  mScheme->setColors( mModel->colors(), mModel->context(), mModel->baseColor() );
73  return true;
74 }
75 
77 {
78  QList<int> rows;
79  Q_FOREACH ( const QModelIndex &index, selectedIndexes() )
80  {
81  rows << index.row();
82  }
83  //remove duplicates
84  QList<int> rowsToRemove = QList<int>::fromSet( rows.toSet() );
85 
86  //remove rows in descending order
87  qSort( rowsToRemove.begin(), rowsToRemove.end(), qGreater<int>() );
88  Q_FOREACH ( int row, rowsToRemove )
89  {
90  mModel->removeRow( row );
91  }
92 }
93 
94 void QgsColorSchemeList::addColor( const QColor &color, const QString &label )
95 {
96  mModel->addColor( color, label );
97 }
98 
100 {
102 
103  if ( pastedColors.length() == 0 )
104  {
105  //no pasted colors
106  return;
107  }
108 
109  //insert pasted colors
110  QgsNamedColorList::const_iterator colorIt = pastedColors.constBegin();
111  for ( ; colorIt != pastedColors.constEnd(); ++colorIt )
112  {
113  mModel->addColor(( *colorIt ).first, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
114  }
115 }
116 
118 {
119  QList<int> rows;
120  Q_FOREACH ( const QModelIndex &index, selectedIndexes() )
121  {
122  rows << index.row();
123  }
124  //remove duplicates
125  QList<int> rowsToCopy = QList<int>::fromSet( rows.toSet() );
126 
127  QgsNamedColorList colorsToCopy;
128  Q_FOREACH ( int row, rowsToCopy )
129  {
130  colorsToCopy << mModel->colors().at( row );
131  }
132 
133  //copy colors
134  QMimeData* mimeData = QgsSymbolLayerV2Utils::colorListToMimeData( colorsToCopy );
135  QApplication::clipboard()->setMimeData( mimeData );
136 }
137 
139 {
140  //listen out for delete/backspace presses and remove selected colors
141  if (( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) )
142  {
143  QList<int> rows;
144  Q_FOREACH ( const QModelIndex &index, selectedIndexes() )
145  {
146  rows << index.row();
147  }
148  //remove duplicates
149  QList<int> rowsToRemove = QList<int>::fromSet( rows.toSet() );
150 
151  //remove rows in descending order
152  qSort( rowsToRemove.begin(), rowsToRemove.end(), qGreater<int>() );
153  Q_FOREACH ( int row, rowsToRemove )
154  {
155  mModel->removeRow( row );
156  }
157  return;
158  }
159 
160  QTreeView::keyPressEvent( event );
161 }
162 
164 {
165  if ( event->button() == Qt::LeftButton )
166  {
167  //record press start position
168  mDragStartPosition = event->pos();
169  }
171 }
172 
174 {
175  if (( event->button() == Qt::LeftButton ) &&
176  ( event->pos() - mDragStartPosition ).manhattanLength() <= QApplication::startDragDistance() )
177  {
178  //just a click, not a drag
179 
180  //if only one item is selected, emit color changed signal
181  //(if multiple are selected, user probably was interacting with color list rather than trying to pick a color)
182  if ( selectedIndexes().length() == mModel->columnCount() )
183  {
184  QModelIndex selectedColor = selectedIndexes().at( 0 );
185  emit colorSelected( mModel->colors().at( selectedColor.row() ).first );
186  }
187  }
188 
190 }
191 
193 {
194  QgsNamedColorList importedColors;
195  bool ok = false;
196  QString name;
197  importedColors = QgsSymbolLayerV2Utils::importColorsFromGpl( file, ok, name );
198  if ( !ok )
199  {
200  return false;
201  }
202 
203  if ( importedColors.length() == 0 )
204  {
205  //no imported colors
206  return false;
207  }
208 
209  //insert imported colors
210  QgsNamedColorList::const_iterator colorIt = importedColors.constBegin();
211  for ( ; colorIt != importedColors.constEnd(); ++colorIt )
212  {
213  mModel->addColor(( *colorIt ).first, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
214  }
215 
216  return true;
217 }
218 
220 {
221  return QgsSymbolLayerV2Utils::saveColorsToGpl( file, QString(), mModel->colors() );
222 }
223 
225 {
226  if ( !mModel )
227  {
228  return false;
229  }
230 
231  return mModel->isDirty();
232 }
233 
235 {
236  return mScheme;
237 }
238 
239 //
240 // QgsColorSchemeModel
241 //
242 
244  : QAbstractItemModel( parent )
245  , mScheme( scheme )
246  , mContext( context )
247  , mBaseColor( baseColor )
248  , mIsDirty( false )
249 {
250  if ( scheme )
251  {
252  mColors = scheme->fetchColors( context, baseColor );
253  }
254 }
255 
257 {
258 
259 }
260 
261 QModelIndex QgsColorSchemeModel::index( int row, int column, const QModelIndex &parent ) const
262 {
263  if ( column < 0 || column >= columnCount() )
264  {
265  //column out of bounds
266  return QModelIndex();
267  }
268 
269  if ( !parent.isValid() && row >= 0 && row < mColors.size() )
270  {
271  //return an index for the composer item at this position
272  return createIndex( row, column );
273  }
274 
275  //only top level supported
276  return QModelIndex();
277 }
278 
280 {
281  Q_UNUSED( index );
282 
283  //all items are top level
284  return QModelIndex();
285 }
286 
288 {
289  if ( !parent.isValid() )
290  {
291  return mColors.size();
292  }
293  else
294  {
295  //no children
296  return 0;
297  }
298 }
299 
301 {
302  Q_UNUSED( parent );
303  return 2;
304 }
305 
307 {
308  if ( !index.isValid() )
309  return QVariant();
310 
311  QPair< QColor, QString > namedColor = mColors.at( index.row() );
312  switch ( role )
313  {
314  case Qt::DisplayRole:
315  case Qt::EditRole:
316  switch ( index.column() )
317  {
318  case ColorSwatch:
319  return namedColor.first;
320  case ColorLabel:
321  return namedColor.second;
322  default:
323  return QVariant();
324  }
325 
326  case Qt::TextAlignmentRole:
327  return QVariant( Qt::AlignLeft | Qt::AlignVCenter );
328 
329  default:
330  return QVariant();
331  }
332 }
333 
335 {
337 
338  if ( ! index.isValid() )
339  {
340  return flags | Qt::ItemIsDropEnabled;
341  }
342 
343  switch ( index.column() )
344  {
345  case ColorSwatch:
346  case ColorLabel:
347  if ( mScheme && mScheme->isEditable() )
348  {
349  flags = flags | Qt::ItemIsEditable;
350  }
351  return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
352  default:
353  return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
354  }
355 }
356 
357 bool QgsColorSchemeModel::setData( const QModelIndex &index, const QVariant &value, int role )
358 {
359  Q_UNUSED( role );
360 
361  if ( !mScheme || !mScheme->isEditable() )
362  return false;
363 
364  if ( !index.isValid() )
365  return false;
366 
367  if ( index.row() >= mColors.length() )
368  return false;
369 
370  switch ( index.column() )
371  {
372  case ColorSwatch:
373  mColors[ index.row()].first = value.value<QColor>();
374  emit dataChanged( index, index );
375  mIsDirty = true;
376  return true;
377 
378  case ColorLabel:
379  mColors[ index.row()].second = value.toString();
380  emit dataChanged( index, index );
381  mIsDirty = true;
382  return true;
383 
384  default:
385  return false;
386  }
387 }
388 
389 QVariant QgsColorSchemeModel::headerData( int section, Qt::Orientation orientation, int role ) const
390 {
391  switch ( role )
392  {
393  case Qt::DisplayRole:
394  {
395  switch ( section )
396  {
397  case ColorSwatch:
398  return tr( "Color" );
399  case ColorLabel:
400  return tr( "Label" );
401  default:
402  return QVariant();
403  }
404  }
405 
406  case Qt::TextAlignmentRole:
407  switch ( section )
408  {
409  case ColorSwatch:
410  return QVariant( Qt::AlignHCenter | Qt::AlignVCenter );
411  case ColorLabel:
412  return QVariant( Qt::AlignLeft | Qt::AlignVCenter );
413  default:
414  return QVariant();
415  }
416  default:
417  return QAbstractItemModel::headerData( section, orientation, role );
418  }
419 }
420 
422 {
423  if ( mScheme && mScheme->isEditable() )
424  {
425  return Qt::CopyAction | Qt::MoveAction;
426  }
427  else
428  {
429  return Qt::CopyAction;
430  }
431 }
432 
434 {
435  if ( !mScheme || !mScheme->isEditable() )
436  {
437  return QStringList();
438  }
439 
440  QStringList types;
441  types << "text/xml";
442  types << "text/plain";
443  types << "application/x-color";
444  types << "application/x-colorobject-list";
445  return types;
446 }
447 
448 QMimeData* QgsColorSchemeModel::mimeData( const QModelIndexList &indexes ) const
449 {
450  QgsNamedColorList colorList;
451 
452  QModelIndexList::const_iterator indexIt = indexes.constBegin();
453  for ( ; indexIt != indexes.constEnd(); ++indexIt )
454  {
455  if (( *indexIt ).column() > 0 )
456  continue;
457 
458  colorList << qMakePair( mColors[( *indexIt ).row()].first, mColors[( *indexIt ).row()].second );
459  }
460 
462  return mimeData;
463 }
464 
465 bool QgsColorSchemeModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
466 {
467  Q_UNUSED( column );
468 
469  if ( !mScheme || !mScheme->isEditable() )
470  {
471  return false;
472  }
473 
474  if ( action == Qt::IgnoreAction )
475  {
476  return true;
477  }
478 
479  if ( parent.isValid() )
480  {
481  return false;
482  }
483 
484  int beginRow = row != -1 ? row : rowCount( QModelIndex() );
486 
487  if ( droppedColors.length() == 0 )
488  {
489  //no dropped colors
490  return false;
491  }
492 
493  //any existing colors? if so, remove them first
494  QgsNamedColorList::const_iterator colorIt = droppedColors.constBegin();
495  for ( ; colorIt != droppedColors.constEnd(); ++colorIt )
496  {
497  //dest color
498  QPair< QColor, QString > color = qMakePair(( *colorIt ).first, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
499  //if color already exists, remove it
500  int existingIndex = mColors.indexOf( color );
501  if ( existingIndex >= 0 )
502  {
503  if ( existingIndex < beginRow )
504  {
505  //color is before destination row, so decrease destination row to account for removal
506  beginRow--;
507  }
508 
509  beginRemoveRows( parent, existingIndex, existingIndex );
510  mColors.removeAt( existingIndex );
511  endRemoveRows();
512  }
513  }
514 
515  //insert dropped colors
516  insertRows( beginRow, droppedColors.length(), QModelIndex() );
517  colorIt = droppedColors.constBegin();
518  for ( ; colorIt != droppedColors.constEnd(); ++colorIt )
519  {
520  QModelIndex colorIdx = index( beginRow, 0, QModelIndex() );
521  setData( colorIdx, QVariant(( *colorIt ).first ) );
522  QModelIndex labelIdx = index( beginRow, 1, QModelIndex() );
523  setData( labelIdx, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
524  beginRow++;
525  }
526  mIsDirty = true;
527 
528  return true;
529 }
530 
532 {
533  mScheme = scheme;
534  mContext = context;
535  mBaseColor = baseColor;
536  mIsDirty = false;
537  beginResetModel();
538  mColors = scheme->fetchColors( mContext, mBaseColor );
539  endResetModel();
540 }
541 
542 bool QgsColorSchemeModel::removeRows( int row, int count, const QModelIndex &parent )
543 {
544  if ( !mScheme || !mScheme->isEditable() )
545  {
546  return false;
547  }
548 
549  if ( parent.isValid() )
550  {
551  return false;
552  }
553 
554  if ( row >= mColors.count() )
555  {
556  return false;
557  }
558 
559  for ( int i = row + count - 1; i >= row; --i )
560  {
561  beginRemoveRows( parent, i, i );
562  mColors.removeAt( i );
563  endRemoveRows();
564  }
565 
566  mIsDirty = true;
567  return true;
568 }
569 
570 bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& parent )
571 {
572  Q_UNUSED( parent );
573 
574  if ( !mScheme || !mScheme->isEditable() )
575  {
576  return false;
577  }
578 
579  beginInsertRows( QModelIndex(), row, row + count - 1 );
580  for ( int i = row; i < row + count; ++i )
581  {
582  QPair< QColor, QString > newColor;
583  mColors.insert( i, newColor );
584  }
585  endInsertRows();
586  mIsDirty = true;
587  return true;
588 }
589 
590 void QgsColorSchemeModel::addColor( const QColor &color, const QString &label )
591 {
592  if ( !mScheme || !mScheme->isEditable() )
593  {
594  return;
595  }
596 
597  //matches existing color? if so, remove it first
598  QPair< QColor, QString > newColor = qMakePair( color, !label.isEmpty() ? label : QgsSymbolLayerV2Utils::colorToName( color ) );
599  //if color already exists, remove it
600  int existingIndex = mColors.indexOf( newColor );
601  if ( existingIndex >= 0 )
602  {
603  beginRemoveRows( QModelIndex(), existingIndex, existingIndex );
604  mColors.removeAt( existingIndex );
605  endRemoveRows();
606  }
607 
608  int row = rowCount();
609  insertRow( row );
610  QModelIndex colorIdx = index( row, 0, QModelIndex() );
611  setData( colorIdx, QVariant( color ) );
612  QModelIndex labelIdx = index( row, 1, QModelIndex() );
613  setData( labelIdx, QVariant( label ) );
614  mIsDirty = true;
615 }
616 
617 
618 //
619 // QgsColorSwatchDelegate
620 //
622  : QAbstractItemDelegate( parent )
623  , mParent( parent )
624 {
625 
626 }
627 
628 void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
629 {
630  if ( option.state & QStyle::State_Selected )
631  {
632  painter->setPen( QPen( Qt::NoPen ) );
633  if ( option.state & QStyle::State_Active )
634  {
635  painter->setBrush( QBrush( QPalette().highlight() ) );
636  }
637  else
638  {
639  painter->setBrush( QBrush( QPalette().color( QPalette::Inactive,
640  QPalette::Highlight ) ) );
641  }
642  painter->drawRect( option.rect );
643  }
644 
645  QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();
646  if ( !color.isValid() )
647  {
648  return;
649  }
650 
651  QRect rect = option.rect;
652  //center it
653  rect.setLeft( option.rect.center().x() - 15 );
654  rect.setSize( QSize( 30, 30 ) );
655  rect.adjust( 0, 1, 0, 1 );
656  //create an icon pixmap
657  painter->save();
658  painter->setRenderHint( QPainter::Antialiasing );
659  painter->setPen( Qt::NoPen );
660  if ( color.alpha() < 255 )
661  {
662  //start with checkboard pattern
663  QBrush checkBrush = QBrush( transparentBackground() );
664  painter->setBrush( checkBrush );
665  painter->drawRoundedRect( rect, 5, 5 );
666  }
667 
668  //draw semi-transparent color on top
669  painter->setBrush( color );
670  painter->drawRoundedRect( rect, 5, 5 );
671  painter->restore();
672 }
673 
674 const QPixmap& QgsColorSwatchDelegate::transparentBackground() const
675 {
676  static QPixmap transpBkgrd;
677 
678  if ( transpBkgrd.isNull() )
679  transpBkgrd = QgsApplication::getThemePixmap( "/transp-background_8x8.png" );
680 
681  return transpBkgrd;
682 }
683 
685 {
686  Q_UNUSED( option );
687  Q_UNUSED( index );
688  return QSize( 30, 32 );
689 }
690 
692 {
693  Q_UNUSED( option );
694  if ( event->type() == QEvent::MouseButtonDblClick )
695  {
696  if ( !index.model()->flags( index ).testFlag( Qt::ItemIsEditable ) )
697  {
698  //item not editable
699  return false;
700  }
701  QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();
702  QColor newColor = QgsColorDialogV2::getColor( color, mParent, tr( "Select color" ), true );
703  if ( !newColor.isValid() )
704  {
705  return false;
706  }
707 
708  return model->setData( index, newColor, Qt::EditRole );
709  }
710 
711  return false;
712 }
bool insertRow(int row, const QModelIndex &parent)
Qt::DropActions supportedDropActions() const override
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
static unsigned index
bool exportColorsToGpl(QFile &file)
Export colors to a GPL palette file from the list.
void addColor(const QColor &color, const QString &label=QString())
Add a color to the list.
Type type() const
void colorSelected(const QColor &color)
Emitted when a color is selected from the list.
QgsNamedColorList colors() const
Returns a list of colors shown in the widget.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void removeSelection()
Removes any selected colors from the list.
void setRenderHint(RenderHint hint, bool on)
QColor baseColor() const
Get the base color for the color scheme used by the model.
int length() const
Abstract base class for color schemes.
QString context() const
Get the current color scheme context for the model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bool removeRow(int row, const QModelIndex &parent)
const T & at(int i) const
void removeAt(int i)
void setDragDropMode(DragDropMode behavior)
void save()
T value() const
void setScheme(QgsColorScheme *scheme, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the color scheme to show in the widget.
Qt::ItemFlags flags(const QModelIndex &index) const override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
QSet< T > toSet() const
void setScheme(QgsColorScheme *scheme, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the color scheme to show in the list.
void pasteColors()
Pastes colors from clipboard to the list.
QgsColorSchemeModel(QgsColorScheme *scheme, const QString &context=QString(), const QColor &baseColor=QColor(), QObject *parent=nullptr)
Constructor.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QString tr(const char *sourceText, const char *disambiguation, int n)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
static QPixmap getThemePixmap(const QString &theName)
Helper to get a theme icon as a pixmap.
bool importColorsFromGpl(QFile &file)
Import colors from a GPL palette file to the list.
int size() const
void mouseReleaseEvent(QMouseEvent *event) override
virtual bool event(QEvent *e)
int indexOf(const T &value, int from) const
QList< T > fromSet(const QSet< T > &set)
void drawRect(const QRectF &rectangle)
const char * name() const
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
bool isValid() const
QgsColorScheme * scheme()
Returns the scheme currently selected in the list.
int count(const T &value) const
void mousePressEvent(QMouseEvent *event) override
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QClipboard * clipboard()
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file.
void setPen(const QColor &color)
Qt::MouseButton button() const
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
bool isEmpty() const
void beginRemoveRows(const QModelIndex &parent, int first, int last)
int row() const
void setBrush(const QBrush &brush)
virtual QVariant data(const QModelIndex &index, int role) const=0
T & first()
bool isDirty() const
Returns whether the color scheme list has been modified.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void setMimeData(QMimeData *src, Mode mode)
virtual void mouseReleaseEvent(QMouseEvent *event)
int alpha() const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
void setAcceptDrops(bool on)
QModelIndex createIndex(int row, int column, void *ptr) const
QgsColorSwatchDelegate(QWidget *parent=nullptr)
iterator end()
int key() const
bool isNull() const
bool saveColorsToScheme()
Saves the current colors shown in the list back to a color scheme, if supported by the color scheme...
void addColor(const QColor &color, const QString &label=QString())
Adds a color to the list.
void beginInsertRows(const QModelIndex &parent, int first, int last)
void restore()
virtual bool isEditable() const
Returns whether the color scheme is editable.
virtual bool event(QEvent *event)
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), const bool allowAlpha=false)
Return a color selection from a color dialog.
const QAbstractItemModel * model() const
bool isDirty() const
Returns whether the color scheme model has been modified.
typedef DropActions
void copyColors()
Copies colors from the list to the clipboard.
void insert(int i, const T &value)
static QMimeData * colorListToMimeData(const QgsNamedColorList &colorList, const bool allFormats=true)
Creates mime data from a list of named colors.
virtual void setModel(QAbstractItemModel *model)
virtual QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor())=0
Gets a list of colors from the scheme.
QStringList mimeTypes() const override
void adjust(int dx1, int dy1, int dx2, int dy2)
QgsColorSchemeList(QWidget *parent=nullptr, QgsColorScheme *scheme=nullptr, const QString &context=QString(), const QColor &baseColor=QColor())
Construct a new color swatch grid.
int column() const
virtual QModelIndexList selectedIndexes() const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual void mousePressEvent(QMouseEvent *event)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void keyPressEvent(QKeyEvent *event) override
const QPoint & pos() const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setDefaultDropAction(Qt::DropAction dropAction)
const_iterator constEnd() const
const_iterator constBegin() const
void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate)
virtual void keyPressEvent(QKeyEvent *event)
void setRootIsDecorated(bool show)
QObject * parent() const
void setSize(const QSize &size)
QString toString() const
void setLeft(int x)
static bool saveColorsToGpl(QFile &file, const QString &paletteName, const QgsNamedColorList &colors)
Exports colors to a gpl GIMP palette file.
iterator begin()
virtual bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the colors for the scheme.
A delegate for showing a color swatch in a list.
QMimeData * mimeData(const QModelIndexList &indexes) const override
void setDropIndicatorShown(bool enable)
int startDragDistance()
bool isValid() const
void setDragEnabled(bool enable)
A model for colors in a color scheme.
static QgsNamedColorList colorListFromMimeData(const QMimeData *data)
Attempts to parse mime data as a list of named colors.
typedef ItemFlags