25 #include <QHeaderView>
26 #include <QVBoxLayout>
28 #define YUILogComponent "mga-qt-ui"
29 #include <yui/YUILog.h>
31 #include <yui/qt/utf8.h>
33 #include <yui/qt/YQUI.h>
34 #include <yui/YEvent.h>
35 #include <yui/qt/YQSignalBlocker.h>
36 #include <yui/YUIException.h>
38 #include "YMGA_QCBTable.h"
39 #include <yui/qt/YQApplication.h>
52 : QFrame( (QWidget *) parent->widgetRep() )
53 , YMGA_CBTable( parent, tableHeader, tableMode ), _qt_listView(0), d(new
Private)
57 setWidgetRep (
this );
58 QVBoxLayout* layout =
new QVBoxLayout (
this );
59 layout->setSpacing ( 0 );
62 layout->setMargin ( YQWidgetMargin );
64 _qt_listView =
new QY2ListView (
this );
65 YUI_CHECK_NEW ( _qt_listView );
66 layout->addWidget ( _qt_listView );
67 _qt_listView->setAllColumnsShowFocus (
true );
68 _qt_listView->header()->setStretchLastSection (
false );
74 yuiMilestone() <<
" Slection mode " << tableMode << std::endl;
76 if ( tableMode == YCBTableCheckBoxOnFirstColumn )
81 _qt_listView->setContextMenuPolicy ( Qt::CustomContextMenu );
88 _qt_listView->setColumnCount ( columns() );
91 for (
int i=0; i < columns(); i++ )
93 headers << fromUTF8 ( header ( i ) );
96 _qt_listView->setHeaderLabels ( headers );
97 _qt_listView->header()->setSectionResizeMode ( QHeaderView::Interactive );
98 _qt_listView->sortItems ( 0, Qt::AscendingOrder );
104 connect ( _qt_listView, SIGNAL ( itemDoubleClicked ( QTreeWidgetItem *,
int ) ),
107 connect ( _qt_listView, SIGNAL ( itemClicked ( QTreeWidgetItem *,
int ) ),
108 this, SLOT ( slotcolumnClicked ( QTreeWidgetItem *,
int ) ) );
110 connect ( _qt_listView, SIGNAL ( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
113 connect ( _qt_listView, SIGNAL ( customContextMenuRequested (
const QPoint & ) ),
136 YMGA_CBTable::setKeepSorting( keepSorting );
137 _qt_listView->setSortByInsertionSequence( keepSorting );
138 _qt_listView->setSortingEnabled( ! keepSorting );
154 YCBTableItem * item =
dynamic_cast<YCBTableItem *
> ( yitem );
155 YUI_CHECK_PTR ( item );
157 YMGA_CBTable::addItem ( item );
160 YUI_CHECK_NEW ( clone );
162 if ( ! batchMode && item->selected() )
166 YQSignalBlocker sigBlocker ( _qt_listView );
175 for (
int col=0; col < columns(); col++ )
177 switch ( alignment ( col ) )
180 clone->setTextAlignment ( col, Qt::AlignLeft | Qt::AlignVCenter );
183 clone->setTextAlignment ( col, Qt::AlignCenter | Qt::AlignVCenter );
186 clone->setTextAlignment ( col, Qt::AlignRight | Qt::AlignVCenter );
189 case YAlignUnchanged:
195 _qt_listView->sortItems ( 0, Qt::AscendingOrder );
197 if ( resizeColumnsToContent )
199 for (
int i=0; i < columns(); i++ )
200 _qt_listView->resizeColumnToContents ( i );
209 YQSignalBlocker sigBlocker ( _qt_listView );
211 for ( YItemConstIterator it = itemCollection.begin();
212 it != itemCollection.end();
223 YItem * sel = YSelectionWidget::selectedItem();
228 for (
int i=0; i < columns(); i++ )
229 _qt_listView->resizeColumnToContents ( i );
235 YQSignalBlocker sigBlocker ( _qt_listView );
237 YCBTableItem * item =
dynamic_cast<YCBTableItem *
> ( yitem );
238 YUI_CHECK_PTR ( item );
241 YUI_CHECK_PTR ( clone );
243 if ( ! selected && clone == _qt_listView->currentItem() )
249 if ( ! hasMultiSelection() )
250 _qt_listView->setCurrentItem ( clone );
252 clone->setSelected (
true );
253 YMGA_CBTable::selectItem ( item, selected );
259 YQSignalBlocker sigBlocker ( _qt_listView );
261 YCBTableItem * item =
dynamic_cast<YCBTableItem *
> ( yitem );
262 YUI_CHECK_PTR ( item );
265 YUI_CHECK_PTR ( clone );
267 item->check(checked);
268 clone->setCheckState (
checkboxItemColumn(), checked ? Qt::CheckState::Checked : Qt::CheckState::Unchecked );
275 YQSignalBlocker sigBlocker( _qt_listView );
277 YMGA_CBTable::deselectAllItems();
278 _qt_listView->clearSelection();
285 _qt_listView->clear();
286 YMGA_CBTable::deleteAllItems();
293 YCBTableItem * item =
dynamic_cast<YCBTableItem*
>(cell->parent());
294 YUI_CHECK_PTR( item );
297 YUI_CHECK_PTR( clone );
308 YUI_CHECK_PTR ( tableListViewItem );
310 YMGA_CBTable::selectItem ( tableListViewItem->
origItem(), true );
311 if ( ! hasMultiSelection() )
312 _qt_listView->setCurrentItem( listViewItem );
325 if ( hasItems() && YSelectionWidget::hasSelectedItem() )
329 if ( immediateMode() )
331 if ( ! YQUI::ui()->eventPendingFor (
this ) )
335 yuiDebug() <<
"Sending SelectionChanged event" << std::endl;
336 YQUI::ui()->sendEvent (
new YWidgetEvent (
this, YEvent::SelectionChanged ) );
346 yuiDebug() <<
"Sending Activated event" << std::endl;
347 YQUI::ui()->sendEvent(
new YWidgetEvent(
this, YEvent::Activated ) );
353 YMGA_QCBTable::slotcolumnClicked(QTreeWidgetItem* item,
361 Qt::CheckState checked = item->checkState ( col );
362 YCBTableItem *pYCBTableItem = it->
origItem();
364 yuiDebug() <<
"Column is checked: " << (checked == Qt::CheckState::Checked?
"yes":
"no" ) << std::endl;
367 pYCBTableItem->check ( checked == Qt::CheckState::Checked );
371 YMGA_CBTable::setChangedItem ( pYCBTableItem );
372 YQUI::ui()->sendEvent (
new YWidgetEvent (
this, YEvent::ValueChanged ) );
381 _qt_listView->setEnabled( enabled );
383 YWidget::setEnabled( enabled );
411 resize( newWidth, newHeight );
418 _qt_listView->setFocus();
427 if ( ! _qt_listView || ! _qt_listView->viewport() )
430 YQUI::yqApp()->setContextMenuPos( _qt_listView->viewport()->mapToGlobal( pos ) );
431 if ( notifyContextMenu() )
432 YQUI::ui()->sendEvent(
new YWidgetEvent(
this, YEvent::ContextMenuActivated ) );
437 QY2ListView * parent,
438 YCBTableItem * origItem )
439 : QY2ListViewItem( parent )
441 , _origItem( origItem )
443 YUI_CHECK_PTR( _table );
444 YUI_CHECK_PTR( _origItem );
446 _origItem->setData(
this );
450 int table_columns = _table->columns()-2;
451 setCheckState(table->
checkboxItemColumn(), _origItem->checked() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
453 for ( YTableCellIterator it = _origItem->cellsBegin();
454 it != _origItem->cellsEnd();
457 YTableCell * cell = *it;
459 if (cell->column() > table_columns)
461 yuiWarning() <<
"Item contains too many columns, current is " << cell->column()
462 <<
" but only " << _table->columns() <<
" columns are configured" << std::endl;
476 int column = cell->column();
477 YCBTableMode mode =
table()->tableMode();
478 if (mode == YCBTableMode::YCBTableCheckBoxOnFirstColumn)
485 setText( column, fromUTF8( cell->label() ) );
490 if ( cell->hasIconName() )
494 string iconName = _table->iconFullPath( cell->iconName() );
495 QPixmap icon = QPixmap( iconName.c_str() );
498 yuiWarning() <<
"Can't load icon " << iconName << std::endl;
500 setData( column, Qt::DecorationRole, icon );
504 if ( ! data( column, Qt::DecorationRole ).isNull() )
506 setData( column, Qt::DecorationRole, QPixmap() );
512 #include "YMGA_QCBTable.moc"
YMGA_QCBTable * table() const
Return the parent table widget.
unsigned int firstColumnOffset
< offset to first YCell usually 1 if checkbox Enabled and mode is YCBTableCheckBoxOnFirstColumn 0 oth...
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
void slotContextMenu(const QPoint &pos)
Propagate a context menu selection.
virtual void addItem(YItem *item)
Add an item.
void slotSelected(QTreeWidgetItem *)
Notification that an item is selected (single click or keyboard).
YCBTableItem * origItem() const
Return the corresponding YCBTableItem.
virtual void deselectAllItems()
Deselect all items.
virtual ~YMGA_QCBTable()
Destructor.
virtual int preferredWidth()
Preferred width of the widget.
virtual void cellChanged(const YTableCell *cell)
Notification that a cell (its text and/or its icon) was changed from the outside. ...
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
virtual void setKeepSorting(bool keepSorting)
Switch between sorting by item insertion order (keepSorting: true) or allowing the user to sort by an...
virtual int preferredHeight()
Preferred height of the widget.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
int checkboxItemColumn()
returns which column is managed by checkboxes, if any -1 otherwise
void checkItem(YItem *item, bool checked=true)
check/uncheck Item from application.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
void updateCell(const YTableCell *cell)
Update this item's display with the content of 'cell'.
YMGA_QCBTable(YWidget *parent, YTableHeader *header, YCBTableMode checkboxMode)
Constructor.
void slotActivated(QTreeWidgetItem *listViewItem, int column)
Notification that an item is activated (double click or keyboard).
void selectOrigItem(QTreeWidgetItem *listViewItem)
Select the original item (the YCBTableItem) that corresponds to the specified listViewItem.
YMGA_QCBTableListViewItem(YMGA_QCBTable *table, QY2ListView *parent, YCBTableItem *origItem)
Constructor.
virtual void deleteAllItems()
Delete all items.
Visual representation of a YCBTableItem.