#include "listviewdelegate.h"
#include "mainwindow.h"
ListViewDelegate
::ListViewDelegate(MainWindow
*parent
):QItemDelegate(parent
) {}
{
MainWindow* mw=static_cast<MainWindow*>(parent());
if (index.column() == 7)
{
createEditor(mw,option,index);
//this prints at wrong place
return;
}
else if (index.column()==4) //progress
{
progressBarOption.
state=QStyle::State_Enabled;
progressBarOption.
direction = QApplication::layoutDirection();
progressBarOption.rect = option.rect;
progressBarOption.
fontMetrics = QApplication::fontMetrics();
progressBarOption.minimum = 0;
try{
progressBarOption.maximum=mw->totalSize[index.row()];
}
catch(...){
}
progressBarOption.textAlignment = Qt::AlignCenter;
progressBarOption.textVisible = true;
if (index.row() == mw->currIdx){
int progress=mw->progress;
try{
progressBarOption.progress = progress < 0 ? 0 : progress;
}
catch(...){
}
progressBarOption.text = CMFile::getShortValue(progressBarOption.progress)+" / " +CMFile::getShortValue(progressBarOption.maximum);
}
else
{
progressBarOption.text=(index.row() < mw->currIdx)?"Completed":"Queued";
}
return;
}
return;
}
{
cmbBox->insertItem(0,"YES");
cmbBox->insertItem(1,"NO");
cmbBox->setVisible(true);
return cmbBox;
}
void ListViewDelegate
::setEditorData(QWidget *editor,
{
int value = index.model()->data(index, Qt::EditRole).toInt();
QComboBox *cmbBox
= static_cast<QComboBox
*>
(editor
);
cmbBox->setCurrentIndex(value);
}
{
QComboBox *cmbBox
= static_cast<QComboBox
*>
(editor
);
int value = cmbBox->itemText(0).toInt();
model->setData(index, value, Qt::EditRole);
}
void ListViewDelegate
::updateEditorGeometry(QWidget *editor,
{
editor->setGeometry(option.rect);
}
#include "listviewdelegate.h"
#include "mainwindow.h"
ListViewDelegate::ListViewDelegate(MainWindow *parent):QItemDelegate(parent) {}
void ListViewDelegate::paint(QPainter *painter,const QStyleOptionViewItem &option,const QModelIndex &index) const
{
MainWindow* mw=static_cast<MainWindow*>(parent());
if (index.column() == 7)
{
createEditor(mw,option,index);
//this prints at wrong place
return;
}
else if (index.column()==4) //progress
{
QStyleOptionProgressBarV2 progressBarOption;
progressBarOption.state=QStyle::State_Enabled;
progressBarOption.direction = QApplication::layoutDirection();
progressBarOption.rect = option.rect;
progressBarOption.fontMetrics = QApplication::fontMetrics();
progressBarOption.minimum = 0;
try{
progressBarOption.maximum=mw->totalSize[index.row()];
}
catch(...){
}
progressBarOption.textAlignment = Qt::AlignCenter;
progressBarOption.textVisible = true;
if (index.row() == mw->currIdx){
int progress=mw->progress;
try{
progressBarOption.progress = progress < 0 ? 0 : progress;
}
catch(...){
}
progressBarOption.text = CMFile::getShortValue(progressBarOption.progress)+" / " +CMFile::getShortValue(progressBarOption.maximum);
}
else
{
progressBarOption.text=(index.row() < mw->currIdx)?"Completed":"Queued";
}
QApplication::style()->drawControl(QStyle::CE_ProgressBar,&progressBarOption,painter);
return;
}
QItemDelegate::paint(painter,option,index);
return;
}
QWidget* ListViewDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QComboBox *cmbBox=new QComboBox(parent);
cmbBox->insertItem(0,"YES");
cmbBox->insertItem(1,"NO");
cmbBox->setVisible(true);
return cmbBox;
}
void ListViewDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
int value = index.model()->data(index, Qt::EditRole).toInt();
QComboBox *cmbBox = static_cast<QComboBox*>(editor);
cmbBox->setCurrentIndex(value);
}
void ListViewDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QComboBox *cmbBox = static_cast<QComboBox*>(editor);
int value = cmbBox->itemText(0).toInt();
model->setData(index, value, Qt::EditRole);
}
void ListViewDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
To copy to clipboard, switch view to plain text mode
Bookmarks