00001 /****************************************************************************************************** 00002 * (C) 2016 markummitchell@github.com. This file is part of Engauge Digitizer, which is released * 00003 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file * 00004 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. * 00005 ******************************************************************************************************/ 00006 00007 #include <qdebug.h> 00008 #include <QHeaderView> 00009 #include <QMouseEvent> 00010 #include <QStandardItemModel> 00011 #include "WindowModelBase.h" 00012 #include "WindowTable.h" 00013 00014 // Modes: 00015 // -ContiguousSelection is an ok selection mode when dragging is disabled since user can click and drag 00016 // to easily define a rectangular selection. However, dragging changes that sequence into the start of a drag and drop. 00017 // -ExtendedSelection is best selection mode when dragging is disabled since it acts as ContiguousSelection and also 00018 // allows control-click to select/unselect individual cells 00019 // -MultiSelection is frustrating since user cannot easily remove existing selection by clicking on an unselected cell, 00020 // which results in tedious deselections 00021 const QAbstractItemView::SelectionMode SELECTION_MODE = QAbstractItemView::ExtendedSelection; 00022 00023 WindowTable::WindowTable(WindowModelBase &model) 00024 { 00025 horizontalHeader()->setStretchLastSection (true); 00026 setModel (&model); 00027 setSelectionMode (SELECTION_MODE); 00028 // setDragEnabled (true); This is set later from MainWindowModel 00029 setDragDropMode (QAbstractItemView::DragOnly); 00030 horizontalHeader()->hide(); 00031 verticalHeader()->hide(); 00032 setEditTriggers (QAbstractItemView::NoEditTriggers); // Control is read only 00033 00034 // No WhatsThis text is needed since this table is within a dockable widget that has the same WhatsThis text for 00035 // a click anywhere in that widget 00036 00037 // Connect model to view so model can access the current selection 00038 model.setView (*this); 00039 } 00040 00041 WindowTable::~WindowTable() 00042 { 00043 } 00044 00045 void WindowTable::focusInEvent (QFocusEvent *event) 00046 { 00047 QTableView::focusInEvent (event); 00048 00049 emit signalTableStatusChange (); 00050 } 00051 00052 void WindowTable::focusOutEvent (QFocusEvent *event) 00053 { 00054 QTableView::focusOutEvent (event); 00055 00056 emit signalTableStatusChange (); 00057 } 00058 00059 void WindowTable::selectionChanged(const QItemSelection &selected, 00060 const QItemSelection &deselected) 00061 { 00062 QTableView::selectionChanged (selected, 00063 deselected); 00064 00065 emit signalTableStatusChange (); 00066 }