/***************************************************************************
    qgsmaskingwidget.h
    ---------------------
    begin                : September 2019
    copyright            : (C) 2019 by Hugo Mercier
    email                : hugo dot mercier at oslandia dot com
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef QGSMASKINGWIDGET_H
#define QGSMASKINGWIDGET_H

// We don't want to expose this in the public API

/// @cond PRIVATE

#include "ui_qgsmaskingwidgetbase.h"

#include "qgis_gui.h"
#include "qgis_sip.h"
#include "qgspanelwidget.h"
#include "qgsstyleentityvisitor.h"

#include <QPointer>

#define SIP_NO_FILE

class QgsMessageBarItem;

/**
 * \ingroup gui
 * \brief Main widget for the configuration of mask sources and targets.
 *
 * \note This class is not a part of public API
 * \since QGIS 3.14
 */
class GUI_EXPORT QgsMaskingWidget : public QgsPanelWidget, private Ui::QgsMaskingWidgetBase
{
    Q_OBJECT
  public:
    //! constructor
    QgsMaskingWidget( QWidget *parent = nullptr );

    //! Sets the layer to configure
    void setLayer( QgsVectorLayer *layer );

    //! Applies the changes
    void apply();

  private slots:

    /**
     * Called whenever mask sources or targets selection has changed
     */
    void onSelectionChanged();

  private:
    QPointer< QgsVectorLayer > mLayer;
    //! Populate the mask source and target widgets
    void populate();

    QPointer<QgsMessageBarItem> mMessageBarItem;

    friend class TestQgsMaskingWidget;
};


/**
 * \ingroup gui
 * \brief Generic visitor that collects symbol layers of a vector layer's renderer and call a callback function on them with their corresponding QgsSymbolLayerId.
 *
 * \note This class is not a part of public API
 * \since QGIS 3.14
 */
class SymbolLayerVisitor : public QgsStyleEntityVisitorInterface
{
  public:
    typedef std::function<void( const QgsSymbolLayer * )> SymbolLayerCallback;

    //! constructor
    SymbolLayerVisitor( SymbolLayerCallback callback );

    bool visitEnter( const QgsStyleEntityVisitorInterface::Node &node ) override;

    //! Process a symbol
    void visitSymbol( const QgsSymbol *symbol, const QString &leafIdentifier );

    bool visit( const QgsStyleEntityVisitorInterface::StyleLeaf &leaf ) override;

  private:
    SymbolLayerCallback mCallback;
};

/// @endcond private

#endif
