QGIS API Documentation  2.14.0-Essen
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 
234 //
235 // QgsColorSchemeModel
236 //
237 
239  : QAbstractItemModel( parent )
240  , mScheme( scheme )
241  , mContext( context )
242  , mBaseColor( baseColor )
243  , mIsDirty( false )
244 {
245  if ( scheme )
246  {
247  mColors = scheme->fetchColors( context, baseColor );
248  }
249 }
250 
252 {
253 
254 }
255 
256 QModelIndex QgsColorSchemeModel::index( int row, int column, const QModelIndex &parent ) const
257 {
258  if ( column < 0 || column >= columnCount() )
259  {
260  //column out of bounds
261  return QModelIndex();
262  }
263 
264  if ( !parent.isValid() && row >= 0 && row < mColors.size() )
265  {
266  //return an index for the composer item at this position
267  return createIndex( row, column );
268  }
269 
270  //only top level supported
271  return QModelIndex();
272 }
273 
275 {
276  Q_UNUSED( index );
277 
278  //all items are top level
279  return QModelIndex();
280 }
281 
283 {
284  if ( !parent.isValid() )
285  {
286  return mColors.size();
287  }
288  else
289  {
290  //no children
291  return 0;
292  }
293 }
294 
296 {
297  Q_UNUSED( parent );
298  return 2;
299 }
300 
302 {
303  if ( !index.isValid() )
304  return QVariant();
305 
306  QPair< QColor, QString > namedColor = mColors.at( index.row() );
307  switch ( role )
308  {
309  case Qt::DisplayRole:
310  case Qt::EditRole:
311  switch ( index.column() )
312  {
313  case ColorSwatch:
314  return namedColor.first;
315  case ColorLabel:
316  return namedColor.second;
317  default:
318  return QVariant();
319  }
320 
321  case Qt::TextAlignmentRole:
322  return QVariant( Qt::AlignLeft | Qt::AlignVCenter );
323 
324  default:
325  return QVariant();
326  }
327 }
328 
330 {
332 
333  if ( ! index.isValid() )
334  {
335  return flags | Qt::ItemIsDropEnabled;
336  }
337 
338  switch ( index.column() )
339  {
340  case ColorSwatch:
341  case ColorLabel:
342  if ( mScheme && mScheme->isEditable() )
343  {
344  flags = flags | Qt::ItemIsEditable;
345  }
346  return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
347  default:
348  return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
349  }
350 }
351 
352 bool QgsColorSchemeModel::setData( const QModelIndex &index, const QVariant &value, int role )
353 {
354  Q_UNUSED( role );
355 
356  if ( !mScheme || !mScheme->isEditable() )
357  return false;
358 
359  if ( !index.isValid() )
360  return false;
361 
362  if ( index.row() >= mColors.length() )
363  return false;
364 
365  switch ( index.column() )
366  {
367  case ColorSwatch:
368  mColors[ index.row()].first = value.value<QColor>();
369  emit dataChanged( index, index );
370  mIsDirty = true;
371  return true;
372 
373  case ColorLabel:
374  mColors[ index.row()].second = value.toString();
375  emit dataChanged( index, index );
376  mIsDirty = true;
377  return true;
378 
379  default:
380  return false;
381  }
382 }
383 
384 QVariant QgsColorSchemeModel::headerData( int section, Qt::Orientation orientation, int role ) const
385 {
386  switch ( role )
387  {
388  case Qt::DisplayRole:
389  {
390  switch ( section )
391  {
392  case ColorSwatch:
393  return tr( "Color" );
394  case ColorLabel:
395  return tr( "Label" );
396  default:
397  return QVariant();
398  }
399  }
400 
401  case Qt::TextAlignmentRole:
402  switch ( section )
403  {
404  case ColorSwatch:
405  return QVariant( Qt::AlignHCenter | Qt::AlignVCenter );
406  case ColorLabel:
407  return QVariant( Qt::AlignLeft | Qt::AlignVCenter );
408  default:
409  return QVariant();
410  }
411  default:
412  return QAbstractItemModel::headerData( section, orientation, role );
413  }
414 }
415 
417 {
418  if ( mScheme && mScheme->isEditable() )
419  {
420  return Qt::CopyAction | Qt::MoveAction;
421  }
422  else
423  {
424  return Qt::CopyAction;
425  }
426 }
427 
429 {
430  if ( !mScheme || !mScheme->isEditable() )
431  {
432  return QStringList();
433  }
434 
435  QStringList types;
436  types << "text/xml";
437  types << "text/plain";
438  types << "application/x-color";
439  types << "application/x-colorobject-list";
440  return types;
441 }
442 
443 QMimeData* QgsColorSchemeModel::mimeData( const QModelIndexList &indexes ) const
444 {
445  QgsNamedColorList colorList;
446 
447  QModelIndexList::const_iterator indexIt = indexes.constBegin();
448  for ( ; indexIt != indexes.constEnd(); ++indexIt )
449  {
450  if (( *indexIt ).column() > 0 )
451  continue;
452 
453  colorList << qMakePair( mColors[( *indexIt ).row()].first, mColors[( *indexIt ).row()].second );
454  }
455 
457  return mimeData;
458 }
459 
460 bool QgsColorSchemeModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
461 {
462  Q_UNUSED( column );
463 
464  if ( !mScheme || !mScheme->isEditable() )
465  {
466  return false;
467  }
468 
469  if ( action == Qt::IgnoreAction )
470  {
471  return true;
472  }
473 
474  if ( parent.isValid() )
475  {
476  return false;
477  }
478 
479  int beginRow = row != -1 ? row : rowCount( QModelIndex() );
481 
482  if ( droppedColors.length() == 0 )
483  {
484  //no dropped colors
485  return false;
486  }
487 
488  //any existing colors? if so, remove them first
489  QgsNamedColorList::const_iterator colorIt = droppedColors.constBegin();
490  for ( ; colorIt != droppedColors.constEnd(); ++colorIt )
491  {
492  //dest color
493  QPair< QColor, QString > color = qMakePair(( *colorIt ).first, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
494  //if color already exists, remove it
495  int existingIndex = mColors.indexOf( color );
496  if ( existingIndex >= 0 )
497  {
498  if ( existingIndex < beginRow )
499  {
500  //color is before destination row, so decrease destination row to account for removal
501  beginRow--;
502  }
503 
504  beginRemoveRows( parent, existingIndex, existingIndex );
505  mColors.removeAt( existingIndex );
506  endRemoveRows();
507  }
508  }
509 
510  //insert dropped colors
511  insertRows( beginRow, droppedColors.length(), QModelIndex() );
512  colorIt = droppedColors.constBegin();
513  for ( ; colorIt != droppedColors.constEnd(); ++colorIt )
514  {
515  QModelIndex colorIdx = index( beginRow, 0, QModelIndex() );
516  setData( colorIdx, QVariant(( *colorIt ).first ) );
517  QModelIndex labelIdx = index( beginRow, 1, QModelIndex() );
518  setData( labelIdx, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
519  beginRow++;
520  }
521  mIsDirty = true;
522 
523  return true;
524 }
525 
527 {
528  mScheme = scheme;
529  mContext = context;
530  mBaseColor = baseColor;
531  mIsDirty = false;
532  beginResetModel();
533  mColors = scheme->fetchColors( mContext, mBaseColor );
534  endResetModel();
535 }
536 
537 bool QgsColorSchemeModel::removeRows( int row, int count, const QModelIndex &parent )
538 {
539  if ( !mScheme || !mScheme->isEditable() )
540  {
541  return false;
542  }
543 
544  if ( parent.isValid() )
545  {
546  return false;
547  }
548 
549  if ( row >= mColors.count() )
550  {
551  return false;
552  }
553 
554  for ( int i = row + count - 1; i >= row; --i )
555  {
556  beginRemoveRows( parent, i, i );
557  mColors.removeAt( i );
558  endRemoveRows();
559  }
560 
561  mIsDirty = true;
562  return true;
563 }
564 
565 bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& parent )
566 {
567  Q_UNUSED( parent );
568 
569  if ( !mScheme || !mScheme->isEditable() )
570  {
571  return false;
572  }
573 
574  beginInsertRows( QModelIndex(), row, row + count - 1 );
575  for ( int i = row; i < row + count; ++i )
576  {
577  QPair< QColor, QString > newColor;
578  mColors.insert( i, newColor );
579  }
580  endInsertRows();
581  mIsDirty = true;
582  return true;
583 }
584 
585 void QgsColorSchemeModel::addColor( const QColor &color, const QString &label )
586 {
587  if ( !mScheme || !mScheme->isEditable() )
588  {
589  return;
590  }
591 
592  //matches existing color? if so, remove it first
593  QPair< QColor, QString > newColor = qMakePair( color, !label.isEmpty() ? label : QgsSymbolLayerV2Utils::colorToName( color ) );
594  //if color already exists, remove it
595  int existingIndex = mColors.indexOf( newColor );
596  if ( existingIndex >= 0 )
597  {
598  beginRemoveRows( QModelIndex(), existingIndex, existingIndex );
599  mColors.removeAt( existingIndex );
600  endRemoveRows();
601  }
602 
603  int row = rowCount();
604  insertRow( row );
605  QModelIndex colorIdx = index( row, 0, QModelIndex() );
606  setData( colorIdx, QVariant( color ) );
607  QModelIndex labelIdx = index( row, 1, QModelIndex() );
608  setData( labelIdx, QVariant( label ) );
609  mIsDirty = true;
610 }
611 
612 
613 //
614 // QgsColorSwatchDelegate
615 //
617  : QAbstractItemDelegate( parent )
618  , mParent( parent )
619 {
620 
621 }
622 
623 void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
624 {
625  if ( option.state & QStyle::State_Selected )
626  {
627  painter->setPen( QPen( Qt::NoPen ) );
628  if ( option.state & QStyle::State_Active )
629  {
630  painter->setBrush( QBrush( QPalette().highlight() ) );
631  }
632  else
633  {
634  painter->setBrush( QBrush( QPalette().color( QPalette::Inactive,
635  QPalette::Highlight ) ) );
636  }
637  painter->drawRect( option.rect );
638  }
639 
640  QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();
641  if ( !color.isValid() )
642  {
643  return;
644  }
645 
646  QRect rect = option.rect;
647  //center it
648  rect.setLeft( option.rect.center().x() - 15 );
649  rect.setSize( QSize( 30, 30 ) );
650  rect.adjust( 0, 1, 0, 1 );
651  //create an icon pixmap
652  painter->save();
653  painter->setRenderHint( QPainter::Antialiasing );
654  painter->setPen( Qt::NoPen );
655  if ( color.alpha() < 255 )
656  {
657  //start with checkboard pattern
658  QBrush checkBrush = QBrush( transparentBackground() );
659  painter->setBrush( checkBrush );
660  painter->drawRoundedRect( rect, 5, 5 );
661  }
662 
663  //draw semi-transparent color on top
664  painter->setBrush( color );
665  painter->drawRoundedRect( rect, 5, 5 );
666  painter->restore();
667 }
668 
669 const QPixmap& QgsColorSwatchDelegate::transparentBackground() const
670 {
671  static QPixmap transpBkgrd;
672 
673  if ( transpBkgrd.isNull() )
674  transpBkgrd = QgsApplication::getThemePixmap( "/transp-background_8x8.png" );
675 
676  return transpBkgrd;
677 }
678 
680 {
681  Q_UNUSED( option );
682  Q_UNUSED( index );
683  return QSize( 30, 32 );
684 }
685 
687 {
688  Q_UNUSED( option );
689  if ( event->type() == QEvent::MouseButtonDblClick )
690  {
691  if ( !index.model()->flags( index ).testFlag( Qt::ItemIsEditable ) )
692  {
693  //item not editable
694  return false;
695  }
696  QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();
697  QColor newColor = QgsColorDialogV2::getColor( color, mParent, tr( "Select color" ), true );
698  if ( !newColor.isValid() )
699  {
700  return false;
701  }
702 
703  return model->setData( index, newColor, Qt::EditRole );
704  }
705 
706  return false;
707 }
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.
QString context() const
Get the current color scheme context for the model.
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)
int length() const
Abstract base class for color schemes.
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
int count(const T &value) const
virtual bool isEditable() const
Returns whether the color scheme is editable.
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)
bool isDirty() const
Returns whether the color scheme model has been modified.
Qt::MouseButton button() const
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
bool isDirty() const
Returns whether the color scheme list has been modified.
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 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 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
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
QgsNamedColorList colors() const
Returns a list of colors shown in the widget.
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.
QColor baseColor() const
Get the base color for the color scheme used by the model.
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