In some cases need just disable GUI (Read only mode) without writing in file.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-25 18:18:01 +03:00
parent 6294fcc753
commit 3c32c869a6
7 changed files with 136 additions and 81 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 B

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 B

After

Width:  |  Height:  |  Size: 616 B

View File

@ -151,12 +151,13 @@ void TMainWindow::LoadFile(const QString &path)
InitWindow(); InitWindow();
RefreshData(); RefreshData();
ReadOnly(m->ReadOnly());
if (ui->tableWidget->rowCount() > 0) if (ui->tableWidget->rowCount() > 0)
{ {
ui->tableWidget->selectRow(0); ui->tableWidget->selectRow(0);
} }
GUIReadOnly(m->ReadOnly()); // Keep last
} }
catch (VException &e) catch (VException &e)
{ {
@ -209,6 +210,8 @@ void TMainWindow::FileNew()
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
InitWindow(); InitWindow();
GUIReadOnly(m->ReadOnly()); // Keep last
} }
else else
{ {
@ -420,101 +423,71 @@ void TMainWindow::AboutApplication()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveGivenName() void TMainWindow::SaveGivenName()
{ {
if (m->GivenName() != ui->lineEditGivenName->text())
{
m->SetGivenName(ui->lineEditGivenName->text()); m->SetGivenName(ui->lineEditGivenName->text());
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveFamilyName() void TMainWindow::SaveFamilyName()
{ {
if (m->FamilyName() != ui->lineEditFamilyName->text())
{
m->SetFamilyName(ui->lineEditFamilyName->text()); m->SetFamilyName(ui->lineEditFamilyName->text());
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveEmail() void TMainWindow::SaveEmail()
{ {
if (m->Email() != ui->lineEditEmail->text())
{
m->SetEmail(ui->lineEditEmail->text()); m->SetEmail(ui->lineEditEmail->text());
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveSex(int index) void TMainWindow::SaveSex(int index)
{ {
m->SetSex(static_cast<SexType>(ui->comboBoxSex->itemData(index).toInt())); const SexType type = static_cast<SexType>(ui->comboBoxSex->itemData(index).toInt());
if (m->Sex() != type)
{
m->SetSex(type);
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveBirthDate(const QDate &date) void TMainWindow::SaveBirthDate(const QDate &date)
{ {
if (m->BirthDate() != date)
{
m->SetBirthDate(date); m->SetBirthDate(date);
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveNotes() void TMainWindow::SaveNotes()
{ {
if (m->Notes() != ui->plainTextEditNotes->toPlainText())
{
m->SetNotes(ui->plainTextEditNotes->toPlainText()); m->SetNotes(ui->plainTextEditNotes->toPlainText());
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ReadOnly(bool ro) void TMainWindow::ReadOnly(bool ro)
{ {
ui->actionReadOnly->setChecked(ro);
if (ro)
{
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_locked.png"));
}
else
{
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_opened.png"));
}
m->SetReadOnly(ro); m->SetReadOnly(ro);
MeasurementsWasSaved(false); MeasurementsWasSaved(false);
ui->plainTextEditNotes->setReadOnly(ro); GUIReadOnly(ro);
ui->actionAddCustom->setDisabled(ro);
ui->actionAddKnown->setDisabled(ro);
if (not ro)
{
if (QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0))
{
if (nameField->text().indexOf(CustomSign) == 0) // Check if custom
{
ui->lineEditName->setReadOnly(ro);
}
}
}
else
{
ui->lineEditName->setReadOnly(ro);
}
ui->plainTextEditDescription->setReadOnly(ro);
if (mType == MeasurementsType::Individual)
{
ui->lineEditGivenName->setReadOnly(ro);
ui->lineEditFamilyName->setReadOnly(ro);
ui->dateEditBirthDate->setReadOnly(ro);
ui->comboBoxSex->setDisabled(ro);
ui->lineEditEmail->setReadOnly(ro);
ui->plainTextEditFormula->setReadOnly(ro);
}
else
{
ui->doubleSpinBoxBaseValue->setDisabled(ro);
ui->doubleSpinBoxInSizes->setDisabled(ro);
ui->doubleSpinBoxInHeights->setDisabled(ro);
gradationHeights->setDisabled(ro);
gradationSizes->setDisabled(ro);
}
Controls(); // Buttons remove, up, down
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -854,11 +827,23 @@ void TMainWindow::ShowMData()
{ {
ui->plainTextEditDescription->setReadOnly(false); ui->plainTextEditDescription->setReadOnly(false);
ui->lineEditName->setReadOnly(false); ui->lineEditName->setReadOnly(false);
ui->lineEditFullName->setReadOnly(false);
if (mType == MeasurementsType::Individual)
{
ui->plainTextEditFormula->setReadOnly(false);
}
} }
else else
{ {
ui->plainTextEditDescription->setReadOnly(false); ui->plainTextEditDescription->setReadOnly(true);
ui->lineEditName->setReadOnly(false); ui->lineEditName->setReadOnly(true);
ui->lineEditFullName->setReadOnly(true);
if (mType == MeasurementsType::Individual)
{
ui->plainTextEditFormula->setReadOnly(true);
}
} }
} }
} }
@ -1140,6 +1125,7 @@ void TMainWindow::InitWindow()
SCASSERT(m != nullptr); SCASSERT(m != nullptr);
ui->labelToolTip->setVisible(false); ui->labelToolTip->setVisible(false);
ui->tabWidget->setVisible(true); ui->tabWidget->setVisible(true);
ui->tabWidget->setCurrentIndex(0);
ui->plainTextEditNotes->setEnabled(true); ui->plainTextEditNotes->setEnabled(true);
@ -1557,10 +1543,6 @@ void TMainWindow::Controls()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::MFields(bool enabled) void TMainWindow::MFields(bool enabled)
{ {
ui->lineEditName->setEnabled(enabled);
ui->plainTextEditDescription->setEnabled(enabled);
ui->lineEditFullName->setEnabled(enabled);
if (mType == MeasurementsType::Standard) if (mType == MeasurementsType::Standard)
{ {
ui->doubleSpinBoxBaseValue->setEnabled(enabled); ui->doubleSpinBoxBaseValue->setEnabled(enabled);
@ -1569,7 +1551,6 @@ void TMainWindow::MFields(bool enabled)
} }
else else
{ {
ui->plainTextEditFormula->setEnabled(enabled);
ui->pushButtonGrow->setEnabled(enabled); ui->pushButtonGrow->setEnabled(enabled);
ui->toolButtonExpr->setEnabled(enabled); ui->toolButtonExpr->setEnabled(enabled);
} }
@ -1633,6 +1614,68 @@ void TMainWindow::Open(const QString &pathTo, const QString &filter)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::GUIReadOnly(bool ro)
{
ui->actionReadOnly->setChecked(ro);
if (ro)
{
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_locked.png"));
}
else
{
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_opened.png"));
}
ui->plainTextEditNotes->setReadOnly(ro);
ui->actionAddCustom->setDisabled(ro);
ui->actionAddKnown->setDisabled(ro);
ui->lineEditName->setDisabled(false);
if (not ro)
{
if (QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0))
{
if (nameField->text().indexOf(CustomSign) == 0) // Check if custom
{
ui->lineEditName->setReadOnly(ro);
}
}
}
else
{
ui->lineEditName->setReadOnly(ro);
}
ui->plainTextEditDescription->setDisabled(false);
ui->plainTextEditDescription->setReadOnly(ro);
ui->lineEditFullName->setDisabled(false);
ui->lineEditFullName->setReadOnly(ro);
if (mType == MeasurementsType::Individual)
{
ui->lineEditGivenName->setReadOnly(ro);
ui->lineEditFamilyName->setReadOnly(ro);
ui->dateEditBirthDate->setReadOnly(ro);
ui->comboBoxSex->setDisabled(ro);
ui->lineEditEmail->setReadOnly(ro);
ui->plainTextEditFormula->setDisabled(false);
ui->plainTextEditFormula->setReadOnly(ro);
}
else
{
ui->doubleSpinBoxBaseValue->setDisabled(ro);
ui->doubleSpinBoxInSizes->setDisabled(ro);
ui->doubleSpinBoxInHeights->setDisabled(ro);
gradationHeights->setDisabled(ro);
gradationSizes->setDisabled(ro);
}
Controls(); // Buttons remove, up, down
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetDecimals() void TMainWindow::SetDecimals()
{ {

View File

@ -69,6 +69,7 @@ private slots:
void AboutToShowWindowMenu(); void AboutToShowWindowMenu();
void ShowWindow(); void ShowWindow();
void AboutApplication(); void AboutApplication();
void SaveGivenName(); void SaveGivenName();
void SaveFamilyName(); void SaveFamilyName();
void SaveEmail(); void SaveEmail();
@ -144,6 +145,7 @@ private:
void EvalFormula(const QString &formula, VContainer *data, QLabel *label); void EvalFormula(const QString &formula, VContainer *data, QLabel *label);
void Open(const QString &pathTo, const QString &filter); void Open(const QString &pathTo, const QString &filter);
void GUIReadOnly(bool ro);
}; };
#endif // TMAINWINDOW_H #endif // TMAINWINDOW_H

View File

@ -32,7 +32,7 @@
<string/> <string/>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tabMeasurements"> <widget class="QWidget" name="tabMeasurements">
<attribute name="icon"> <attribute name="icon">

View File

@ -5,16 +5,16 @@
<xs:sequence> <xs:sequence>
<xs:element name="version" type="formatVersion"></xs:element> <xs:element name="version" type="formatVersion"></xs:element>
<xs:element name="read-only" type="xs:boolean"></xs:element> <xs:element name="read-only" type="xs:boolean"></xs:element>
<xs:element name="unit" type="units"></xs:element>
<xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="personal" minOccurs="0" maxOccurs="1"> <xs:element name="unit" type="units"></xs:element>
<xs:element name="personal">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:element name="family-name" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="given-name" type="xs:string"></xs:element>
<xs:element name="given-name" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="family-name" type="xs:string"></xs:element>
<xs:element name="birth-date" type="xs:date" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="birth-date" type="xs:date"></xs:element>
<xs:element name="sex" type="sex" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="sex" type="sex"></xs:element>
<xs:element name="email" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="email" type="xs:string"></xs:element>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>

View File

@ -304,7 +304,7 @@ void VMeasurements::SetGivenName(const QString &text)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QDate VMeasurements::BirthDate() const QDate VMeasurements::BirthDate() const
{ {
const QString date = UniqueTagText(TagBirthDate, "1900-01-01"); const QString date = UniqueTagText(TagBirthDate, "1990-02-15");
return QDate::fromString(date, "yyyy-MM-dd"); return QDate::fromString(date, "yyyy-MM-dd");
} }
@ -541,8 +541,18 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit)
QDomElement personal = createElement(TagPersonal); QDomElement personal = createElement(TagPersonal);
personal.appendChild(createElement(TagGivenName)); personal.appendChild(createElement(TagGivenName));
personal.appendChild(createElement(TagBirthDate)); personal.appendChild(createElement(TagFamilyName));
personal.appendChild(createElement(TagSex));
QDomElement date = createElement(TagBirthDate);
const QDomText newDate = createTextNode(QDate(1990, 02, 15).toString("yyyy-MM-dd"));
date.appendChild(newDate);
personal.appendChild(date);
QDomElement sex = createElement(TagSex);
const QDomText newSex = createTextNode(GenderToStr(SexType::Male));
sex.appendChild(newSex);
personal.appendChild(sex);
personal.appendChild(createElement(TagEmail)); personal.appendChild(createElement(TagEmail));
mElement.appendChild(personal); mElement.appendChild(personal);