ui: file not up to date display

* the codeview now displays a hatched background for a filename when the file's content has changed or the file does not exist anymore.
* added TimePoint class to encapsulate boost.
This commit is contained in:
malte_langkabel
2015-11-03 10:29:29 +01:00
parent 42ab36fbad
commit a524a7a71c
18 changed files with 161 additions and 20 deletions
+39 -6
View File
@@ -4,6 +4,8 @@
#include <QPushButton>
#include <QVBoxLayout>
#include "utility/file/FileSystem.h"
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageActivateFile.h"
#include "utility/messaging/type/MessageShowFile.h"
#include "utility/messaging/type/MessageShowSnippets.h"
@@ -19,6 +21,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
: QFrame(parent)
, m_parent(parent)
, m_filePath(filePath)
, m_updateTitleBarFunctor(std::bind(&QtCodeFile::doUpdateTitleBar, this))
{
setObjectName("code_file");
@@ -28,15 +31,15 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
layout->setAlignment(Qt::AlignTop);
setLayout(layout);
QPushButton* titleWidget = new QPushButton(this);
titleWidget->setObjectName("title_widget");
layout->addWidget(titleWidget);
m_titleBar = new QPushButton(this);
m_titleBar->setObjectName("title_widget");
layout->addWidget(m_titleBar);
QHBoxLayout* titleLayout = new QHBoxLayout();
titleLayout->setMargin(0);
titleLayout->setSpacing(0);
titleLayout->setAlignment(Qt::AlignLeft);
titleWidget->setLayout(titleLayout);
m_titleBar->setLayout(titleLayout);
m_title = new QPushButton(filePath.fileName().c_str(), this);
m_title->setObjectName("title_label");
@@ -54,7 +57,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
titleLayout->addWidget(m_title);
titleWidget->setMinimumHeight(m_title->height() + 4);
m_titleBar->setMinimumHeight(m_title->height() + 4);
m_referenceCount = new QLabel(this);
m_referenceCount->setObjectName("references_label");
@@ -85,7 +88,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
m_snippetButton->setEnabled(false);
m_maximizeButton->setEnabled(false);
connect(titleWidget, SIGNAL(clicked()), this, SLOT(clickedTitleBar()));
connect(m_titleBar, SIGNAL(clicked()), this, SLOT(clickedTitleBar()));
connect(m_title, SIGNAL(clicked()), this, SLOT(clickedTitle()));
connect(m_minimizeButton, SIGNAL(clicked()), this, SLOT(clickedMinimizeButton()));
connect(m_snippetButton, SIGNAL(clicked()), this, SLOT(clickedSnippetButton()));
@@ -105,6 +108,12 @@ QtCodeFile::~QtCodeFile()
{
}
void QtCodeFile::setModificationTime(TimePoint modificationTime)
{
m_modificationTime = modificationTime;
updateTitleBar();
}
const FilePath& QtCodeFile::getFilePath() const
{
return m_filePath;
@@ -386,6 +395,11 @@ void QtCodeFile::clickedMaximizeButton()
m_minimizePlaceholder->hide();
}
void QtCodeFile::handleMessage(MessageWindowFocus* message)
{
updateTitleBar();
}
void QtCodeFile::updateSnippets()
{
int maxDigits = 1;
@@ -420,3 +434,22 @@ void QtCodeFile::updateRefCount(int refCount)
m_referenceCount->hide();
}
}
void QtCodeFile::updateTitleBar()
{
m_updateTitleBarFunctor();
}
void QtCodeFile::doUpdateTitleBar()
{
// cannot use m_filePath.exists() here since it is only checked when FilePath is constructed.
if ((!FileSystem::exists(m_filePath.str())) ||
(FileSystem::getLastWriteTime(m_filePath) > m_modificationTime))
{
m_title->setStyleSheet("background-image: url(data/gui/code_view/images/pattern.png);");
}
else
{
m_title->setStyleSheet("");
}
}
+15
View File
@@ -8,7 +8,11 @@
#include <QFrame>
#include "utility/file/FilePath.h"
#include "utility/TimePoint.h"
#include "utility/types.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageWindowFocus.h"
#include "qt/utility/QtThreadedFunctor.h"
class QLabel;
class QPushButton;
@@ -19,6 +23,7 @@ class TokenLocationFile;
class QtCodeFile
: public QFrame
, MessageListener<MessageWindowFocus>
{
Q_OBJECT
@@ -26,6 +31,8 @@ public:
QtCodeFile(const FilePath& filePath, QtCodeFileList* parent);
virtual ~QtCodeFile();
void setModificationTime(TimePoint modificationTime);
const FilePath& getFilePath() const;
std::string getFileName() const;
Id getFocusedTokenId() const;
@@ -67,11 +74,18 @@ private slots:
void clickedMaximizeButton();
private:
virtual void handleMessage(MessageWindowFocus* message);
void updateSnippets();
void updateRefCount(int refCount);
void updateTitleBar();
void doUpdateTitleBar();
QtThreadedFunctor<> m_updateTitleBarFunctor;
QtCodeFileList* m_parent;
QPushButton* m_titleBar;
QPushButton* m_title;
QLabel* m_referenceCount;
@@ -85,6 +99,7 @@ private:
QWidget* m_minimizePlaceholder;
const FilePath m_filePath;
TimePoint m_modificationTime;
std::shared_ptr<TokenLocationFile> m_locationFile;
};
+4 -1
View File
@@ -47,6 +47,7 @@ void QtCodeFileList::addCodeSnippet(
const std::string& code,
std::shared_ptr<TokenLocationFile> locationFile,
int refCount,
TimePoint modificationTime,
bool insert
){
QtCodeFile* file = getFile(locationFile);
@@ -60,12 +61,14 @@ void QtCodeFileList::addCodeSnippet(
{
file->addCodeSnippet(startLineNumber, title, titleId, code, locationFile, refCount);
}
file->setModificationTime(modificationTime);
}
void QtCodeFileList::addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount)
void QtCodeFileList::addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime)
{
QtCodeFile* file = getFile(locationFile);
file->setLocationFile(locationFile, refCount);
file->setModificationTime(modificationTime);
}
void QtCodeFileList::clearCodeSnippets()
+3 -1
View File
@@ -7,6 +7,7 @@
#include <QFrame>
#include <QScrollArea>
#include "utility/TimePoint.h"
#include "utility/types.h"
class QtCodeFile;
@@ -33,10 +34,11 @@ public:
const std::string& code,
std::shared_ptr<TokenLocationFile> locationFile,
int refCount,
TimePoint modificationTime,
bool insert = false
);
void addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount);
void addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime);
void clearCodeSnippets();
+12 -10
View File
@@ -96,7 +96,7 @@ void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippe
{
if (params.isCollapsed)
{
m_widget->addFile(params.locationFile, params.refCount);
m_widget->addFile(params.locationFile, params.refCount, params.modificationTime);
}
else
{
@@ -106,7 +106,8 @@ void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippe
params.titleId,
params.code,
params.locationFile,
params.refCount
params.refCount,
params.modificationTime
);
}
}
@@ -116,15 +117,16 @@ void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippe
void QtCodeView::doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
{
for (const CodeSnippetParams& snippet : snippets)
for (const CodeSnippetParams& params : snippets)
{
m_widget->addCodeSnippet(
snippet.startLineNumber,
snippet.title,
snippet.titleId,
snippet.code,
snippet.locationFile,
snippet.refCount,
params.startLineNumber,
params.title,
params.titleId,
params.code,
params.locationFile,
params.refCount,
params.modificationTime,
true
);
}
@@ -134,7 +136,7 @@ void QtCodeView::doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippet
void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
{
m_widget->addCodeSnippet(1, params.title, 0, params.code, params.locationFile, -1);
m_widget->addCodeSnippet(1, params.title, 0, params.code, params.locationFile, -1, params.modificationTime);
}
void QtCodeView::doShowFirstActiveSnippet()