@@ -110,20 +110,29 @@ EditDialog::~EditDialog()
110110 delete ui;
111111}
112112
113- void EditDialog::setCurrentIndex ( const QModelIndex& idx )
113+ void EditDialog::promptSaveData ( )
114114{
115- if (m_currentIndex != QPersistentModelIndex (idx) && ui->buttonApply ->isEnabled () &&
116- (sciEdit->isModified () || ui->qtEdit ->document ()->isModified () || hexEdit->isModified ())) {
115+ if (m_currentIndex.isValid () && isModified ()) {
117116
118117 QMessageBox::StandardButton reply = QMessageBox::question (
119118 this ,
120119 tr (" Unsaved data in the cell editor" ),
121120 tr (" The cell editor contains data not yet applied to the database.\n "
122- " Do you want to apply the edited data?" ),
123- QMessageBox::Apply | QMessageBox::Discard);
121+ " Do you want to apply the edited data to row=%1, column=%2?" )
122+ .arg (m_currentIndex.row () + 1 ).arg (m_currentIndex.column ()),
123+ QMessageBox::Apply | QMessageBox::Discard, QMessageBox::Apply);
124124
125125 if (reply == QMessageBox::Apply)
126126 accept ();
127+ else
128+ reject ();
129+ }
130+ }
131+
132+ void EditDialog::setCurrentIndex (const QModelIndex& idx)
133+ {
134+ if (m_currentIndex != QPersistentModelIndex (idx)) {
135+ promptSaveData ();
127136 }
128137
129138 setDisabled (!idx.isValid ());
@@ -132,11 +141,27 @@ void EditDialog::setCurrentIndex(const QModelIndex& idx)
132141
133142 QByteArray bArrData = idx.data (Qt::EditRole).toByteArray ();
134143 loadData (bArrData);
144+ if (idx.isValid ()) {
145+ ui->labelCell ->setText (tr (" Editing row=%1, column=%2" )
146+ .arg (m_currentIndex.row () + 1 ).arg (m_currentIndex.column ()));
147+ } else {
148+ ui->labelCell ->setText (tr (" No cell active." ));
149+ }
135150 updateCellInfoAndMode (bArrData);
136151
137- ui->buttonApply ->setDisabled (true );
138- sciEdit->setModified (false );
139- ui->qtEdit ->document ()->setModified (false );
152+ setModified (false );
153+ }
154+
155+ bool EditDialog::isModified () const
156+ {
157+ return (sciEdit->isModified () || ui->qtEdit ->document ()->isModified ());
158+ }
159+
160+ void EditDialog::setModified (bool modified)
161+ {
162+ ui->buttonApply ->setEnabled (modified);
163+ sciEdit->setModified (modified);
164+ ui->qtEdit ->document ()->setModified (modified);
140165}
141166
142167void EditDialog::showEvent (QShowEvent*)
@@ -154,7 +179,7 @@ void EditDialog::reject()
154179{
155180 // We override this, to ensure the Escape key doesn't make the Edit Cell
156181 // dock go away
157- return ;
182+ setCurrentIndex (m_currentIndex) ;
158183}
159184
160185// Loads data from a cell into the Edit Cell window
@@ -663,6 +688,7 @@ void EditDialog::accept()
663688 // The data is different, so commit it back to the database
664689 emit recordTextUpdated (m_currentIndex, removedBom + newTextData.toUtf8 (), false );
665690 }
691+ setModified (false );
666692}
667693
668694void EditDialog::setDataInBuffer (const QByteArray& bArrdata, DataSources source)
@@ -888,12 +914,14 @@ void EditDialog::editTextChanged()
888914
889915 // If data has been entered in the text editor, it can't be a NULL
890916 // any more. It hasn't been validated yet, so it cannot be JSON nor XML.
891- if (dataType == Null && isModified && dataLength != 0 )
917+ if (dataType == Null && isModified && dataLength != 0 ) {
892918 dataType = Text;
893-
894- if (dataType != Null)
895- ui->labelType ->setText (tr (" Type of data currently in cell: Text / Numeric" ));
896- ui->labelSize ->setText (tr (" %n character(s)" , " " , dataLength));
919+ sciEdit->clearTextInMargin ();
920+ }
921+ if (dataType == Null)
922+ ui->labelInfo ->setText (tr (" Type: NULL; Size: 0 bytes" ));
923+ else
924+ ui->labelInfo ->setText (tr (" Type: Text / Numeric; Size: %n character(s)" , " " , dataLength));
897925 }
898926}
899927
@@ -989,6 +1017,9 @@ void EditDialog::setFocus()
9891017// Sets or unsets read-only properties for the editors.
9901018void EditDialog::setReadOnly (bool ro)
9911019{
1020+ if (ro && !isReadOnly) {
1021+ promptSaveData ();
1022+ }
9921023 isReadOnly = ro;
9931024
9941025 ui->buttonApply ->setEnabled (!ro);
@@ -1050,15 +1081,16 @@ void EditDialog::updateCellInfoAndMode(const QByteArray& bArrdata)
10501081 // Display the image format
10511082 QString imageFormat = imageReader.format ();
10521083
1053- ui->labelType ->setText (tr (" Type of data currently in cell: %1 Image" ).arg (imageFormat.toUpper ()));
1054-
10551084 // Display the image dimensions and size
10561085 QSize imageDimensions = imageReader.size ();
10571086 unsigned int imageSize = static_cast <unsigned int >(cellData.size ());
10581087
1059- QString labelSizeText = tr (" %1x%2 pixel(s)" ).arg (imageDimensions.width ()).arg (imageDimensions.height ()) + " , " + humanReadableSize (imageSize);
1088+ QString labelInfoText = tr (" Type: %1 Image; Size: %2x%3 pixel(s)" )
1089+ .arg (imageFormat.toUpper ())
1090+ .arg (imageDimensions.width ()).arg (imageDimensions.height ())
1091+ + " , " + humanReadableSize (imageSize);
10601092
1061- ui->labelSize ->setText (labelSizeText );
1093+ ui->labelInfo ->setText (labelInfoText );
10621094
10631095 return ;
10641096 }
@@ -1067,8 +1099,7 @@ void EditDialog::updateCellInfoAndMode(const QByteArray& bArrdata)
10671099 switch (dataType) {
10681100 case Null: {
10691101 // NULL data type
1070- ui->labelType ->setText (tr (" Type of data currently in cell: NULL" ));
1071- ui->labelSize ->setText (tr (" %n byte(s)" , " " , 0 ));
1102+ ui->labelInfo ->setText (tr (" Type: NULL; Size: 0 bytes" ));
10721103
10731104 // Use margin to set the NULL text.
10741105 sciEdit->setTextInMargin (Settings::getValue (" databrowser" , " null_text" ).toString ());
@@ -1080,25 +1111,22 @@ void EditDialog::updateCellInfoAndMode(const QByteArray& bArrdata)
10801111 // Text only
10811112 // Determine the length of the cell text in characters (possibly different to number of bytes).
10821113 int textLength = QString (cellData).length ();
1083- ui->labelType ->setText (tr (" Type of data currently in cell: Text / Numeric" ));
1084- ui->labelSize ->setText (tr (" %n character(s)" , " " , textLength));
1114+ ui->labelInfo ->setText (tr (" Type: Text / Numeric; Size: %n character(s)" , " " , textLength));
10851115 break ;
10861116 }
10871117 case JSON: {
10881118 // Valid JSON
10891119 // Determine the length of the cell text in characters (possibly different to number of bytes).
10901120 int jsonLength = QString (cellData).length ();
1091- ui->labelType ->setText (tr (" Type of data currently in cell: Valid JSON" ));
1092- ui->labelSize ->setText (tr (" %n character(s)" , " " , jsonLength));
1121+ ui->labelInfo ->setText (tr (" Type: Valid JSON; Size: %n character(s)" , " " , jsonLength));
10931122 break ;
10941123 }
10951124 default :
10961125
10971126 // Determine the length of the cell data
10981127 int dataLength = cellData.length ();
10991128 // If none of the above data types, consider it general binary data
1100- ui->labelType ->setText (tr (" Type of data currently in cell: Binary" ));
1101- ui->labelSize ->setText (tr (" %n byte(s)" , " " , dataLength));
1129+ ui->labelInfo ->setText (tr (" Type: Binary; Size: %n byte(s)" , " " , dataLength));
11021130 break ;
11031131 }
11041132}
0 commit comments