mirror of
https://github.com/Fishwaldo/ozw-admin.git
synced 2025-03-15 19:31:38 +00:00
ozwadmin-main/valuetable.cpp
This commit is contained in:
parent
9440a7d5dd
commit
cfba9838ed
4 changed files with 26 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -21,17 +21,26 @@ void Value_Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option
|
|||
switch (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>()) {
|
||||
case QTOZW_ValueIds::ValueIdTypes::List: {
|
||||
QTOZW_ValueIDList val = index.data().value<QTOZW_ValueIDList>();
|
||||
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<QIcon>();
|
||||
//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<QTOZW_ValueIds::ValueIdTypes>()) {
|
||||
case QTOZW_ValueIds::ValueIdTypes::List: {
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(ozwvd);
|
||||
|
||||
|
||||
class Value_Delegate : public QStyledItemDelegate
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue