changeeees
This commit is contained in:
parent
eb0c734369
commit
e119d96896
@ -224,7 +224,7 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages
|
||||
}
|
||||
|
||||
// Commit changes.
|
||||
if (db_handle.commit()) {
|
||||
if (db_handle.commit()) {
|
||||
// FULLY reload the model if underlying data is changed.
|
||||
select();
|
||||
fetchAll();
|
||||
|
@ -27,3 +27,24 @@ MessagesModel *MessagesProxyModel::sourceModel() {
|
||||
bool MessagesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const {
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
|
||||
QModelIndexList MessagesProxyModel::mapListFromSource(const QModelIndexList &idxs) {
|
||||
QModelIndexList mapped_idxs;
|
||||
|
||||
foreach (const QModelIndex &index, idxs) {
|
||||
mapped_idxs << mapFromSource(index);
|
||||
}
|
||||
|
||||
return mapped_idxs;
|
||||
}
|
||||
|
||||
QModelIndexList MessagesProxyModel::mapListToSource(const QModelIndexList &idxs) {
|
||||
QModelIndexList source_idxs;
|
||||
|
||||
foreach (const QModelIndex &index, idxs) {
|
||||
source_idxs << mapToSource(index);
|
||||
}
|
||||
|
||||
return source_idxs;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,10 @@ class MessagesProxyModel : public QSortFilterProxyModel {
|
||||
// Source model getter.
|
||||
MessagesModel *sourceModel();
|
||||
|
||||
// Maps list of indexes.
|
||||
QModelIndexList mapListToSource(const QModelIndexList &idxs);
|
||||
QModelIndexList mapListFromSource(const QModelIndexList &idxs);
|
||||
|
||||
protected:
|
||||
// Compares two rows of data.
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
@ -24,16 +24,20 @@ FeedMessageViewer::FeedMessageViewer(QWidget *parent)
|
||||
m_messagesBrowser(new WebBrowser(this)) {
|
||||
initialize();
|
||||
initializeViews();
|
||||
setupConnections();
|
||||
}
|
||||
|
||||
// TODO: Separate into createConnections.
|
||||
void FeedMessageViewer::setupConnections() {
|
||||
// General connections.
|
||||
connect(m_messagesView, SIGNAL(currentMessageRemoved()),
|
||||
m_messagesBrowser, SLOT(clear()));
|
||||
connect(m_messagesView, SIGNAL(currentMessageChanged(Message)),
|
||||
m_messagesBrowser, SLOT(navigateToMessage(Message)));
|
||||
|
||||
// Toolbar forwardings.
|
||||
connect(FormMain::getInstance()->m_ui->m_actionSwitchImportanceOfSelectedMessages,
|
||||
SIGNAL(triggered()),
|
||||
m_messagesView,
|
||||
SLOT(switchSelectedMessagesImportance()));
|
||||
SIGNAL(triggered()), m_messagesView, SLOT(switchSelectedMessagesImportance()));
|
||||
|
||||
}
|
||||
|
||||
void FeedMessageViewer::initialize() {
|
||||
|
@ -27,6 +27,9 @@ class FeedMessageViewer : public TabContent {
|
||||
// Initializes both messages/feeds views.
|
||||
void initializeViews();
|
||||
|
||||
// Sets up connections.
|
||||
void setupConnections();
|
||||
|
||||
private:
|
||||
QToolBar *m_toolBar;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <QHeaderView>
|
||||
#include <QKeyEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "gui/messagesview.h"
|
||||
#include "core/messagesproxymodel.h"
|
||||
@ -121,37 +122,57 @@ void MessagesView::mousePressEvent(QMouseEvent *event) {
|
||||
|
||||
void MessagesView::currentChanged(const QModelIndex ¤t,
|
||||
const QModelIndex &previous) {
|
||||
QModelIndex mapped_current = m_proxyModel->mapToSource(current);
|
||||
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current);
|
||||
|
||||
|
||||
qDebug("Current row changed, row [%d,%d] source %d %d",
|
||||
current.row(), current.column(),
|
||||
mapped_current.row(), mapped_current.column());
|
||||
mapped_current_index.row(), mapped_current_index.column());
|
||||
|
||||
m_sourceModel->setMessageRead(mapped_current.row(), 1);
|
||||
emit currentMessageChanged(m_sourceModel->messageAt(mapped_current.row()));
|
||||
if (mapped_current_index.isValid()) {
|
||||
m_sourceModel->setMessageRead(mapped_current_index.row(), 1);
|
||||
emit currentMessageChanged(m_sourceModel->messageAt(mapped_current_index.row()));
|
||||
}
|
||||
else {
|
||||
emit currentMessageRemoved();
|
||||
}
|
||||
|
||||
QTreeView::currentChanged(current, previous);
|
||||
}
|
||||
|
||||
void MessagesView::switchSelectedMessagesImportance() {
|
||||
/*
|
||||
// toto muže obsahovat moc indexů -> z jednoho radku to muze
|
||||
// obsahovat indexy ze vsech sloupcu, overit.
|
||||
QItemSelection selected_indexes = selectionModel()->selection();
|
||||
QItemSelection mapped_selection = m_proxyModel->mapSelectionToSource(selected_indexes);
|
||||
QModelIndex current_idx = selectionModel()->currentIndex();
|
||||
QModelIndex mapped_current_idx = m_proxyModel->mapToSource(current_idx);
|
||||
QModelIndexList selected_idxs = selectionModel()->selectedRows();
|
||||
QModelIndexList mapped_idxs = m_proxyModel->mapListToSource(selected_idxs);
|
||||
|
||||
m_sourceModel->switchBatchMessageImportance(mapped_selection.indexes());
|
||||
*/
|
||||
m_sourceModel->switchBatchMessageImportance(mapped_idxs);
|
||||
|
||||
QModelIndexList selected_indexes = selectionModel()->selectedRows();
|
||||
QModelIndexList mapped_indexes;
|
||||
//selected_idxs.clear();
|
||||
selected_idxs = m_proxyModel->mapListFromSource(mapped_idxs);
|
||||
|
||||
foreach (const QModelIndex &index, selected_indexes) {
|
||||
mapped_indexes << m_proxyModel->mapToSource(index);
|
||||
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
|
||||
/*
|
||||
foreach (const QModelIndex &index, mapped_idxs) {
|
||||
selected_idxs << m_proxyModel->mapFromSource(m_sourceModel->index(index.row(),
|
||||
index.column()));
|
||||
}
|
||||
*/
|
||||
current_idx = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_idx.row(),
|
||||
mapped_current_idx.column()));
|
||||
|
||||
m_sourceModel->switchBatchMessageImportance(mapped_indexes);
|
||||
setCurrentIndex(current_idx);
|
||||
scrollTo(current_idx);
|
||||
reselectIndexes(selected_idxs);
|
||||
}
|
||||
|
||||
void MessagesView::reselectIndexes(const QModelIndexList &indexes) {
|
||||
selectionModel()->clearSelection();
|
||||
|
||||
foreach (const QModelIndex &idx, indexes) {
|
||||
selectionModel()->select(idx,
|
||||
QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesView::setAllMessagesRead() {
|
||||
|
@ -27,6 +27,9 @@ class MessagesView : public QTreeView {
|
||||
void switchSelectedMessagesImportance();
|
||||
void setAllMessagesRead();
|
||||
|
||||
protected slots:
|
||||
void reselectIndexes(const QModelIndexList &indexes);
|
||||
|
||||
protected:
|
||||
void setupAppearance();
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
Loading…
x
Reference in New Issue
Block a user