From d39c47613141efb5ab367a1c012afe9fc2d1d7d8 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 5 Jun 2020 18:07:33 +0200 Subject: [PATCH] fixed entering editing event. --- .../gxschannels/GxsChannelPostFilesModel.cpp | 26 ++++++++++++++++--- .../gxschannels/GxsChannelPostFilesModel.h | 17 +++++------- .../GxsChannelPostsWidgetWithModel.cpp | 18 +++++-------- .../GxsChannelPostsWidgetWithModel.ui | 9 +------ 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index 9098af57b..17554a632 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -65,7 +65,7 @@ void RsGxsChannelPostFilesModel::postMods() { endResetModel(); - emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFiles.size(),COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFiles.size(),COLUMN_FILES_NB_COLUMNS-1,(void*)NULL)); } #ifdef TODO @@ -107,7 +107,7 @@ int RsGxsChannelPostFilesModel::rowCount(const QModelIndex& parent) const int RsGxsChannelPostFilesModel::columnCount(const QModelIndex &/*parent*/) const { - return COLUMN_THREAD_NB_COLUMNS ; + return COLUMN_FILES_NB_COLUMNS ; } // std::vector > RsGxsChannelPostsModel::getPostVersions(const RsGxsMessageId& mid) const @@ -175,7 +175,7 @@ bool RsGxsChannelPostFilesModel::convertRefPointerToTabEntry(quintptr ref, uint3 QModelIndex RsGxsChannelPostFilesModel::index(int row, int column, const QModelIndex & parent) const { - if(row < 0 || column < 0 || column >= COLUMN_THREAD_NB_COLUMNS) + if(row < 0 || column < 0 || column >= COLUMN_FILES_NB_COLUMNS) return QModelIndex(); quintptr ref = getChildRef(parent.internalId(),row); @@ -199,7 +199,10 @@ Qt::ItemFlags RsGxsChannelPostFilesModel::flags(const QModelIndex& index) const if (!index.isValid()) return 0; - return QAbstractItemModel::flags(index); + if(index.column() == COLUMN_FILES_FILE) + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; + else + return QAbstractItemModel::flags(index); } quintptr RsGxsChannelPostFilesModel::getChildRef(quintptr ref,int index) const @@ -258,6 +261,21 @@ int RsGxsChannelPostFilesModel::getChildrenCount(quintptr ref) const return 0; } +QVariant RsGxsChannelPostFilesModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + switch(section) + { + case COLUMN_FILES_FILE: return QString("Status"); + case COLUMN_FILES_SIZE: return QString("Size"); + case COLUMN_FILES_NAME: return QString("File"); + default: + return QString("[No data]"); + } +} + QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) const { #ifdef DEBUG_CHANNEL_MODEL diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h index f42007bdb..111906e64 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h @@ -44,20 +44,14 @@ public: explicit RsGxsChannelPostFilesModel(QObject *parent = NULL); ~RsGxsChannelPostFilesModel(){} - static const int COLUMN_THREAD_NB_COLUMNS = 0x03; // columns for name, size, percentage completion - -#ifdef TODO enum Columns { - COLUMN_THREAD_TITLE =0x00, - COLUMN_THREAD_READ =0x01, - COLUMN_THREAD_DATE =0x02, - COLUMN_THREAD_DISTRIBUTION =0x03, - COLUMN_THREAD_AUTHOR =0x04, - COLUMN_THREAD_CONTENT =0x05, - COLUMN_THREAD_MSGID =0x06, - COLUMN_THREAD_DATA =0x07, + COLUMN_FILES_NAME = 0x00, + COLUMN_FILES_SIZE = 0x01, + COLUMN_FILES_FILE = 0x02, + COLUMN_FILES_NB_COLUMNS = 0x03 }; +#ifdef TODO enum Roles{ SortRole = Qt::UserRole+1, ThreadPinnedRole = Qt::UserRole+2, MissingRole = Qt::UserRole+3, @@ -106,6 +100,7 @@ public: Qt::ItemFlags flags(const QModelIndex& index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; // Custom item roles diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 2865e2649..4e5ea5077 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -62,10 +62,6 @@ static const int CHANNEL_TABS_POSTS = 1; #define VIEW_MODE_FEEDS 1 #define VIEW_MODE_FILES 2 -#define CHANNEL_FILES_COLUMN_NAME 0 -#define CHANNEL_FILES_COLUMN_SIZE 1 -#define CHANNEL_FILES_COLUMN_FILE 2 - Q_DECLARE_METATYPE(RsGxsFile) void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const @@ -150,7 +146,7 @@ QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOpt { RsGxsFile file = index.data(Qt::UserRole).value() ; - if(index.column() == CHANNEL_FILES_COLUMN_FILE) + if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE) return new GxsChannelFilesStatusWidget(file,parent); else return NULL; @@ -208,11 +204,11 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI switch(index.column()) { - case CHANNEL_FILES_COLUMN_NAME: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter,QString::fromUtf8(file.mName.c_str())); + case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter,QString::fromUtf8(file.mName.c_str())); break; - case CHANNEL_FILES_COLUMN_SIZE: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter,misc::friendlyUnit(qulonglong(file.mSize))); + case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: painter->drawText(option.rect,Qt::AlignRight | Qt::AlignVCenter,misc::friendlyUnit(qulonglong(file.mSize))); break; - case CHANNEL_FILES_COLUMN_FILE: { + case RsGxsChannelPostFilesModel::COLUMN_FILES_FILE: { GxsChannelFilesStatusWidget w(file); QPixmap pixmap(w.size()); @@ -241,10 +237,10 @@ QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, con switch(index.column()) { - case CHANNEL_FILES_COLUMN_NAME: return QSize(fm.width(QString::fromUtf8(file.mName.c_str())),fm.height()); - case CHANNEL_FILES_COLUMN_SIZE: return QSize(fm.width(misc::friendlyUnit(qulonglong(file.mSize))),fm.height()); + case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: return QSize(fm.width(QString::fromUtf8(file.mName.c_str())),fm.height()); + case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: return QSize(fm.width(misc::friendlyUnit(qulonglong(file.mSize))),fm.height()); default: - case CHANNEL_FILES_COLUMN_FILE: return GxsChannelFilesStatusWidget(file).size(); + case RsGxsChannelPostFilesModel::COLUMN_FILES_FILE: return GxsChannelFilesStatusWidget(file).size(); } } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui index b6dfb43d5..18e59ff2e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui @@ -495,20 +495,13 @@ p, li { white-space: pre-wrap; } - QAbstractItemView::CurrentChanged + QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked true - - - - Download selected files - - -