itom 2.0.0
D:/git-itom/sources/itom/Qitom/ui/dialogPluginPicker.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2013, Institut für Technische Optik (ITO),
00005     Universität Stuttgart, Germany
00006 
00007     This file is part of itom.
00008   
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013 
00014     itom is distributed in the hope that it will be useful, but
00015     WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00017     General Public Licence for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with itom. If not, see <http://www.gnu.org/licenses/>.
00021 *********************************************************************** */
00022 
00023 #ifndef DIALOGPLUGINPICKER_H
00024 #define DIALOGPLUGINPICKER_H
00025 
00026 #include "../../common/addInInterface.h"
00027 #include "../../common/sharedStructures.h"
00028 
00029 #include <QtGui>
00030 #include <qdialog.h>
00031 #include <qvector.h>
00032 
00033 #include "../organizer/addInManager.h"
00034 #include <qsortfilterproxymodel.h>
00035 
00036 #include "ui_dialogPluginPicker.h"
00037 
00038 namespace ito {
00039 
00040 class PickerSortFilterProxyModel : public QSortFilterProxyModel
00041 {
00042 public:
00043     PickerSortFilterProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent), m_minimumMask(0x0), m_pluginName(QString::Null()), m_showPluginsWithoutInstance(false) {};
00044     ~PickerSortFilterProxyModel() {};
00045 
00046     inline void setPluginMinimumMask( const int minimumMask ) 
00047     { 
00048         m_minimumMask = minimumMask; 
00049         invalidateFilter(); 
00050     };
00051 
00052     inline void setPluginName( QString &name )
00053     {
00054         m_pluginName = name;
00055         invalidateFilter();
00056     }
00057 
00058     inline void showPluginsWithoutInstance(bool show) 
00059     { 
00060         m_showPluginsWithoutInstance = show; 
00061         invalidateFilter(); 
00062     };
00063 
00064 protected:
00065     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
00066     {
00067         QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
00068         int type = sourceModel()->data(idx, Qt::UserRole + 1).toInt();
00069         int itemType = sourceModel()->data(idx, Qt::UserRole + 3).toInt();
00070 
00071 
00072         if(!m_showPluginsWithoutInstance)
00073         {
00074             int itemType = sourceModel()->data(idx, Qt::UserRole + 3).toInt();
00075             if(itemType == ito::PlugInModel::itemPlugin && sourceModel()->hasChildren(idx) == false) 
00076             {
00077                 return false;
00078             }
00079         }
00080 
00081         if(!m_pluginName.isNull() && itemType == ito::PlugInModel::itemPlugin )
00082         {
00083             if( QString::compare( sourceModel()->data(idx, Qt::DisplayRole).toString(), m_pluginName, Qt::CaseInsensitive ) != 0)
00084             {
00085                 return false;
00086             }
00087         }
00088 
00089         if(type == ito::typeAlgo) 
00090         {
00091             return false; //never allow algorithms or widgets
00092         }
00093 
00094         return (type & m_minimumMask) == m_minimumMask;
00095     }
00096 
00097 private:
00098     int m_minimumMask;
00099     QString m_pluginName; //default QString::Null()
00100     bool m_showPluginsWithoutInstance;
00101 };
00102 
00103 } //end namespace ito
00104 
00105 namespace ito {
00106 
00107 
00108 class DialogPluginPicker : public QDialog 
00109 {
00110     Q_OBJECT
00111 
00112 public:
00113     DialogPluginPicker(bool allowNewInstances, ito::AddInBase *currentItem, int minimumPluginTypeMask = 0x0, QString pluginName = QString::Null(), QWidget *parent = NULL );
00114     ~DialogPluginPicker() {};
00115 
00116     ito::AddInBase* getSelectedInstance();
00117 
00118 protected:
00119 
00120 private:
00121 
00122     Ui::DialogPluginPicker ui;
00123     PickerSortFilterProxyModel *m_pFilterModel;
00124 
00125 private slots:
00126     void itemClicked(const QModelIndex &index);
00127     void itemDblClicked(const QModelIndex &index);
00128     void showPluginsWithoutInstance(bool checked); 
00129     void createNewInstance(bool checked);
00130 
00131 };
00132 
00133 } //end namespace ito
00134 
00135 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends