diff --git a/src/aichatassistant.cpp b/src/aichatassistant.cpp index b9e03dff9a..182a722536 100644 --- a/src/aichatassistant.cpp +++ b/src/aichatassistant.cpp @@ -329,6 +329,9 @@ void AIChatAssistant::onTreeViewClicked(const QModelIndex &index) }else{ btInsert->setText(tr("Insert")); } + }else{ + // no query sent yet + textBrowser->clear(); } } /*! diff --git a/src/aiquerystoragemodel.cpp b/src/aiquerystoragemodel.cpp index 54a7f4ffa2..f2ec5dc89f 100644 --- a/src/aiquerystoragemodel.cpp +++ b/src/aiquerystoragemodel.cpp @@ -9,8 +9,19 @@ QVariant AIQueryStorageModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { quintptr parent_row = index.internalId(); if (!parent_row) { + if(m_segments.size()>0){ + return m_segments.at(index.row()).name; + } return QStringLiteral("Queries"); } else { + if(m_segments.size()>0){ + int previous=0; + if(parent_row>1 && parent_row<=m_segments.size()){ + previous=m_segments.at(parent_row-2).index; + } + int r=index.row(); + return m_files.value(previous+r); + } return m_files.at(index.row()); } } @@ -32,17 +43,30 @@ QModelIndex AIQueryStorageModel::parent(const QModelIndex &index) const if (row == 0) { return QModelIndex{}; } else { - return createIndex(row, 0); + return createIndex(row-1, 0); } } int AIQueryStorageModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) { - return 1; // for now + if(m_segments.size()>0){ + return m_segments.size(); + } + return 1; // nothing recorded yet } else { quintptr row = parent.internalId(); if (row == 0) { + if(m_segments.size()>0){ + int row=parent.row(); + if(row>0){ + int previous=m_segments.at(row-1).index; + int current=m_segments.at(row).index; + return current-previous; + }else{ + return m_segments.at(row).index; + } + } return m_files.size(); } return 0; @@ -66,6 +90,32 @@ void AIQueryStorageModel::setStoragePath(const QString &path) { m_storageDirectory.setPath(path); m_files=m_storageDirectory.entryList({"*.json"},QDir::Files,QDir::Reversed); + if(m_files.isEmpty()) { + return; + } + auto lst_names = std::vector{tr("Today"),tr("Last Week"),tr("Last Month")}; + auto lst_date = std::vector{QDate::currentDate(),QDate::currentDate().addDays(-7),QDate::currentDate().addMonths(-1)}; + auto last_it=m_files.cbegin(); + for(size_t i=0;i()); + if (it-last_it > 0) { + TimeFrame tf; + tf.name=lst_names.at(i); + tf.index=it-m_files.constBegin(); + m_segments.append(tf); + last_it=it; + } + if(it==m_files.cend()){ + break; + } + } + if(last_it!=m_files.cend()){ + TimeFrame tf; + tf.name=tr("Older"); + tf.index=last_it-m_files.constBegin(); + m_segments.append(tf); + } } QString AIQueryStorageModel::getFileName(const QModelIndex &index) const @@ -74,6 +124,14 @@ QString AIQueryStorageModel::getFileName(const QModelIndex &index) const if (row == 0) { return QString{}; } + if(m_segments.size()>0){ + int previous=0; + if(row>1 && row<=m_segments.size()){ + previous=m_segments.at(row-2).index; + } + int r=index.row(); + return m_storageDirectory.absoluteFilePath(m_files.value(previous+r)); + } return m_storageDirectory.absoluteFilePath(m_files.at(index.row())); } @@ -81,5 +139,16 @@ void AIQueryStorageModel::addFileName(const QString &name) { beginInsertRows(QModelIndex{},m_files.size(),m_files.size()); m_files.prepend(name); + for(auto &tf:m_segments){ + ++tf.index; + } + if(m_segments.size()>0){ + if(m_segments[0].name!=tr("Today")){ + TimeFrame tf; + tf.name=tr("Today"); + tf.index=1; + m_segments.prepend(tf); + } + } endInsertRows(); } diff --git a/src/aiquerystoragemodel.h b/src/aiquerystoragemodel.h index 2021822bd6..595222c078 100644 --- a/src/aiquerystoragemodel.h +++ b/src/aiquerystoragemodel.h @@ -24,6 +24,14 @@ class AIQueryStorageModel : public QAbstractItemModel QDir m_storageDirectory; QStringList m_files; + struct TimeFrame + { + QString name; + int index; + }; + QListm_segments; + + // QAbstractItemModel interface };