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"
43 YQTable::YQTable( YWidget * parent, YTableHeader * tableHeader,
bool multiSelectionMode )
44 : QFrame( (QWidget *) parent->widgetRep() )
45 , YTable( parent, tableHeader, multiSelectionMode )
48 QVBoxLayout* layout =
new QVBoxLayout(
this );
49 layout->setSpacing( 0 );
52 layout->setMargin( YQWidgetMargin );
55 YUI_CHECK_NEW( _qt_listView );
56 layout->addWidget( _qt_listView );
57 _qt_listView->setAllColumnsShowFocus(
true );
58 _qt_listView->header()->setStretchLastSection(
false );
62 if ( multiSelectionMode )
63 _qt_listView->setSelectionMode( QAbstractItemView::ExtendedSelection );
65 _qt_listView->setContextMenuPolicy( Qt::CustomContextMenu );
72 _qt_listView->setColumnCount( columns() );
74 for (
int i=0; i < columns(); i++ )
76 headers << fromUTF8( header(i) );
79 _qt_listView->setHeaderLabels( headers );
80 _qt_listView->header()->setSectionResizeMode( QHeaderView::Interactive );
81 _qt_listView->sortItems( 0, Qt::AscendingOrder);
88 connect( _qt_listView, &pclass(_qt_listView)::itemDoubleClicked,
91 connect( _qt_listView, &pclass(_qt_listView)::customContextMenuRequested,
94 if ( multiSelectionMode )
97 connect( _qt_listView, &pclass(_qt_listView)::itemSelectionChanged,
102 connect( _qt_listView, &pclass(_qt_listView)::currentItemChanged,
117 YTable::setKeepSorting( keepSorting );
119 _qt_listView->setSortingEnabled( ! keepSorting );
135 YTableItem * item =
dynamic_cast<YTableItem *
> (yitem);
136 YUI_CHECK_PTR( item );
138 YTable::addItem( item );
141 YUI_CHECK_NEW( clone );
143 if ( ! batchMode && item->selected() )
156 for (
int col=0; col < columns(); col++ )
158 switch ( alignment( col ) )
160 case YAlignBegin: clone->setTextAlignment( col, Qt::AlignLeft | Qt::AlignVCenter );
break;
161 case YAlignCenter: clone->setTextAlignment( col, Qt::AlignCenter | Qt::AlignVCenter );
break;
162 case YAlignEnd: clone->setTextAlignment( col, Qt::AlignRight | Qt::AlignVCenter );
break;
164 case YAlignUnchanged:
break;
169 _qt_listView->sortItems( 0, Qt::AscendingOrder);
171 if ( resizeColumnsToContent )
173 for (
int i=0; i < columns(); i++ )
174 _qt_listView->resizeColumnToContents( i );
185 for ( YItemConstIterator it = itemCollection.begin();
186 it != itemCollection.end();
197 YItem * sel = YSelectionWidget::selectedItem();
202 for (
int i=0; i < columns(); i++ )
203 _qt_listView->resizeColumnToContents( i );
212 YTableItem * item =
dynamic_cast<YTableItem *
> (yitem);
213 YUI_CHECK_PTR( item );
216 YUI_CHECK_PTR( clone );
219 if ( ! selected && clone == _qt_listView->currentItem() )
225 if ( ! hasMultiSelection() )
226 _qt_listView->setCurrentItem( clone );
228 clone->setSelected(
true );
229 YTable::selectItem( item, selected );
239 YTable::deselectAllItems();
240 _qt_listView->clearSelection();
247 _qt_listView->
clear();
248 YTable::deleteAllItems();
255 YTableItem * item = cell->parent();
256 YUI_CHECK_PTR( item );
259 YUI_CHECK_PTR( clone );
271 YUI_CHECK_PTR( tableListViewItem );
273 YTable::selectItem( tableListViewItem->
origItem(),
true );
287 if ( hasItems() && YSelectionWidget::hasSelectedItem() )
291 if ( immediateMode() )
293 if ( !
YQUI::ui()->eventPendingFor(
this ) )
297 yuiDebug() <<
"Sending SelectionChanged event" << std::endl;
307 YSelectionWidget::deselectAllItems();
308 yuiDebug() << std::endl;
310 QList<QTreeWidgetItem *> selItems = _qt_listView->selectedItems();
312 for ( QList<QTreeWidgetItem *>::iterator it = selItems.begin();
313 it != selItems.end();
318 if ( tableListViewItem )
320 tableListViewItem->
origItem()->setSelected(
true );
322 yuiDebug() <<
"Selected item: " << tableListViewItem->
origItem()->label() << std::endl;
326 if ( immediateMode() )
328 if ( !
YQUI::ui()->eventPendingFor(
this ) )
332 yuiDebug() <<
"Sending SelectionChanged event" << std::endl;
346 yuiDebug() <<
"Sending Activated event" << std::endl;
355 _qt_listView->setEnabled( enabled );
357 YWidget::setEnabled( enabled );
385 resize( newWidth, newHeight );
392 _qt_listView->setFocus();
401 if ( ! _qt_listView || ! _qt_listView->viewport() )
405 if ( notifyContextMenu() )
415 YTableItem * origItem )
418 , _origItem( origItem )
420 YUI_CHECK_PTR( _table );
421 YUI_CHECK_PTR( _origItem );
423 _origItem->setData(
this );
425 for ( YTableCellIterator it = _origItem->cellsBegin();
426 it != _origItem->cellsEnd();
440 int column = cell->column();
446 setText( column, fromUTF8( cell->label() ) );
453 if ( cell->hasIconName() )
457 string iconName = _table->iconFullPath( cell->iconName() );
458 QPixmap icon = QPixmap( iconName.c_str() );
461 yuiWarning() <<
"Can't load icon " << iconName << std::endl;
463 setData( column, Qt::DecorationRole, icon );
467 if ( ! data( column, Qt::DecorationRole ).isNull() )
469 setData( column, Qt::DecorationRole, QPixmap() );
475 #include "YQTable.moc"