Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added changes indicator in tab title.

  • Loading branch information...
commit 1588c4a8d521443ea47f82344aa15352631c75d4 1 parent 3a665d7
@ssharunas authored
View
22 Repleisiukas/mainwindow.cpp
@@ -37,6 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(fileOperations, SIGNAL(UpdateLastUsed()), this, SLOT(UpdateLastUsedMenu()));
connect(ui->stringIn, SIGNAL(updateRequest()), this, SLOT(on_pushButton_Go_clicked()));
+ connect(ui->query, SIGNAL(textChanged()), this, SLOT(onQueryChanged()));
ui->tabs->createNewTab();
tabDocument = ui->tabs->getCurrentDocument();
@@ -109,14 +110,14 @@ void MainWindow::on_openFile_clicked()
{
QString file = senderAction->data().toString();
qDebug() << "trying to open file" << file;
+ LoadQueryToGUI(fileOperations->LoadFromFile(file));
if(tabDocument != 0)
{
tabDocument->setFileName(file);
- tabDocument->nameFromFileName();
+ tabDocument->setQuery(ui->query->toPlainText());
+ tabDocument->setIsModified(false);
}
-
- LoadQueryToGUI(fileOperations->LoadFromFile(file));
}
}
@@ -153,6 +154,8 @@ void MainWindow::on_actionSave_triggered()
if(!tabDocument->fileName().isEmpty())
{
fileOperations->SaveToFile(tabDocument->fileName(), ui->query->toPlainText());
+ tabDocument->setQuery(ui->query->toPlainText());
+ tabDocument->setIsModified(false);
}else
{
on_actionSave_As_triggered();
@@ -168,7 +171,8 @@ void MainWindow::on_actionSave_As_triggered()
if(tabDocument != 0)
{
tabDocument->setFileName(fileName);
- tabDocument->nameFromFileName();
+ tabDocument->setQuery(ui->query->toPlainText());
+ tabDocument->setIsModified(false);
}
}
}
@@ -181,7 +185,7 @@ void MainWindow::on_actionLoad_triggered()
if(tabDocument != 0)
{
tabDocument->setFileName(fileName);
- tabDocument->nameFromFileName();
+ tabDocument->setIsModified(false);
}
LoadQueryToGUI(fileOperations->LoadFromFile(fileName));
@@ -245,6 +249,14 @@ void MainWindow::onClosing()
fileOperations->saveCurrentSession(documents);
}
+void MainWindow::onQueryChanged()
+{
+ if(!contructionInProgress && tabDocument != 0)
+ {
+ tabDocument->setIsModified(ui->query->toPlainText() != tabDocument->query());
+ }
+}
+
void MainWindow::closeEvent(QCloseEvent *ev)
{
onClosing();
View
1  Repleisiukas/mainwindow.h
@@ -40,6 +40,7 @@ class MainWindow : public QMainWindow
private slots:
void onClosing();
+ void onQueryChanged();
void tabChanged(int index);
void on_pushButton_2_clicked();
void UpdateLastUsedMenu();
View
62 Repleisiukas/model/qtabdocument.cpp
@@ -1,7 +1,7 @@
#include "qtabdocument.h"
QTabDocument::QTabDocument(QObject *parent) :
- QObject(parent), _index(-1)
+ QObject(parent), _isModified(0)
{
}
@@ -9,6 +9,11 @@ QTabDocument::~QTabDocument(){
qDebug("Tab was destroyed...");
}
+bool QTabDocument::isModified()
+{
+ return _isModified;
+}
+
QString QTabDocument::uid(){
if(_uid.isNull())
_uid = QUuid::createUuid();
@@ -24,6 +29,28 @@ QString QTabDocument::name(){
return _name;
}
+QString QTabDocument::tabName()
+{
+ QString tabName = name();
+
+ if(!fileName().isEmpty())
+ {
+ int slash = fileName().lastIndexOf('/');
+
+ if((slash != -1) & (slash + 1 < fileName().length()))
+ {
+ tabName = fileName().mid(slash + 1);
+
+ if(isModified())
+ {
+ tabName += "*";
+ }
+ }
+ }
+
+ return tabName;
+}
+
QString QTabDocument::input(){
return _input;
}
@@ -36,18 +63,22 @@ QString QTabDocument::output(){
return _output;
}
-//int QTabDocument::index(){
-// return _index;
-//}
+void QTabDocument::setIsModified(bool value){
+ _isModified = value;
+
+ emit changed();
+}
void QTabDocument::setFileName(QString filename){
_fileName = filename;
+
+ emit changed();
}
void QTabDocument::setName(QString name){
_name = name;
- emit nameChanged();
+ emit changed();
}
void QTabDocument::setInput(QString input){
@@ -61,24 +92,3 @@ void QTabDocument::setQuery(QString query){
void QTabDocument::setOutput(QString output){
_output = output;
}
-
-void QTabDocument::nameFromFileName()
-{
- QString name = QString();
-
- if(!fileName().isEmpty())
- {
- int slash = fileName().lastIndexOf('/');
-
- if((slash != -1) & (slash + 1 < fileName().length()))
- {
- name= fileName().mid(slash + 1);
- }
- }
-
- setName(name);
-}
-
-//void QTabDocument::setIndex(int index){
-// _index = index;
-//}
View
11 Repleisiukas/model/qtabdocument.h
@@ -11,30 +11,29 @@ class QTabDocument : public QObject
explicit QTabDocument(QObject *parent = 0);
~QTabDocument();
+ bool isModified();
QString uid();
QString fileName();
QString name();
+ QString tabName();
QString input();
QString query();
QString output();
-// int index();
+ void setIsModified(bool);
void setFileName(QString);
void setName(QString);
void setInput(QString);
void setQuery(QString);
void setOutput(QString);
-// void setIndex(int);
-
- void nameFromFileName();
signals:
- void nameChanged();
+ void changed();
private:
- int _index;
+ bool _isModified;
QUuid _uid;
QString _fileName;
QString _name;
View
10 Repleisiukas/qadvancedtabbar.cpp
@@ -51,7 +51,7 @@ QTabDocument* QAdvancedTabBar::createDocument()
{
QTabDocument* doc = new QTabDocument(this);
doc->setName(QString("New %1").arg(tab_document_count++));
- connect(doc, SIGNAL(nameChanged()), this, SLOT(updateTab()));
+ connect(doc, SIGNAL(changed()), this, SLOT(updateTab()));
documents[doc->uid()] = doc;
@@ -65,7 +65,7 @@ void QAdvancedTabBar::openDocument(QTabDocument* document)
if(!documents.contains(document->uid()))
{
documents[document->uid()] = document;
- connect(document, SIGNAL(nameChanged()), this, SLOT(updateTab()));
+ connect(document, SIGNAL(changed()), this, SLOT(updateTab()));
}
int index = -1;
@@ -80,7 +80,7 @@ void QAdvancedTabBar::openDocument(QTabDocument* document)
if(index == -1)
{
- index = addTab(document->name());
+ index = addTab(document->tabName());
setTabData(index, QVariant(document->uid()));
}
@@ -91,7 +91,7 @@ void QAdvancedTabBar::openDocument(QTabDocument* document)
void QAdvancedTabBar::createNewTab()
{
QTabDocument* doc = createDocument();
- int index = addTab(doc->name());
+ int index = addTab(doc->tabName());
setTabData(index, QVariant(doc->uid()));
if(currentIndex() != index){
@@ -218,7 +218,7 @@ void QAdvancedTabBar::updateTab()
if(index != -1)
{
- setTabText(index, doc->name());
+ setTabText(index, doc->tabName());
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.