Sessions: introduce a sessionDateTime

This can show the last modified time of a session and
will be used in a next commit to make it more clear
when session was saved.

Change-Id: I9f73f62652efc9287563f833f25c49f79c39d936
Task-number: QTCREATORBUG-15790
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tim Jenssen
2016-09-23 19:14:50 +02:00
parent b8f198a985
commit 29f6f4f253
5 changed files with 60 additions and 10 deletions

View File

@@ -39,7 +39,7 @@ namespace ProjectExplorer {
namespace Internal {
SessionModel::SessionModel(QObject *parent)
: QAbstractListModel(parent)
: QAbstractTableModel(parent)
{
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
this, &SessionModel::resetSessions);
@@ -55,6 +55,36 @@ QString SessionModel::sessionAt(int row)
return SessionManager::sessions().value(row, QString());
}
QVariant SessionModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant result;
if (orientation == Qt::Horizontal) {
switch (role) {
case Qt::DisplayRole:
switch (section) {
case 0: result = tr("Session");
break;
case 1: result = tr("Last Modified");
break;
} // switch (section)
break;
} // switch (role) {
}
return result;
}
int SessionModel::columnCount(const QModelIndex &) const
{
static int sectionCount = 0;
if (sectionCount == 0) {
// headers sections defining possible columns
while (!headerData(sectionCount, Qt::Horizontal, Qt::DisplayRole).isNull())
sectionCount++;
}
return sectionCount;
}
int SessionModel::rowCount(const QModelIndex &) const
{
return SessionManager::sessions().count();
@@ -85,6 +115,8 @@ QVariant SessionModel::data(const QModelIndex &index, int role) const
switch (index.column()) {
case 0: result = sessionName;
break;
case 1: result = SessionManager::sessionDateTime(sessionName);
break;
} // switch (section)
break;
case DefaultSessionRole:
@@ -118,7 +150,7 @@ QHash<int, QByteArray> SessionModel::roleNames() const
{ProjectsPathRole, "projectsPath"},
{ProjectsDisplayRole, "projectsName"}
};
return QAbstractListModel::roleNames().unite(extraRoles);
return QAbstractTableModel::roleNames().unite(extraRoles);
}
bool SessionModel::isDefaultVirgin() const
@@ -186,5 +218,6 @@ void SessionModel::runNewSessionDialog(const QString &suggestedName, std::functi
switchToSession(newSession);
}
}
} // namespace Internal
} // namespace ProjectExplorer