25 #include <QHeaderView> 26 #include <QVBoxLayout> 28 #define YUILogComponent "qt-ui" 29 #include <yui/YUILog.h> 33 #include <yui/YEvent.h> 34 #include "YQSignalBlocker.h" 35 #include <yui/YUIException.h> 37 #include "QY2ListView.h" 39 #include "YQApplication.h" 44 YTableHeader * tableHeader,
45 bool multiSelectionMode )
46 : QFrame( (QWidget *) parent->widgetRep() )
47 , YTable( parent, tableHeader, multiSelectionMode )
50 QVBoxLayout* layout =
new QVBoxLayout(
this );
51 layout->setSpacing( 0 );
54 layout->setMargin( YQWidgetMargin );
57 YUI_CHECK_NEW( _qt_listView );
58 layout->addWidget( _qt_listView );
59 _qt_listView->setAllColumnsShowFocus(
true );
60 _qt_listView->header()->setStretchLastSection(
false );
64 if ( multiSelectionMode )
65 _qt_listView->setSelectionMode( QAbstractItemView::ExtendedSelection );
67 _qt_listView->setContextMenuPolicy( Qt::CustomContextMenu );
74 _qt_listView->setColumnCount( columns() );
76 for (
int i=0; i < columns(); i++ )
78 headers << fromUTF8( header(i) );
81 _qt_listView->setHeaderLabels( headers );
82 _qt_listView->header()->setSectionResizeMode( QHeaderView::Interactive );
83 _qt_listView->sortItems( 0, Qt::AscendingOrder);
90 connect( _qt_listView, &pclass(_qt_listView)::itemDoubleClicked,
93 connect( _qt_listView, &pclass(_qt_listView)::customContextMenuRequested,
96 if ( multiSelectionMode )
99 connect( _qt_listView, &pclass(_qt_listView)::itemSelectionChanged,
104 connect( _qt_listView, &pclass(_qt_listView)::currentItemChanged,
119 YTable::setKeepSorting( keepSorting );
121 _qt_listView->setSortingEnabled( ! keepSorting );
137 YTableItem * item =
dynamic_cast<YTableItem *
> (yitem);
138 YUI_CHECK_PTR( item );
140 YTable::addItem( item );
143 YUI_CHECK_NEW( clone );
145 if ( ! batchMode && item->selected() )
158 for (
int col=0; col < columns(); col++ )
160 switch ( alignment( col ) )
162 case YAlignBegin: clone->setTextAlignment( col, Qt::AlignLeft | Qt::AlignVCenter );
break;
163 case YAlignCenter: clone->setTextAlignment( col, Qt::AlignCenter | Qt::AlignVCenter );
break;
164 case YAlignEnd: clone->setTextAlignment( col, Qt::AlignRight | Qt::AlignVCenter );
break;
166 case YAlignUnchanged:
break;
171 _qt_listView->sortItems( 0, Qt::AscendingOrder);
173 if ( resizeColumnsToContent )
175 for (
int i=0; i < columns(); i++ )
176 _qt_listView->resizeColumnToContents( i );
187 for ( YItemConstIterator it = itemCollection.begin();
188 it != itemCollection.end();
199 YItem * sel = YSelectionWidget::selectedItem();
204 for (
int i=0; i < columns(); i++ )
205 _qt_listView->resizeColumnToContents( i );
214 YTableItem * item =
dynamic_cast<YTableItem *
> (yitem);
215 YUI_CHECK_PTR( item );
218 YUI_CHECK_PTR( clone );
221 if ( ! selected && clone == _qt_listView->currentItem() )
227 if ( ! hasMultiSelection() )
228 _qt_listView->setCurrentItem( clone );
230 clone->setSelected(
true );
231 YTable::selectItem( item, selected );
241 YTable::deselectAllItems();
242 _qt_listView->clearSelection();
249 _qt_listView->
clear();
250 YTable::deleteAllItems();
257 YTableItem * item = cell->parent();
258 YUI_CHECK_PTR( item );
261 YUI_CHECK_PTR( clone );
273 YUI_CHECK_PTR( tableListViewItem );
275 YTable::selectItem( tableListViewItem->
origItem(), true );
289 if ( hasItems() && YSelectionWidget::hasSelectedItem() )
293 if ( immediateMode() )
295 if ( !
YQUI::ui()->eventPendingFor(
this ) )
299 yuiDebug() <<
"Sending SelectionChanged event" << endl;
309 YSelectionWidget::deselectAllItems();
312 QList<QTreeWidgetItem *> selItems = _qt_listView->selectedItems();
314 for ( QList<QTreeWidgetItem *>::iterator it = selItems.begin();
315 it != selItems.end();
320 if ( tableListViewItem )
322 tableListViewItem->
origItem()->setSelected(
true );
324 yuiDebug() <<
"Selected item: " << tableListViewItem->
origItem()->label() << endl;
328 if ( immediateMode() )
330 if ( !
YQUI::ui()->eventPendingFor(
this ) )
334 yuiDebug() <<
"Sending SelectionChanged event" << endl;
348 yuiDebug() <<
"Sending Activated event" << endl;
357 _qt_listView->setEnabled( enabled );
359 YWidget::setEnabled( enabled );
387 resize( newWidth, newHeight );
394 _qt_listView->setFocus();
403 if ( ! _qt_listView || ! _qt_listView->viewport() )
407 if ( notifyContextMenu() )
417 YTableItem * origItem )
420 , _origItem( origItem )
422 YUI_CHECK_PTR( _table );
423 YUI_CHECK_PTR( _origItem );
425 _origItem->setData(
this );
427 for ( YTableCellIterator it = _origItem->cellsBegin();
428 it != _origItem->cellsEnd();
442 int column = cell->column();
448 setText( column, fromUTF8( cell->label() ) );
455 if ( cell->hasIconName() )
460 if ( ! icon.isNull() )
461 setData( column, Qt::DecorationRole, icon );
465 if ( ! data( column, Qt::DecorationRole ).isNull() )
467 setData( column, Qt::DecorationRole, QIcon() );
476 const YTableCell* tableCell =
origItem()->cell(column);
478 if (tableCell->hasSortKey())
479 return QString::fromUtf8(tableCell->sortKey().c_str());
481 return text(column).trimmed();
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
virtual void setSortByInsertionSequence(bool sortByInsertionSequence)
Enforce sorting by item insertion order (true) or let user change sorting by clicking on a column hea...
virtual void addItem(YItem *item)
Add an item.
static YQApplication * yqApp()
Return the global YApplication object as YQApplication.
void slotContextMenu(const QPoint &pos)
Propagate a context menu selection.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
YQTableListViewItem(YQTable *table, QY2ListView *parent, YTableItem *origItem)
Constructor.
void slotSelected(QTreeWidgetItem *)
Notification that an item is selected (single click or keyboard).
virtual void setKeepSorting(bool keepSorting)
Switch between sorting by item insertion order (keepSorting: true) or allowing the user to sort by an...
virtual void clear()
Reimplemented from Q3ListView: Adjust header sizes after clearing contents.
virtual void deleteAllItems()
Delete all items.
void selectOrigItem(QTreeWidgetItem *listViewItem)
Select the original item (the YTableItem) that corresponds to the specified listViewItem.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Visual representation of a YTableItem.
QIcon loadIcon(const string &iconName) const
Load an icon.
YTableItem * origItem() const
Return the corresponding YTableItem.
virtual void deselectAllItems()
Deselect all items.
virtual void setContextMenuPos(QPoint contextMenuPos)
Sets the position of the context menu (in gloabl coordinates)
virtual void cellChanged(const YTableCell *cell)
Notification that a cell (its text and/or its icon) was changed from the outside. ...
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
YQTable(YWidget *parent, YTableHeader *header, bool multiSelection)
Constructor.
virtual ~YQTable()
Destructor.
void updateCell(const YTableCell *cell)
Update this item's display with the content of 'cell'.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
void slotActivated(QTreeWidgetItem *)
Notification that an item is activated (double click or keyboard).
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
virtual int preferredWidth()
Preferred width of the widget.
Enhanced QTreeWidgetItem.
virtual QString smartSortKey(int column) const override
The text of the table cell or the sort-key if available.
virtual int preferredHeight()
Preferred height of the widget.
void slotSelectionChanged()
Notification that the item selection changed (relevant for multiSelection mode).
static YQUI * ui()
Access the global Qt-UI.