@@ -90,28 +90,39 @@ void EditDialog::loadText(const QByteArray& data, int row, int col)
9090 curCol = col;
9191 oldData = data;
9292
93- // Load data
94- QString textData = QString::fromUtf8 (data.constData (), data.size ());
95- ui->editorText ->setPlainText (textData);
93+ // Always load the data into the hex editor, as other methods in this class
94+ // rely on it being there
9695 hexEdit->setData (data);
9796
97+ // Get the current editor mode (eg text, hex, or image mode)
98+ int editMode = ui->editorStack ->currentIndex ();
99+
100+ // Only load the data into the text editor if that's the active edit mode
101+ if (editMode == 0 ) {
102+ QString textData = QString::fromUtf8 (data.constData (), data.size ());
103+ ui->editorText ->setPlainText (textData);
104+ }
105+
98106 // Determine the data type in the cell
99107 int dataType = checkDataType ();
100108
101109 // Do some data type specific handling
102110 QImage img;
103111 switch (dataType) {
104112 case Text:
105- // For text, ensure it's all selected in the Edit Cell
106- ui->editorText ->selectAll ();
113+ // If in text editor mode, select all of the text by default
114+ if (editMode == 0 ) {
115+
116+ ui->editorText ->selectAll ();
117+ }
107118
108119 // Clear any image from the image viewing widget
109120 ui->editorImage ->setPixmap (QPixmap (0 ,0 ));
110121 break ;
111122
112123 case Image:
113124 // For images, load the image into the image viewing widget
114- if (img.loadFromData (hexEdit-> data () )) {
125+ if (img.loadFromData (data)) {
115126 ui->editorImage ->setPixmap (QPixmap::fromImage (img));
116127 }
117128 break ;
@@ -122,9 +133,6 @@ void EditDialog::loadText(const QByteArray& data, int row, int col)
122133 break ;
123134 }
124135
125- // Get the current editor mode (eg text, hex, or image mode)
126- int editMode = ui->editorStack ->currentIndex ();
127-
128136 // Show or hide the warning about editing binary data in text mode
129137 updateBinaryEditWarning (editMode, dataType);
130138
@@ -210,6 +218,13 @@ void EditDialog::accept()
210218// Called when the user manually changes the "Mode" drop down combobox
211219void EditDialog::editModeChanged (int editMode)
212220{
221+ // If the new editor mode is "text editor", load the data into it
222+ if (editMode == 0 ) {
223+ QByteArray data = hexEdit->data ();
224+ QString textData = QString::fromUtf8 (data, data.size ());
225+ ui->editorText ->setPlainText (textData);
226+ }
227+
213228 // Switch to the selected editor
214229 ui->editorStack ->setCurrentIndex (editMode);
215230
0 commit comments