Mercurial > octave
comparison libgui/src/variable-editor-model.cc @ 27247:9e5a825bb966
replace more explicit callback functions with lambda expressions
* Canvas.h, Canvas.cc (Canvas::annotation_callback): Delete.
Replace uses of callback functions with equivalent lambda expressions
in calls to octave_link::post_event.
* file-editor-tab.h, file-editor-tab.cc
(file_editor_tab::add_breakpoint_event): New function.
(file_editor_tab::add_breakpoint_callback,
file_editor_tab::remove_breakpoint_callback,
file_editor_tab::remove_all_breakpoints_callback): Delete.
Replace uses of callback functions with equivalent lambda expressions
in calls to octave_link::post_event. Use add_breakpoint_event to
consolidate the calls to post_event for this action to a single function.
* variable-editor-model.h, variable-editor-model.cc
(variable_editor_model::eval_expr_event): New function.
(variable_editor_model::init_from_oct): Eliminate unnecessary function
parameter.
(variable_editor_model::set_data_oct,
variable_editor_model::eval_oct): Delete.
Replace uses of callback functions with equivalent lambda expressions
in calls to octave_link::post_event. Use eval_expr_event to
consolidate the calls to post_event for this action to a single
function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 12 Jul 2019 19:26:55 -0400 |
parents | 2d9decd77e58 |
children | dccdc3b001a2 |
comparison
equal
deleted
inserted
replaced
27246:7c778a102de8 | 27247:9e5a825bb966 |
---|---|
1011 os << qc; | 1011 os << qc; |
1012 | 1012 |
1013 std::string expr = os.str (); | 1013 std::string expr = os.str (); |
1014 | 1014 |
1015 octave_link::post_event | 1015 octave_link::post_event |
1016 (this, &variable_editor_model::set_data_oct, nm, expr, idx); | 1016 ([this, nm, expr, idx] (void) |
1017 { | |
1018 // INTERPRETER THREAD | |
1019 | |
1020 try | |
1021 { | |
1022 interpreter& interp | |
1023 = __get_interpreter__ ("variable_editor_model::setData"); | |
1024 | |
1025 int parse_status = 0; | |
1026 interp.eval_string (expr, true, parse_status); | |
1027 | |
1028 octave_value val = retrieve_variable (nm); | |
1029 | |
1030 emit update_data_signal (val); | |
1031 } | |
1032 catch (execution_exception&) | |
1033 { | |
1034 clear_update_pending (); | |
1035 | |
1036 evaluation_error (expr); | |
1037 | |
1038 // This will cause the data in the cell to be reset | |
1039 // from the cached octave_value object. | |
1040 | |
1041 emit dataChanged (idx, idx); | |
1042 } | |
1043 }); | |
1017 | 1044 |
1018 return true; | 1045 return true; |
1019 } | 1046 } |
1020 | 1047 |
1021 bool | 1048 bool |
1047 bool | 1074 bool |
1048 variable_editor_model::insertRows (int row, int count, const QModelIndex&) | 1075 variable_editor_model::insertRows (int row, int count, const QModelIndex&) |
1049 { | 1076 { |
1050 // FIXME: cells? | 1077 // FIXME: cells? |
1051 | 1078 |
1052 octave_link::post_event | 1079 eval_expr_event |
1053 (this, &variable_editor_model::eval_oct, name (), | 1080 (QString ("%1 = [%1(1:%2,:); zeros(%3,columns(%1)); %1(%2+%3:end,:)]") |
1054 QString ("%1 = [ %1(1:%2,:) ; zeros(%3, columns(%1)) ; %1(%2+%3:end,:) ]") | |
1055 .arg (QString::fromStdString (name ())) | 1081 .arg (QString::fromStdString (name ())) |
1056 .arg (row) | 1082 .arg (row) |
1057 .arg (count) | 1083 .arg (count)); |
1058 .toStdString ()); | |
1059 | 1084 |
1060 return true; | 1085 return true; |
1061 } | 1086 } |
1062 | 1087 |
1063 bool | 1088 bool |
1069 << data_rows () << " " | 1094 << data_rows () << " " |
1070 << count << " (" << row << ")"; | 1095 << count << " (" << row << ")"; |
1071 return false; | 1096 return false; |
1072 } | 1097 } |
1073 | 1098 |
1074 octave_link::post_event | 1099 eval_expr_event |
1075 (this, &variable_editor_model::eval_oct, name (), | 1100 (QString ("%1(%2:%3,:) = []") |
1076 QString ("%1(%2:%3, :) = []") | |
1077 .arg (QString::fromStdString (name ())) | 1101 .arg (QString::fromStdString (name ())) |
1078 .arg (row) | 1102 .arg (row) |
1079 .arg (row + count) | 1103 .arg (row + count)); |
1080 .toStdString ()); | |
1081 | 1104 |
1082 return true; | 1105 return true; |
1083 } | 1106 } |
1084 | 1107 |
1085 bool | 1108 bool |
1086 variable_editor_model::insertColumns (int col, int count, const QModelIndex&) | 1109 variable_editor_model::insertColumns (int col, int count, const QModelIndex&) |
1087 { | 1110 { |
1088 octave_link::post_event | 1111 eval_expr_event |
1089 (this, &variable_editor_model::eval_oct, name (), | 1112 (QString ("%1 = [%1(:,1:%2); zeros(rows(%1),%3) %1(:,%2+%3:end)]") |
1090 QString ("%1 = [ %1(:,1:%2) ; zeros(rows(%1), %3) %1(:,%2+%3:end) ]") | |
1091 .arg (QString::fromStdString (name ())) | 1113 .arg (QString::fromStdString (name ())) |
1092 .arg (col) | 1114 .arg (col) |
1093 .arg (count) | 1115 .arg (count)); |
1094 .toStdString ()); | |
1095 | 1116 |
1096 return true; | 1117 return true; |
1097 } | 1118 } |
1098 | 1119 |
1099 bool | 1120 bool |
1105 << data_columns () << " " | 1126 << data_columns () << " " |
1106 << count << " (" << col << ")"; | 1127 << count << " (" << col << ")"; |
1107 return false; | 1128 return false; |
1108 } | 1129 } |
1109 | 1130 |
1110 octave_link::post_event | 1131 eval_expr_event |
1111 (this, &variable_editor_model::eval_oct, name (), | 1132 (QString ("%1(:,%2:%3) = []") |
1112 QString ("%1(:, %2:%3) = []") | |
1113 .arg (QString::fromStdString (name ())) | 1133 .arg (QString::fromStdString (name ())) |
1114 .arg (col) | 1134 .arg (col) |
1115 .arg (col + count) | 1135 .arg (col + count)); |
1116 .toStdString ()); | |
1117 | 1136 |
1118 return true; | 1137 return true; |
1119 } | 1138 } |
1120 | 1139 |
1121 void | 1140 void |
1122 variable_editor_model::set_data_oct (const std::string& name, | 1141 variable_editor_model::init_from_oct (void) |
1123 const std::string& expr, | |
1124 const QModelIndex& idx) | |
1125 { | 1142 { |
1126 // INTERPRETER THREAD | 1143 // INTERPRETER THREAD |
1127 | 1144 |
1145 std::string nm = name (); | |
1146 | |
1128 try | 1147 try |
1129 { | 1148 { |
1130 interpreter& interp | 1149 octave_value val = retrieve_variable (nm); |
1131 = __get_interpreter__ ("variable_editor_model::set_data_oct"); | |
1132 | |
1133 int parse_status = 0; | |
1134 interp.eval_string (expr, true, parse_status); | |
1135 | |
1136 octave_value val = retrieve_variable (name); | |
1137 | 1150 |
1138 emit update_data_signal (val); | 1151 emit update_data_signal (val); |
1139 } | 1152 } |
1140 catch (execution_exception&) | 1153 catch (execution_exception&) |
1141 { | 1154 { |
1142 clear_update_pending (); | |
1143 | |
1144 evaluation_error (expr); | |
1145 | |
1146 // This will cause the data in the cell to be reset | |
1147 // from the cached octave_value object. | |
1148 | |
1149 emit dataChanged (idx, idx); | |
1150 } | |
1151 } | |
1152 | |
1153 void | |
1154 variable_editor_model::init_from_oct (const std::string& name) | |
1155 { | |
1156 // INTERPRETER THREAD | |
1157 | |
1158 try | |
1159 { | |
1160 octave_value val = retrieve_variable (name); | |
1161 | |
1162 emit update_data_signal (val); | |
1163 } | |
1164 catch (execution_exception&) | |
1165 { | |
1166 QString msg = (QString ("variable '%1' is invalid or undefined") | 1155 QString msg = (QString ("variable '%1' is invalid or undefined") |
1167 .arg (QString::fromStdString (name))); | 1156 .arg (QString::fromStdString (nm))); |
1168 | 1157 |
1169 emit data_error_signal (msg); | 1158 emit data_error_signal (msg); |
1170 } | 1159 } |
1171 } | 1160 } |
1172 | 1161 |
1173 void | 1162 void |
1174 variable_editor_model::eval_oct (const std::string& name, | 1163 variable_editor_model::eval_expr_event (const QString& expr_arg) |
1175 const std::string& expr) | 1164 { |
1176 { | 1165 std::string expr = expr_arg.toStdString (); |
1177 // INTERPRETER THREAD | 1166 |
1178 | 1167 octave_link::post_event |
1179 try | 1168 ([this, expr] (void) |
1180 { | 1169 { |
1181 interpreter& interp | 1170 // INTERPRETER THREAD |
1182 = __get_interpreter__ ("variable_editor_model::eval_oct"); | 1171 |
1183 | 1172 try |
1184 int parse_status = 0; | 1173 { |
1185 interp.eval_string (expr, true, parse_status); | 1174 interpreter& interp |
1186 | 1175 = __get_interpreter__ ("variable_editor_model::eval_expr_event"); |
1187 init_from_oct (name); | 1176 |
1188 } | 1177 int parse_status = 0; |
1189 catch (execution_exception&) | 1178 interp.eval_string (expr, true, parse_status); |
1190 { | 1179 |
1191 evaluation_error (expr); | 1180 init_from_oct (); |
1192 } | 1181 } |
1182 catch (execution_exception&) | |
1183 { | |
1184 evaluation_error (expr); | |
1185 } | |
1186 }); | |
1193 } | 1187 } |
1194 | 1188 |
1195 // If the variable exists, load it into the data model. If it doesn't | 1189 // If the variable exists, load it into the data model. If it doesn't |
1196 // exist, flag the data model as referring to a nonexistent variable. | 1190 // exist, flag the data model as referring to a nonexistent variable. |
1197 // This allows the variable to be opened before it is created. | 1191 // This allows the variable to be opened before it is created. |
1240 | 1234 |
1241 void | 1235 void |
1242 variable_editor_model::update_data_cache (void) | 1236 variable_editor_model::update_data_cache (void) |
1243 { | 1237 { |
1244 octave_link::post_event | 1238 octave_link::post_event |
1245 (this, &variable_editor_model::init_from_oct, name ()); | 1239 ([this] (void) |
1240 { | |
1241 // INTERPRETER_THREAD | |
1242 | |
1243 init_from_oct (); | |
1244 }); | |
1246 } | 1245 } |
1247 | 1246 |
1248 void | 1247 void |
1249 variable_editor_model::update_data (const octave_value& val) | 1248 variable_editor_model::update_data (const octave_value& val) |
1250 { | 1249 { |