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 ( itemChanged ( QTreeWidgetItem *,
int ) ),
111 this, SLOT ( slotcolumnClicked ( QTreeWidgetItem *,
int ) ) );
114 connect ( _qt_listView, SIGNAL ( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
117 connect ( _qt_listView, SIGNAL ( customContextMenuRequested (
const QPoint & ) ),
140 YMGA_CBTable::setKeepSorting( keepSorting );
141 _qt_listView->setSortByInsertionSequence( keepSorting );
142 _qt_listView->setSortingEnabled( ! keepSorting );
158 YCBTableItem * item =
dynamic_cast<YCBTableItem *
> ( yitem );
159 YUI_CHECK_PTR ( item );
161 YMGA_CBTable::addItem ( item );
164 YUI_CHECK_NEW ( clone );
166 if ( ! batchMode && item->selected() )
170 YQSignalBlocker sigBlocker ( _qt_listView );
179 for (
int col=0; col < columns(); col++ )
181 switch ( alignment ( col ) )
184 clone->setTextAlignment ( col, Qt::AlignLeft | Qt::AlignVCenter );
187 clone->setTextAlignment ( col, Qt::AlignCenter | Qt::AlignVCenter );
190 clone->setTextAlignment ( col, Qt::AlignRight | Qt::AlignVCenter );
193 case YAlignUnchanged:
199 _qt_listView->sortItems ( 0, Qt::AscendingOrder );
201 if ( resizeColumnsToContent )
203 for (
int i=0; i < columns(); i++ )
204 _qt_listView->resizeColumnToContents ( i );
213 YQSignalBlocker sigBlocker ( _qt_listView );
215 for ( YItemConstIterator it = itemCollection.begin();
216 it != itemCollection.end();
227 YItem * sel = YSelectionWidget::selectedItem();
232 for (
int i=0; i < columns(); i++ )
233 _qt_listView->resizeColumnToContents ( i );
239 YQSignalBlocker sigBlocker ( _qt_listView );
241 YCBTableItem * item =
dynamic_cast<YCBTableItem *
> ( yitem );
242 YUI_CHECK_PTR ( item );
245 YUI_CHECK_PTR ( clone );
247 if ( ! selected && clone == _qt_listView->currentItem() )
253 if ( ! hasMultiSelection() )
254 _qt_listView->setCurrentItem ( clone );
256 clone->setSelected (
true );
257 YMGA_CBTable::selectItem ( item, selected );
263 YQSignalBlocker sigBlocker ( _qt_listView );
265 YCBTableItem * item =
dynamic_cast<YCBTableItem *
> ( yitem );
266 YUI_CHECK_PTR ( item );
269 YUI_CHECK_PTR ( clone );
271 item->check(checked);
272 clone->setCheckState (
checkboxItemColumn(), checked ? Qt::CheckState::Checked : Qt::CheckState::Unchecked );
279 YQSignalBlocker sigBlocker( _qt_listView );
281 YMGA_CBTable::deselectAllItems();
282 _qt_listView->clearSelection();
289 _qt_listView->clear();
290 YMGA_CBTable::deleteAllItems();
297 YCBTableItem * item =
dynamic_cast<YCBTableItem*
>(cell->parent());
298 YUI_CHECK_PTR( item );
301 YUI_CHECK_PTR( clone );
312 YUI_CHECK_PTR ( tableListViewItem );
314 YMGA_CBTable::selectItem ( tableListViewItem->
origItem(),
true );
315 if ( ! hasMultiSelection() )
316 _qt_listView->setCurrentItem( listViewItem );
329 if ( hasItems() && YSelectionWidget::hasSelectedItem() )
333 if ( immediateMode() )
335 if ( ! YQUI::ui()->eventPendingFor (
this ) )
339 yuiDebug() <<
"Sending SelectionChanged event" << std::endl;
340 YQUI::ui()->sendEvent (
new YWidgetEvent (
this, YEvent::SelectionChanged ) );
350 yuiDebug() <<
"Sending Activated event" << std::endl;
351 YQUI::ui()->sendEvent(
new YWidgetEvent(
this, YEvent::Activated ) );
357 YMGA_QCBTable::slotcolumnClicked(QTreeWidgetItem* item,
365 Qt::CheckState checked = item->checkState ( col );
366 YCBTableItem *pYCBTableItem = it->
origItem();
368 yuiDebug() <<
"Column is checked: " << (checked == Qt::CheckState::Checked?
"yes":
"no" ) << std::endl;
371 pYCBTableItem->check ( checked == Qt::CheckState::Checked );
375 YMGA_CBTable::setChangedItem ( pYCBTableItem );
376 YQUI::ui()->sendEvent (
new YWidgetEvent (
this, YEvent::ValueChanged ) );
385 _qt_listView->setEnabled( enabled );
387 YWidget::setEnabled( enabled );
415 resize( newWidth, newHeight );
422 _qt_listView->setFocus();
431 if ( ! _qt_listView || ! _qt_listView->viewport() )
434 YQUI::yqApp()->setContextMenuPos( _qt_listView->viewport()->mapToGlobal( pos ) );
435 if ( notifyContextMenu() )
436 YQUI::ui()->sendEvent(
new YWidgetEvent(
this, YEvent::ContextMenuActivated ) );
441 QY2ListView * parent,
442 YCBTableItem * origItem )
443 : QY2ListViewItem( parent )
445 , _origItem( origItem )
447 YUI_CHECK_PTR( _table );
448 YUI_CHECK_PTR( _origItem );
450 _origItem->setData(
this );
454 int table_columns = _table->columns()-2;
455 setCheckState(
table->
checkboxItemColumn(), _origItem->checked() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
457 for ( YTableCellIterator it = _origItem->cellsBegin();
458 it != _origItem->cellsEnd();
461 YTableCell * cell = *it;
463 if (cell->column() > table_columns)
465 yuiWarning() <<
"Item contains too many columns, current is " << cell->column()
466 <<
" but only " << _table->columns() <<
" columns are configured" << std::endl;
480 int column = cell->column();
481 YCBTableMode mode =
table()->tableMode();
482 if (mode == YCBTableMode::YCBTableCheckBoxOnFirstColumn)
489 setText( column, fromUTF8( cell->label() ) );
494 if ( cell->hasIconName() )
498 string iconName = _table->iconFullPath( cell->iconName() );
499 QPixmap icon = QPixmap( iconName.c_str() );
502 yuiWarning() <<
"Can't load icon " << iconName << std::endl;
504 setData( column, Qt::DecorationRole, icon );
508 if ( ! data( column, Qt::DecorationRole ).isNull() )
510 setData( column, Qt::DecorationRole, QPixmap() );
516 #include "YMGA_QCBTable.moc"
Visual representation of a YCBTableItem.
void updateCell(const YTableCell *cell)
Update this item's display with the content of 'cell'.
YCBTableItem * origItem() const
Return the corresponding YCBTableItem.
YMGA_QCBTableListViewItem(YMGA_QCBTable *table, QY2ListView *parent, YCBTableItem *origItem)
Constructor.
YMGA_QCBTable * table() const
Return the parent table widget.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void deselectAllItems()
Deselect all items.
void slotContextMenu(const QPoint &pos)
Propagate a context menu selection.
int checkboxItemColumn()
returns which column is managed by checkboxes, if any -1 otherwise
virtual int preferredHeight()
Preferred height of the widget.
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
virtual int preferredWidth()
Preferred width of the widget.
virtual void setKeepSorting(bool keepSorting)
Switch between sorting by item insertion order (keepSorting: true) or allowing the user to sort by an...
virtual void cellChanged(const YTableCell *cell)
Notification that a cell (its text and/or its icon) was changed from the outside.
YMGA_QCBTable(YWidget *parent, YTableHeader *header, YCBTableMode checkboxMode)
Constructor.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
void checkItem(YItem *item, bool checked=true)
check/uncheck Item from application.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
void selectOrigItem(QTreeWidgetItem *listViewItem)
Select the original item (the YCBTableItem) that corresponds to the specified listViewItem.
virtual void deleteAllItems()
Delete all items.
void slotActivated(QTreeWidgetItem *listViewItem, int column)
Notification that an item is activated (double click or keyboard).
void slotSelected(QTreeWidgetItem *)
Notification that an item is selected (single click or keyboard).
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
virtual ~YMGA_QCBTable()
Destructor.
virtual void addItem(YItem *item)
Add an item.
unsigned int firstColumnOffset
< offset to first YCell usually 1 if checkbox Enabled and mode is YCBTableCheckBoxOnFirstColumn 0 oth...