diff --git a/ozwadmin-main/main.cpp b/ozwadmin-main/main.cpp index b389d4c..a61ffd6 100644 --- a/ozwadmin-main/main.cpp +++ b/ozwadmin-main/main.cpp @@ -31,6 +31,7 @@ #include "mainwindow.h" Q_LOGGING_CATEGORY(ozwadmin, "ozwadmin"); +Q_LOGGING_CATEGORY(ozwvd, "ozwadmin.valuedelgate"); #define DEF2STR2(x) #x @@ -47,7 +48,8 @@ int main(int argc, char *argv[]) "qt.remoteobjects.warning=true\n" "ozw.*.debug=true\n" "ozw.library.debug=false\n" - "ozwadmin.debug=true\n"); + "ozwadmin.debug=true\n" + "ozwadmin.*=true\n"); #else QLoggingCategory::setFilterRules("default.debug=true"); #endif diff --git a/ozwadmin-main/valuetable.cpp b/ozwadmin-main/valuetable.cpp index 6d102a4..9094dc5 100644 --- a/ozwadmin-main/valuetable.cpp +++ b/ozwadmin-main/valuetable.cpp @@ -23,6 +23,7 @@ ValueTable::ValueTable(QTOZW_ValueIds::ValueIdGenres genre, QWidget *parent) : this->setSelectionMode(QAbstractItemView::SingleSelection); this->setSortingEnabled(true); this->horizontalHeader()->setSectionsMovable(true); + this->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); } void ValueTable::setModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel) @@ -31,7 +32,7 @@ void ValueTable::setModel(QAbstractItemModel *model, QItemSelectionModel *select this->m_proxyModel->setSelectionModel(selectionModel); connect(this->m_proxyModel, &QAbstractItemModel::rowsInserted, this, &ValueTable::resizeContents); connect(this->m_proxyModel, &QAbstractItemModel::rowsRemoved, this, &ValueTable::resizeContents); - connect(selectionModel, &QItemSelectionModel::currentRowChanged, this, &ValueTable::logChanges); + //connect(selectionModel, &QItemSelectionModel::currentRowChanged, this, &ValueTable::logChanges); QTableView::setModel(this->m_proxyModel); for (int i = 0; i <= QTOZW_ValueIds::ValueIdColumns::ValueIdCount; i++) { diff --git a/ozwadmin-widgets/value_delegate.cpp b/ozwadmin-widgets/value_delegate.cpp index 96bf7f6..cffa32f 100644 --- a/ozwadmin-widgets/value_delegate.cpp +++ b/ozwadmin-widgets/value_delegate.cpp @@ -21,17 +21,26 @@ void Value_Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option switch (typeIndex.data().value()) { case QTOZW_ValueIds::ValueIdTypes::List: { QTOZW_ValueIDList val = index.data().value(); + const QWidget* const widget = option.widget; + QStyle* const style = widget ? widget->style() : QApplication::style(); QStyleOptionComboBox comboBoxOption; comboBoxOption.rect = option.rect; comboBoxOption.state = option.state; + comboBoxOption.direction = option.direction; + //comboBoxOption.currentIcon = index.data(Qt::DecorationRole).value(); + //comboBoxOption.currentText = index.data(Qt::DisplayRole).toString(); + comboBoxOption.fontMetrics = option.fontMetrics; + const int iconWidth = style->pixelMetric(QStyle::PM_SmallIconSize, Q_NULLPTR, widget); + comboBoxOption.iconSize = QSize(iconWidth, iconWidth); + comboBoxOption.palette = option.palette; + comboBoxOption.styleObject = option.styleObject; if (readOnly) { comboBoxOption.state |= QStyle::State_ReadOnly; } comboBoxOption.currentText = val.selectedItem; - QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter); - QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &comboBoxOption, painter); - + QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter, widget); + QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &comboBoxOption, painter, widget); break; } case QTOZW_ValueIds::ValueIdTypes::Bool: { @@ -102,7 +111,7 @@ QSize Value_Delegate::sizeHint(const QStyleOptionViewItem &option, const QModelI comboBoxOption.state = option.state; comboBoxOption.currentText = val.selectedItem; QFontMetrics fm(option.font); - Q_FOREACH (const auto& value, val.values) { + Q_FOREACH (const auto& value, val.labels) { hint = hint.expandedTo(qApp->style()->sizeFromContents(QStyle::CT_ComboBox, &comboBoxOption, QSize(fm.width(value), hint.height()))); } @@ -127,6 +136,9 @@ QSize Value_Delegate::sizeHint(const QStyleOptionViewItem &option, const QModelI QWidget *Value_Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { + if (!(index.flags() & Qt::ItemIsEditable)) { + return nullptr; + } QModelIndex typeIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Type); switch (typeIndex.data().value()) { case QTOZW_ValueIds::ValueIdTypes::List: { diff --git a/ozwadmin-widgets/value_delegate.h b/ozwadmin-widgets/value_delegate.h index bfd7af6..80c3321 100644 --- a/ozwadmin-widgets/value_delegate.h +++ b/ozwadmin-widgets/value_delegate.h @@ -5,6 +5,11 @@ #include #include #include +#include + + +Q_DECLARE_LOGGING_CATEGORY(ozwvd); + class Value_Delegate : public QStyledItemDelegate {