Fix text lost when switching timelines : if QML TextEdit is set for rich texts, Qt will change the text before item completion.

This commit is contained in:
Julien Wadel 2023-05-09 17:31:47 +02:00
parent 1dd4f4f285
commit c46727ce75
4 changed files with 14 additions and 6 deletions

View file

@ -110,7 +110,6 @@ void ChatRoomProxyModel::sendMessage(const QString &text){
void ChatRoomProxyModel::compose (const QString& text) {
if (mChatRoomModel && !text.isEmpty())
mChatRoomModel->compose();
gCachedText = text;
}
int ChatRoomProxyModel::getEntryTypeFilter () {
@ -255,6 +254,10 @@ QString ChatRoomProxyModel::getCachedText() const{
return gCachedText;
}
void ChatRoomProxyModel::setCachedText(const QString& text){
gCachedText = text;
}
void ChatRoomProxyModel::setIsCall(const bool& isCall){
if(mIsCall != isCall) {
if(mChatRoomModel){

View file

@ -40,7 +40,7 @@ class ChatRoomProxyModel : public SortFilterProxyModel {
Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress WRITE setFullLocalAddress NOTIFY fullLocalAddressChanged)
Q_PROPERTY(ChatRoomModel *chatRoomModel READ getChatRoomModel WRITE setChatRoomModel NOTIFY chatRoomModelChanged)
Q_PROPERTY(QList<QString> composers READ getComposers NOTIFY isRemoteComposingChanged)
Q_PROPERTY(QString cachedText READ getCachedText)
Q_PROPERTY(QString cachedText READ getCachedText WRITE setCachedText NOTIFY cachedTextChanged)
Q_PROPERTY(QString filterText MEMBER mFilterText WRITE setFilterText NOTIFY filterTextChanged)
Q_PROPERTY(bool markAsReadEnabled READ markAsReadEnabled WRITE enableMarkAsRead NOTIFY markAsReadEnabledChanged)// Focus is at end of the list. Used to reset message count if not at end
@ -95,6 +95,7 @@ signals:
void entryTypeFilterChanged (int type);
void filterTextChanged();
void isCallChanged();
void cachedTextChanged();
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
@ -122,6 +123,7 @@ private:
QList<QString> getComposers () const;
QString getCachedText() const;
void setCachedText(const QString& text);
void reload (ChatRoomModel *chatRoomModel);

View file

@ -638,7 +638,6 @@ bool Utils::isImage(const QString& path){
}else if(!QMimeDatabase().mimeTypeForFile(info).name().contains("image/"))
return false;
QImageReader reader(path);
qWarning() << reader.imageCount();
return reader.canRead() && reader.imageCount() == 1;
}

View file

@ -411,9 +411,13 @@ Rectangle {
placeholderText: qsTr('newMessagePlaceholder')
recordAudioToggled: RecorderManager.haveVocalRecorder && RecorderManager.getVocalRecorder().state != LinphoneEnums.RecorderStateClosed
emojiVisible: chatEmojis.visible
onDropped: Logic.handleFilesDropped(files)
onTextChanged: Logic.handleTextChanged(getText())
property bool componentReady: false
onTextChanged: {// This slot can be call before the item has been completed because of Rich text. So the cache must not take it account.
if(componentReady) {
proxyModel.cachedText=text
}
}
onValidText: {
textArea.text = ''
chat.bindToEnd = true
@ -428,7 +432,7 @@ Rectangle {
onEmojiClicked: {
chatEmojis.visible = !chatEmojis.visible
}
Component.onCompleted: {text = proxyModel.cachedText; cursorPosition=text.length}
Component.onCompleted: {text = proxyModel.cachedText; cursorPosition=text.length;componentReady=true}
Rectangle{
anchors.fill:parent
color:'white'