- Bug on timeline selection that is outside of listview (eg: not loaded)

- Change Listview scroll behaviour
- Hide Filter if no timeline
- Show assistant if no account
This commit is contained in:
Julien Wadel 2021-08-10 11:50:31 +02:00
parent 8f9333967e
commit b7843ada8b
7 changed files with 81 additions and 89 deletions

View file

@ -120,7 +120,7 @@ bool TimelineListModel::removeRows (int row, int count, const QModelIndex &paren
for(auto timeline : oldTimelines)
if(timeline->mSelected)
timeline->setSelected(false);
emit countChanged();
return true;
}
@ -137,7 +137,7 @@ std::shared_ptr<TimelineModel> TimelineListModel::getTimeline(std::shared_ptr<li
if(create){
std::shared_ptr<TimelineModel> model = TimelineModel::create(chatRoom);
//std::shared_ptr<TimelineModel> model = std::make_shared<TimelineModel>(chatRoom);
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(selectedHasChanged(bool)));
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(onSelectedHasChanged(bool)));
connect(model->getChatRoomModel(), &ChatRoomModel::allEntriesRemoved, this, &TimelineListModel::removeChatRoomModel);
add(model);
//connect(model.get(), SIGNAL(conferenceLeft()), this, SLOT(selectedHasChanged(bool)));
@ -179,7 +179,7 @@ std::shared_ptr<ChatRoomModel> TimelineListModel::getChatRoomModel(std::shared_p
if(create){
std::shared_ptr<TimelineModel> model = TimelineModel::create(chatRoom);
if(model){
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(selectedHasChanged(bool)));
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(onSelectedHasChanged(bool)));
connect(model->getChatRoomModel(), &ChatRoomModel::allEntriesRemoved, this, &TimelineListModel::removeChatRoomModel);
//connect(model.get(), SIGNAL(conferenceLeft()), this, SLOT(selectedHasChanged(bool)));
@ -199,6 +199,9 @@ std::shared_ptr<ChatRoomModel> TimelineListModel::getChatRoomModel(ChatRoomModel
return nullptr;
}
int TimelineListModel::getCount() const{
return mTimelines.size();
}
//-------------------------------------------------------------------------------------------------
@ -210,7 +213,7 @@ void TimelineListModel::setSelectedCount(int selectedCount){
}
}
void TimelineListModel::selectedHasChanged(bool selected){
void TimelineListModel::onSelectedHasChanged(bool selected){
if(selected) {
if(mSelectedCount >= 1){// We have more selection than wanted : count select first and unselect after : the final signal will be send only on limit
setSelectedCount(mSelectedCount+1);// It will not send a change signal
@ -219,6 +222,7 @@ void TimelineListModel::selectedHasChanged(bool selected){
(*it)->setSelected(false);
}else
setSelectedCount(mSelectedCount+1);
emit selectedChanged(qobject_cast<TimelineModel*>(sender()));
} else
setSelectedCount(mSelectedCount-1);
}
@ -266,7 +270,7 @@ void TimelineListModel::updateTimelines () {
std::shared_ptr<TimelineModel> model = TimelineModel::create(dbChatRoom);
if( model){
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(selectedHasChanged(bool)));
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(onSelectedHasChanged(bool)));
connect(model->getChatRoomModel(), &ChatRoomModel::allEntriesRemoved, this, &TimelineListModel::removeChatRoomModel);
add(model);
}
@ -281,6 +285,7 @@ void TimelineListModel::add (std::shared_ptr<TimelineModel> timeline){
mTimelines << timeline;
endInsertRows();
resetInternalData();
emit countChanged();
}
void TimelineListModel::remove (TimelineModel* model) {
@ -311,7 +316,7 @@ void TimelineListModel::onChatRoomStateChanged(const std::shared_ptr<linphone::C
&& !getTimeline(chatRoom, false)){// Create a new Timeline if needed
std::shared_ptr<TimelineModel> model = TimelineModel::create(chatRoom);
if(model){
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(selectedHasChanged(bool)));
connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(onSelectedHasChanged(bool)));
connect(model->getChatRoomModel(), &ChatRoomModel::allEntriesRemoved, this, &TimelineListModel::removeChatRoomModel);
add(model);
}

View file

@ -32,6 +32,7 @@ class TimelineListModel : public QAbstractListModel {
public:
Q_PROPERTY(int selectedCount MEMBER mSelectedCount WRITE setSelectedCount NOTIFY selectedCountChanged)
Q_PROPERTY(int count READ getCount NOTIFY countChanged)
TimelineListModel (QObject *parent = Q_NULLPTR);
@ -42,6 +43,7 @@ public:
Q_INVOKABLE QVariantList getLastChatRooms(const int& maxCount) const;
std::shared_ptr<ChatRoomModel> getChatRoomModel(std::shared_ptr<linphone::ChatRoom> chatRoom, const bool &create);
std::shared_ptr<ChatRoomModel> getChatRoomModel(ChatRoomModel * chatRoom);
int getCount() const;
int rowCount (const QModelIndex &index = QModelIndex()) const override;
@ -58,14 +60,16 @@ public:
public slots:
void update();
void removeChatRoomModel(std::shared_ptr<ChatRoomModel> model);
void selectedHasChanged(bool selected);
void onSelectedHasChanged(bool selected);
void onChatRoomStateChanged(const std::shared_ptr<linphone::ChatRoom> &chatRoom,linphone::ChatRoom::State state);
//void onConferenceLeft();
signals:
void countChanged();
void selectedCountChanged(int selectedCount);
void selectedChanged(TimelineModel * timelineModel);
void updated();
private:

View file

@ -42,6 +42,8 @@ TimelineProxyModel::TimelineProxyModel (QObject *parent) : QSortFilterProxyModel
connect(model, SIGNAL(selectedCountChanged(int)), this, SIGNAL(selectedCountChanged(int)));
connect(model, &TimelineListModel::updated, this, &TimelineProxyModel::invalidate);
connect(model, &TimelineListModel::selectedChanged, this, &TimelineProxyModel::selectedChanged);
connect(model, &TimelineListModel::countChanged, this, &TimelineProxyModel::countChanged);
setSourceModel(model);
@ -59,27 +61,11 @@ TimelineProxyModel::TimelineProxyModel (QObject *parent) : QSortFilterProxyModel
}
// -----------------------------------------------------------------------------
/*
void TimelineProxyModel::setCurrentChatRoomModel(ChatRoomModel *data){
mCurrentChatRoomModel = CoreManager::getInstance()->getChatRoomModel(data);
emit currentChatRoomModelChanged(mCurrentChatRoomModel);
if(mCurrentChatRoomModel)
emit currentTimelineChanged(dynamic_cast<TimelineListModel*>(sourceModel())->getTimeline(mCurrentChatRoomModel->getChatRoom(), false).get());
else
emit currentTimelineChanged(nullptr);
int TimelineProxyModel::getCount() const{
return dynamic_cast<TimelineListModel*>(sourceModel())->getCount();
}
ChatRoomModel *TimelineProxyModel::getCurrentChatRoomModel()const{
return mCurrentChatRoomModel.get();
}
void TimelineProxyModel::updateCurrentSelection(){
auto currentAddress = CoreManager::getInstance()->getAccountSettingsModel()->getUsedSipAddress();
if(mCurrentChatRoomModel && !mCurrentChatRoomModel->getChatRoom()->getMe()->getAddress()->weakEqual(currentAddress) ){
setCurrentChatRoomModel(nullptr);
}
}
*/
void TimelineProxyModel::unselectAll(){
dynamic_cast<TimelineListModel*>(sourceModel())->selectAll(false);
}

View file

@ -29,9 +29,9 @@
class TimelineModel;
class TimelineProxyModel : public QSortFilterProxyModel {
Q_OBJECT
Q_OBJECT
public:
enum TimelineFilter {
SimpleChatRoom=1,
@ -44,44 +44,41 @@ public:
};
Q_ENUM(TimelineFilter)
TimelineProxyModel (QObject *parent = Q_NULLPTR);
Q_PROPERTY(int filterFlags MEMBER mFilterFlags WRITE setFilterFlags NOTIFY filterFlagsChanged)
Q_PROPERTY(QString filterText MEMBER mFilterText WRITE setFilterText NOTIFY filterTextChanged)
//Q_PROPERTY(ChatRoomModel *currentChatRoomModel WRITE setCurrentChatRoomModel READ getCurrentChatRoomModel NOTIFY currentChatRoomModelChanged)
//void updateCurrentSelection();
//Q_INVOKABLE void setCurrentChatRoomModel(ChatRoomModel *data);
//ChatRoomModel *getCurrentChatRoomModel() const;
Q_INVOKABLE void unselectAll();
Q_INVOKABLE void setFilterFlags(const int& filterFlags);
Q_INVOKABLE void setFilterText(const QString& text);
//Q_INVOKABLE TimelineModel * getTimeline();
TimelineProxyModel (QObject *parent = Q_NULLPTR);
Q_PROPERTY(int filterFlags MEMBER mFilterFlags WRITE setFilterFlags NOTIFY filterFlagsChanged)
Q_PROPERTY(QString filterText MEMBER mFilterText WRITE setFilterText NOTIFY filterTextChanged)
Q_PROPERTY(int count READ getCount NOTIFY countChanged)
int getCount() const;
Q_INVOKABLE void unselectAll();
Q_INVOKABLE void setFilterFlags(const int& filterFlags);
Q_INVOKABLE void setFilterText(const QString& text);
//Q_INVOKABLE TimelineModel * getTimeline();
signals:
void selectedCountChanged(int selectedCount);
void filterFlagsChanged();
void filterTextChanged();
// void currentChatRoomModelChanged(std::shared_ptr<ChatRoomModel> currentChatRoomModel);
// void currentTimelineChanged(TimelineModel * currentTimeline);
void countChanged();
void selectedCountChanged(int selectedCount);
void selectedChanged(TimelineModel * timelineModel);
void filterFlagsChanged();
void filterTextChanged();
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;
QString getLocalAddress () const;
QString getCleanedLocalAddress () const;
void handleLocalAddressChanged (const QString &localAddress);
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;
QString getLocalAddress () const;
QString getCleanedLocalAddress () const;
void handleLocalAddressChanged (const QString &localAddress);
private:
int mFilterFlags = 0;
QString mFilterText;
//std::shared_ptr<ChatRoomModel> mCurrentChatRoomModel;
//std::shared_ptr<ChatRoomModel> mCurrentChatRoomModel;
};
#endif // TIMELINE_PROXY_MODEL_H_

View file

@ -1,4 +1,4 @@
import QtQuick 2.7
import QtQuick 2.12 //synchronousDrag
import QtQuick.Controls 2.2
import Common 1.0
@ -23,7 +23,8 @@ ListView {
clip: true
contentWidth: width - (vScrollBar.visible?vScrollBar.width:0)
spacing: 0
synchronousDrag:true
maximumFlickVelocity:-1
// ---------------------------------------------------------------------------
// TODO: Find a solution at this bug =>

View file

@ -23,16 +23,6 @@ Rectangle {
//signal entrySelected (string entry)
signal entrySelected (TimelineModel entry)
// ---------------------------------------------------------------------------
/*
function setSelectedEntry (peerAddress, localAddress) {
Logic.setSelectedEntry(peerAddress, localAddress)
}
function resetSelectedEntry () {
Logic.resetSelectedEntry()
}
*/
// ---------------------------------------------------------------------------
color: TimelineStyle.color
@ -49,9 +39,10 @@ Rectangle {
onSelectedCountChanged:{
if(selectedCount<=0) {
view.currentIndex = -1
timeline.entrySelected('',false)
timeline.entrySelected('')
}
}
onSelectedChanged : if(timelineModel) timeline.entrySelected(timelineModel)
// onCurrentTimelineChanged:entrySelected(currentTimeline)
}
/*
@ -71,6 +62,7 @@ Rectangle {
Layout.preferredHeight: TimelineStyle.legend.height
Layout.alignment: Qt.AlignTop
color: showHistory.containsMouse?TimelineStyle.legend.backgroundColor.hovered:TimelineStyle.legend.backgroundColor.normal
visible:view.count > 0
MouseArea{// no more showing history
id:showHistory
@ -278,17 +270,19 @@ Rectangle {
anchors.fill: parent
onClicked: {
//timeline.model.unselectAll()
if(modelData.selected)
if(modelData.selected)// Update selection
timeline.entrySelected(modelData)
modelData.selected = true
view.currentIndex = index;
}
}
Connections{
target:modelData
onSelectedChanged:{
if(selected)
timeline.entrySelected(modelData)
if(selected) {
view.currentIndex = index;
}
}
}
}

View file

@ -264,9 +264,9 @@ ApplicationWindow {
visible: SettingsModel.contactsEnabled
onSelected: {
timeline.model.unselectAll()
setView('Contacts')
}
timeline.model.unselectAll()
setView('Contacts')
}
Icon{
anchors.right:parent.right
anchors.verticalCenter: parent.verticalCenter
@ -285,7 +285,7 @@ ApplicationWindow {
iconSize: 32
name: 'MES CONFERENCES'
onSelected: setView('HistoryView')
onSelected: window.setView('HistoryView')
}
}
@ -297,14 +297,18 @@ ApplicationWindow {
Layout.fillWidth: true
model: TimelineProxyModel{}
onEntrySelected:{ (entry?setView('Conversation', {
chatRoomModel:entry.chatRoomModel
}):
//setView('HistoryView', {}))
setView('Home', {}))
menu.resetSelectedEntry()
}
onEntrySelected:{
if( entry ) {
window.setView('Conversation', {
chatRoomModel:entry.chatRoomModel
})
}else{
window.setView('Home', {})
}
menu.resetSelectedEntry()
}
}
}
@ -318,6 +322,7 @@ ApplicationWindow {
Layout.fillWidth: true
source: 'Home.qml'
Component.onCompleted: if (AccountSettingsModel.accounts.length < 2) source= 'Assistant.qml' // default proxy = 1. Do not use this set diretly in source because of bindings that will override next setSource
}
}
}