added save/restore current selection

This commit is contained in:
csoler 2019-03-21 10:14:50 +01:00
parent 3419b44ec1
commit dc24bb6f03
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 63 additions and 12 deletions

View File

@ -144,9 +144,10 @@ MessagesDialog::MessagesDialog(QWidget *parent)
mMessageProxyModel->setFilterRole(RsMessageModel::FilterRole);
ui.messageTreeWidget->setSortingEnabled(true);
ui.messageTreeWidget->setSortingEnabled(false);
ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_AUTHOR,new GxsIdTreeItemDelegate()) ;
ui.messageTreeWidget->setColumnHidden(RsMessageModel::COLUMN_THREAD_CONTENT,true);
ui.messageTreeWidget->setColumnHidden(RsMessageModel::COLUMN_THREAD_MSGID,true);
RSElidedItemDelegate *itemDelegate = new RSElidedItemDelegate(this);
itemDelegate->setSpacing(QSize(0, 2));
@ -251,6 +252,9 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect(NotifyQt::getInstance(), SIGNAL(messagesChanged()), mMessageModel, SLOT(updateMessages()));
connect(NotifyQt::getInstance(), SIGNAL(messagesTagsChanged()), this, SLOT(messagesTagsChanged()));
connect(mMessageModel,SIGNAL(messagesAboutToLoad()),this,SLOT(preModelUpdate()));
connect(mMessageModel,SIGNAL(messagesLoaded()),this,SLOT(postModelUpdate()));
connect(ui.listWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(folderlistWidgetCustomPopupMenu(QPoint)));
connect(ui.listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(changeBox(int)));
connect(ui.quickViewWidget, SIGNAL(currentRowChanged(int)), this, SLOT(changeQuickView(int)));
@ -271,10 +275,42 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect(ui.messageTreeWidget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(currentChanged(const QModelIndex&,const QModelIndex&)));
}
void MessagesDialog::preModelUpdate()
{
// save current selection
mTmpSavedSelectedIds.clear();
QModelIndexList qmil = ui.messageTreeWidget->selectionModel()->selectedRows();
foreach(const QModelIndex& m, qmil)
mTmpSavedSelectedIds.push_back(m.sibling(m.row(),RsMessageModel::COLUMN_THREAD_MSGID).data(RsMessageModel::MsgIdRole).toString()) ;
std::cerr << "Pre-change: saving selection for " << mTmpSavedSelectedIds.size() << " indexes" << std::endl;
}
void MessagesDialog::postModelUpdate()
{
// restore selection
std::cerr << "Post-change: restoring selection for " << mTmpSavedSelectedIds.size() << " indexes" << std::endl;
QItemSelection sel;
foreach(const QString& s,mTmpSavedSelectedIds)
{
QModelIndex i = mMessageProxyModel->mapFromSource(mMessageModel->getIndexOfMessage(s.toStdString()));
sel.select(i.sibling(i.row(),0),i.sibling(i.row(),RsMessageModel::COLUMN_THREAD_NB_COLUMNS-1));
}
ui.messageTreeWidget->selectionModel()->select(sel,QItemSelectionModel::SelectCurrent);
}
void MessagesDialog::sortColumn(int col,Qt::SortOrder so)
{
mMessageProxyModel->setSortingEnabled(true);
ui.messageTreeWidget->setSortingEnabled(true);
mMessageProxyModel->sort(col,so);
ui.messageTreeWidget->setSortingEnabled(false);
mMessageProxyModel->setSortingEnabled(false);
}

View File

@ -59,6 +59,10 @@ public:
void setTextColorInbox(QColor color) { mTextColorInbox = color; }
signals:
void messagesAboutToLoad();
void messagesLoaded();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
int getSelectedMessages(QList<QString>& mid);
@ -66,7 +70,9 @@ protected:
public slots:
//void insertMessages();
void messagesTagsChanged();
void preModelUpdate();
void postModelUpdate();
private slots:
/** Create the context popup menu and it's submenus */
void messageTreeWidgetCustomPopupMenu(QPoint point);
@ -152,6 +158,8 @@ private:
/** Qt Designer generated object */
Ui::MessagesDialog ui;
QList<QString> mTmpSavedSelectedIds;
};
#endif

View File

@ -547,9 +547,13 @@ void RsMessageModel::setMessages(const std::list<Rs::Msgs::MsgInfoSummary>& msgs
endRemoveRows();
mMessages.clear();
mMessagesMap.clear();
for(auto it(msgs.begin());it!=msgs.end();++it)
{
mMessagesMap[(*it).msgId] = mMessages.size();
mMessages.push_back(*it);
}
// now update prow for all posts
@ -614,10 +618,14 @@ void RsMessageModel::getMessageSummaries(BoxName box,std::list<Rs::Msgs::MsgInfo
void RsMessageModel::updateMessages()
{
emit messagesAboutToLoad();
std::list<Rs::Msgs::MsgInfoSummary> msgs;
getMessageSummaries(mCurrentBox,msgs);
setMessages(msgs);
emit messagesLoaded();
}
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
@ -645,16 +653,15 @@ QModelIndex RsMessageModel::getIndexOfMessage(const std::string& mid) const
{
// Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map.
for(uint32_t i=0;i<mMessages.size();++i)
if(mMessages[i].msgId == mid)
{
quintptr ref ;
convertMsgIndexToInternalId(i,ref);
auto it = mMessagesMap.find(mid);
return createIndex(i,0,ref);
}
if(it == mMessagesMap.end() || it->second >= mMessages.size())
return QModelIndex();
return QModelIndex();
quintptr ref ;
convertMsgIndexToInternalId(it->second,ref);
return createIndex(it->second,0,ref);
}
void RsMessageModel::debug_dump() const
@ -662,5 +669,3 @@ void RsMessageModel::debug_dump() const
for(auto it(mMessages.begin());it!=mMessages.end();++it)
std::cerr << "Id: " << it->msgId << ": from " << it->srcId << ": flags=" << it->msgflags << ": title=\"" << it->title << "\"" << std::endl;
}

View File

@ -153,6 +153,7 @@ public slots:
signals:
void messagesLoaded(); // emitted after the messages have been set. Can be used to updated the UI.
void messagesAboutToLoad();
private:
bool passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const;
@ -184,4 +185,5 @@ private:
FilterType mFilterType;
std::vector<Rs::Msgs::MsgInfoSummary> mMessages;
std::map<std::string,uint32_t> mMessagesMap;
};