Loading isis/src/qisis/objs/AbstractProjectItemViewMW/AbstractProjectItemViewMW.cpp 0 → 100644 +326 −0 Original line number Diff line number Diff line /** * @file * $Date$ * $Revision$ * * Unless noted otherwise, the portions of Isis written by the USGS are * public domain. See individual third-party library and package descriptions * for intellectual property information, user agreements, and related * information. * * Although Isis has been used by the USGS, no warranty, expressed or * implied, is made by the USGS as to the accuracy and functioning of such * software and related material nor shall the fact of distribution * constitute any such warranty, and no responsibility is assumed by the * USGS in connection therewith. * * For additional information, launch * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html * in a browser or see the Privacy & Disclaimers page on the Isis website, * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on * http://www.usgs.gov/privacy.html. */ #include "AbstractProjectItemViewMW.h" #include <QAction> #include <QDebug> #include <QDragEnterEvent> #include <QDragMoveEvent> #include <QDropEvent> #include <QList> #include <QMainWindow> #include <QWidget> #include "ProjectItem.h" #include "ProjectItemModel.h" #include "ProjectItemProxyModel.h" namespace Isis { /** * Constructs the AbstractProjectItemViewMW. * * @param[in] parent (QWidget *) The parent widget */ AbstractProjectItemViewMW::AbstractProjectItemViewMW(QWidget *parent) : QMainWindow(parent) { setWindowFlags(Qt::Widget); m_internalModel = new ProjectItemProxyModel(this); setAcceptDrops(true); } /** * Sets the model used by the view. If the internal model is a proxy * model, it sets the source model. * * @param[in] model (ProjectItemModel *) The new model */ void AbstractProjectItemViewMW::setModel(ProjectItemModel *model) { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { proxyModel->setSourceModel(model); } } /** * Returns the model used by the view. If the internal model is a * proxy model, it returns the source model. * * @return @b ProjectItemModel * The model. */ ProjectItemModel *AbstractProjectItemViewMW::model() { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { return proxyModel->sourceModel(); } return internalModel(); } /** * Sets the internal model of the view. * * @param[in] model (ProjectItemModel *) The new internal model */ void AbstractProjectItemViewMW::setInternalModel(ProjectItemModel *model) { m_internalModel = model; } /** * Returns the internal model of the view. By default it is a proxy * model. * * @return @b ProjectItemModel * The internal model */ ProjectItemModel *AbstractProjectItemViewMW::internalModel() { return m_internalModel; } /** * Accepts the drag enter event if the internal model can accept the * mime data. * * @param[in] event (QDragEnterEvent *) The drag event */ void AbstractProjectItemViewMW::dragEnterEvent(QDragEnterEvent *event) { if (internalModel()->canDropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ) ) { event->acceptProposedAction(); } } /** * Accepts the drag event if the internal model can accept the mime * data. * * @param[in] event (QDragMoveEvent *) The drag event */ void AbstractProjectItemViewMW::dragMoveEvent(QDragMoveEvent *event) { if (internalModel()->canDropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ) ) { event->acceptProposedAction(); } } /** * Drops the data into the internal model if it can accept the data. * * @param[in] event (QDropEvent *) The drop event */ void AbstractProjectItemViewMW::dropEvent(QDropEvent *event) { if (internalModel()->canDropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ) ) { internalModel()->dropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ); event->acceptProposedAction(); } } /** * Returns a list of actions appropriate for the permanent tool bar. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::permToolBarActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for the active tool bar. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::activeToolBarActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for the tool pad. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::toolPadActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a context menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::contextMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a file menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::fileMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a project menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::projectMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for an edit menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::editMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a view menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::viewMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a settings menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::settingsMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a help menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::helpMenuActions() { return QList<QAction *>(); } /** * Returns the current item of the model. * * @return @b ProjectItem * The item */ ProjectItem *AbstractProjectItemViewMW::currentItem() { return model()->currentItem(); } /** * Return the selected items of the model. * * @return @b QList<ProjectItem *> The items */ QList<ProjectItem *> AbstractProjectItemViewMW::selectedItems() { return model()->selectedItems(); } /** * Adds an item to the view. The item must be part of the view's * model. This method can be overriden in a subclass to filter out * unneeded items. * * @param[in] item (ProjectItem *) The item to add. */ void AbstractProjectItemViewMW::addItem(ProjectItem *item) { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { proxyModel->addItem(item); } } /** * Adds several items to the view. The items must be a part of the * view's model. * * @param[in] items (QList<ProjectItem *>) The items to add. */ void AbstractProjectItemViewMW::addItems(QList<ProjectItem *> items) { foreach (ProjectItem *item, items) { addItem(item); } } /** * Removes an item to the view. The item must be part of the view's * model. This method can be overriden in a subclass to filter out * unneeded items. * * @param[in] item (ProjectItem *) The item to remove. */ void AbstractProjectItemViewMW::removeItem(ProjectItem *item) { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { proxyModel->removeItem(item); } } /** * Removes several items from the view. The items must be a part of the * view's model. * * @param[in] items (QList<ProjectItem *>) The items to remove. */ void AbstractProjectItemViewMW::removeItems(QList<ProjectItem *> items) { foreach (ProjectItem *item, items) { removeItem(item); } } } isis/src/qisis/objs/AbstractProjectItemViewMW/AbstractProjectItemViewMW.h 0 → 100644 +111 −0 Original line number Diff line number Diff line #ifndef AbstractProjectItemViewMW_h #define AbstractProjectItemViewMW_h /** * @file * $Date$ * $Revision$ * * Unless noted otherwise, the portions of Isis written by the USGS are * public domain. See individual third-party library and package descriptions * for intellectual property information, user agreements, and related * information. * * Although Isis has been used by the USGS, no warranty, expressed or * implied, is made by the USGS as to the accuracy and functioning of such * software and related material nor shall the fact of distribution * constitute any such warranty, and no responsibility is assumed by the * USGS in connection therewith. * * For additional information, launch * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html * in a browser or see the Privacy & Disclaimers page on the Isis website, * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on * http://www.usgs.gov/privacy.html. */ #include <QMainWindow> class QAction; class QDragEnterEvent; class QWidget; template <typename T> class QList; namespace Isis { class ProjectItem; class ProjectItemModel; /** * AbstractProjectItemView is a base class for views of a * ProjectItemModel in Qt's model-view * framework. AbstractProjectItemView is not meant to be * instantiated directly. A view usually only shows items that have * been added to the view. The views contains an internal * ProjectItemProxyModel that represents the items appropriately for * the view. * * An AbstractProjectItemView may provide QActions for manipulating * the view. These actions can be accessed in different contexts * through toolBarActions(), menuActions(), and * contextMenuActions(). * * When mime data is dropped on a view the view adds the selected * items from the source model to the view. * * Note that AbstractProjectItemView does not inherit from QAbstractItemView. * * @author 2015-10-21 Jeffrey Covington * @internal * @history 2015-10-21 Jeffrey Covington - Original version. * @history 2016-06-27 Ian Humphrey - Minor updates to documentation and coding standards. * Fixes #4004. * @history 2016-07-28 Tracie Sucharski - Implemented removeItem and removeItems methods. * @history 2016-08-25 Adam Paquette - Minor updates to documentation. * Fixes #4299. */ class AbstractProjectItemViewMW : public QMainWindow { Q_OBJECT public: AbstractProjectItemViewMW(QWidget *parent=0); virtual void setModel(ProjectItemModel *model); virtual ProjectItemModel *model(); virtual void dragEnterEvent(QDragEnterEvent *event); virtual void dragMoveEvent(QDragMoveEvent *event); virtual void dropEvent(QDropEvent *event); virtual QList<QAction *> permToolBarActions(); virtual QList<QAction *> activeToolBarActions(); virtual QList<QAction *> toolPadActions(); virtual QList<QAction *> contextMenuActions(); virtual QList<QAction *> fileMenuActions(); virtual QList<QAction *> projectMenuActions(); virtual QList<QAction *> editMenuActions(); virtual QList<QAction *> viewMenuActions(); virtual QList<QAction *> settingsMenuActions(); virtual QList<QAction *> helpMenuActions(); virtual ProjectItem *currentItem(); virtual QList<ProjectItem *> selectedItems(); virtual ProjectItemModel *internalModel(); virtual void setInternalModel(ProjectItemModel *model); public slots: virtual void addItem(ProjectItem *item); virtual void addItems(QList<ProjectItem *> items); virtual void removeItem(ProjectItem *item); virtual void removeItems(QList<ProjectItem *> items); private: ProjectItemModel *m_internalModel; //!< The internal model used by the view }; } #endif isis/src/qisis/objs/AbstractProjectItemViewMW/Makefile 0 → 100644 +7 −0 Original line number Diff line number Diff line ifeq ($(ISISROOT), $(BLANK)) .SILENT: error: echo "Please set ISISROOT"; else include $(ISISROOT)/make/isismake.objs endif No newline at end of file Loading
isis/src/qisis/objs/AbstractProjectItemViewMW/AbstractProjectItemViewMW.cpp 0 → 100644 +326 −0 Original line number Diff line number Diff line /** * @file * $Date$ * $Revision$ * * Unless noted otherwise, the portions of Isis written by the USGS are * public domain. See individual third-party library and package descriptions * for intellectual property information, user agreements, and related * information. * * Although Isis has been used by the USGS, no warranty, expressed or * implied, is made by the USGS as to the accuracy and functioning of such * software and related material nor shall the fact of distribution * constitute any such warranty, and no responsibility is assumed by the * USGS in connection therewith. * * For additional information, launch * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html * in a browser or see the Privacy & Disclaimers page on the Isis website, * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on * http://www.usgs.gov/privacy.html. */ #include "AbstractProjectItemViewMW.h" #include <QAction> #include <QDebug> #include <QDragEnterEvent> #include <QDragMoveEvent> #include <QDropEvent> #include <QList> #include <QMainWindow> #include <QWidget> #include "ProjectItem.h" #include "ProjectItemModel.h" #include "ProjectItemProxyModel.h" namespace Isis { /** * Constructs the AbstractProjectItemViewMW. * * @param[in] parent (QWidget *) The parent widget */ AbstractProjectItemViewMW::AbstractProjectItemViewMW(QWidget *parent) : QMainWindow(parent) { setWindowFlags(Qt::Widget); m_internalModel = new ProjectItemProxyModel(this); setAcceptDrops(true); } /** * Sets the model used by the view. If the internal model is a proxy * model, it sets the source model. * * @param[in] model (ProjectItemModel *) The new model */ void AbstractProjectItemViewMW::setModel(ProjectItemModel *model) { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { proxyModel->setSourceModel(model); } } /** * Returns the model used by the view. If the internal model is a * proxy model, it returns the source model. * * @return @b ProjectItemModel * The model. */ ProjectItemModel *AbstractProjectItemViewMW::model() { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { return proxyModel->sourceModel(); } return internalModel(); } /** * Sets the internal model of the view. * * @param[in] model (ProjectItemModel *) The new internal model */ void AbstractProjectItemViewMW::setInternalModel(ProjectItemModel *model) { m_internalModel = model; } /** * Returns the internal model of the view. By default it is a proxy * model. * * @return @b ProjectItemModel * The internal model */ ProjectItemModel *AbstractProjectItemViewMW::internalModel() { return m_internalModel; } /** * Accepts the drag enter event if the internal model can accept the * mime data. * * @param[in] event (QDragEnterEvent *) The drag event */ void AbstractProjectItemViewMW::dragEnterEvent(QDragEnterEvent *event) { if (internalModel()->canDropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ) ) { event->acceptProposedAction(); } } /** * Accepts the drag event if the internal model can accept the mime * data. * * @param[in] event (QDragMoveEvent *) The drag event */ void AbstractProjectItemViewMW::dragMoveEvent(QDragMoveEvent *event) { if (internalModel()->canDropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ) ) { event->acceptProposedAction(); } } /** * Drops the data into the internal model if it can accept the data. * * @param[in] event (QDropEvent *) The drop event */ void AbstractProjectItemViewMW::dropEvent(QDropEvent *event) { if (internalModel()->canDropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ) ) { internalModel()->dropMimeData( event->mimeData(), event->dropAction(), 0, 0, QModelIndex() ); event->acceptProposedAction(); } } /** * Returns a list of actions appropriate for the permanent tool bar. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::permToolBarActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for the active tool bar. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::activeToolBarActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for the tool pad. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::toolPadActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a context menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::contextMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a file menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::fileMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a project menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::projectMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for an edit menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::editMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a view menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::viewMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a settings menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::settingsMenuActions() { return QList<QAction *>(); } /** * Returns a list of actions appropriate for a help menu. * * @return @b QList<QAction *> The actions */ QList<QAction *> AbstractProjectItemViewMW::helpMenuActions() { return QList<QAction *>(); } /** * Returns the current item of the model. * * @return @b ProjectItem * The item */ ProjectItem *AbstractProjectItemViewMW::currentItem() { return model()->currentItem(); } /** * Return the selected items of the model. * * @return @b QList<ProjectItem *> The items */ QList<ProjectItem *> AbstractProjectItemViewMW::selectedItems() { return model()->selectedItems(); } /** * Adds an item to the view. The item must be part of the view's * model. This method can be overriden in a subclass to filter out * unneeded items. * * @param[in] item (ProjectItem *) The item to add. */ void AbstractProjectItemViewMW::addItem(ProjectItem *item) { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { proxyModel->addItem(item); } } /** * Adds several items to the view. The items must be a part of the * view's model. * * @param[in] items (QList<ProjectItem *>) The items to add. */ void AbstractProjectItemViewMW::addItems(QList<ProjectItem *> items) { foreach (ProjectItem *item, items) { addItem(item); } } /** * Removes an item to the view. The item must be part of the view's * model. This method can be overriden in a subclass to filter out * unneeded items. * * @param[in] item (ProjectItem *) The item to remove. */ void AbstractProjectItemViewMW::removeItem(ProjectItem *item) { if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) { proxyModel->removeItem(item); } } /** * Removes several items from the view. The items must be a part of the * view's model. * * @param[in] items (QList<ProjectItem *>) The items to remove. */ void AbstractProjectItemViewMW::removeItems(QList<ProjectItem *> items) { foreach (ProjectItem *item, items) { removeItem(item); } } }
isis/src/qisis/objs/AbstractProjectItemViewMW/AbstractProjectItemViewMW.h 0 → 100644 +111 −0 Original line number Diff line number Diff line #ifndef AbstractProjectItemViewMW_h #define AbstractProjectItemViewMW_h /** * @file * $Date$ * $Revision$ * * Unless noted otherwise, the portions of Isis written by the USGS are * public domain. See individual third-party library and package descriptions * for intellectual property information, user agreements, and related * information. * * Although Isis has been used by the USGS, no warranty, expressed or * implied, is made by the USGS as to the accuracy and functioning of such * software and related material nor shall the fact of distribution * constitute any such warranty, and no responsibility is assumed by the * USGS in connection therewith. * * For additional information, launch * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html * in a browser or see the Privacy & Disclaimers page on the Isis website, * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on * http://www.usgs.gov/privacy.html. */ #include <QMainWindow> class QAction; class QDragEnterEvent; class QWidget; template <typename T> class QList; namespace Isis { class ProjectItem; class ProjectItemModel; /** * AbstractProjectItemView is a base class for views of a * ProjectItemModel in Qt's model-view * framework. AbstractProjectItemView is not meant to be * instantiated directly. A view usually only shows items that have * been added to the view. The views contains an internal * ProjectItemProxyModel that represents the items appropriately for * the view. * * An AbstractProjectItemView may provide QActions for manipulating * the view. These actions can be accessed in different contexts * through toolBarActions(), menuActions(), and * contextMenuActions(). * * When mime data is dropped on a view the view adds the selected * items from the source model to the view. * * Note that AbstractProjectItemView does not inherit from QAbstractItemView. * * @author 2015-10-21 Jeffrey Covington * @internal * @history 2015-10-21 Jeffrey Covington - Original version. * @history 2016-06-27 Ian Humphrey - Minor updates to documentation and coding standards. * Fixes #4004. * @history 2016-07-28 Tracie Sucharski - Implemented removeItem and removeItems methods. * @history 2016-08-25 Adam Paquette - Minor updates to documentation. * Fixes #4299. */ class AbstractProjectItemViewMW : public QMainWindow { Q_OBJECT public: AbstractProjectItemViewMW(QWidget *parent=0); virtual void setModel(ProjectItemModel *model); virtual ProjectItemModel *model(); virtual void dragEnterEvent(QDragEnterEvent *event); virtual void dragMoveEvent(QDragMoveEvent *event); virtual void dropEvent(QDropEvent *event); virtual QList<QAction *> permToolBarActions(); virtual QList<QAction *> activeToolBarActions(); virtual QList<QAction *> toolPadActions(); virtual QList<QAction *> contextMenuActions(); virtual QList<QAction *> fileMenuActions(); virtual QList<QAction *> projectMenuActions(); virtual QList<QAction *> editMenuActions(); virtual QList<QAction *> viewMenuActions(); virtual QList<QAction *> settingsMenuActions(); virtual QList<QAction *> helpMenuActions(); virtual ProjectItem *currentItem(); virtual QList<ProjectItem *> selectedItems(); virtual ProjectItemModel *internalModel(); virtual void setInternalModel(ProjectItemModel *model); public slots: virtual void addItem(ProjectItem *item); virtual void addItems(QList<ProjectItem *> items); virtual void removeItem(ProjectItem *item); virtual void removeItems(QList<ProjectItem *> items); private: ProjectItemModel *m_internalModel; //!< The internal model used by the view }; } #endif
isis/src/qisis/objs/AbstractProjectItemViewMW/Makefile 0 → 100644 +7 −0 Original line number Diff line number Diff line ifeq ($(ISISROOT), $(BLANK)) .SILENT: error: echo "Please set ISISROOT"; else include $(ISISROOT)/make/isismake.objs endif No newline at end of file