/*==============================================================================

  Program: 3D Slicer

  Copyright (c) Seattle Children's Hospital d/b/a Seattle Children's Research Institute.

  See COPYRIGHT.txt
  or http://www.slicer.org/copyright/copyright.txt for details.

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

  This file was originally developed by Csaba Pinter, EBATINCA, S.L.
  and was funded by by Murat Maga (Seattle Children's Research Institute).

==============================================================================*/

#ifndef __qSlicerTerminologyEditorDialog_h
#define __qSlicerTerminologyEditorDialog_h

// Qt includes
#include <QObject>

// Colors includes
#include "qSlicerColorsModuleWidgetsExport.h"

// Terminologies includes
#include "qSlicerTerminologyNavigatorWidget.h"

class qSlicerTerminologyEditorDialogPrivate;
class vtkSlicerTerminologyEntry;

/// \brief Qt dialog for selecting a terminology entry
class Q_SLICER_MODULE_COLORS_WIDGETS_EXPORT qSlicerTerminologyEditorDialog : public QObject
{
public:
  Q_OBJECT

public:
  typedef QObject Superclass;
  qSlicerTerminologyEditorDialog(QObject* parent = nullptr);
#ifndef __VTK_WRAP__
  qSlicerTerminologyEditorDialog(qSlicerTerminologyNavigatorWidget::TerminologyInfoBundle& initialTerminologyInfo, QObject* parent = nullptr);
#endif
  ~qSlicerTerminologyEditorDialog() override;

public:
#ifndef __VTK_WRAP__
  /// Convenience function to start dialog, initialized with a terminology entry
  /// \param terminologyInfo Terminology shown and edited by the dialog. The edited terminology will be stored in this variable as well.
  ///   terminologyInfo.ColorAutoGenerated and terminologyInfo.NameAutoGenerated set to false means that these are set (from terminology)
  ///   and so their value is valid and should be used by the caller.
  /// \return Success flag
  static bool getTerminology(qSlicerTerminologyNavigatorWidget::TerminologyInfoBundle& terminologyInfo, QObject* parent);

  /// Get selected terminology and other metadata (name, color, auto-generated flags) into given info bundle object
  void terminologyInfo(qSlicerTerminologyNavigatorWidget::TerminologyInfoBundle& terminologyInfo);
#endif

  /// Convenience function to start dialog, initialized with a terminology entry.
  /// Does not show name and color overrides.
  /// \param terminology Initial terminology shown by the dialog. The selected terminology is set to this as well.
  /// \return Success flag
  static bool getTerminology(vtkSlicerTerminologyEntry* terminologyEntry, QObject* parent);

  /// Show dialog
  /// \param nodeToSelect Node is selected in the tree if given
  /// \return Success flag (if dialog result is not Accepted then false)
  virtual bool exec();

  /// Python compatibility function for showing dialog (calls \a exec)
  Q_INVOKABLE bool execDialog() { return this->exec(); };

protected slots:
  void setSaveButtonEnabled(bool);

protected:
  QScopedPointer<qSlicerTerminologyEditorDialogPrivate> d_ptr;

private:
  Q_DECLARE_PRIVATE(qSlicerTerminologyEditorDialog);
  Q_DISABLE_COPY(qSlicerTerminologyEditorDialog);
};

#endif
