34 #include <QMessageBox> 50 if ((
val.isnumeric () ||
val.islogical ()) &&
val.numel () == 1)
53 if (
val.is_string () && (
val.rows () == 1 ||
val.is_zero_by_zero ()))
62 if (
val.is_sq_string ())
65 if (
val.is_dq_string ())
76 return (
val.numel () > 250000
92 m_data_rows (m_value.rows ()),
93 m_data_cols (m_value.columns ()),
94 m_display_rows (m_data_rows),
95 m_display_cols (m_data_cols),
97 m_valid (m_value.is_defined ()),
113 if (! idx.isValid ())
168 if (role == Qt::DisplayRole)
194 if (role == Qt::DisplayRole)
207 if (idx.isValid () && role == Qt::DisplayRole &&
update_pending (idx))
212 if (role == Qt::DisplayRole)
213 return QVariant (QString (
"Variable %1 not found")
216 return QVariant (QString (
"x"));
221 case Qt::DisplayRole:
227 case Qt::StatusTipRole:
228 return elem (idx).m_status_tip;
230 case Qt::ToolTipRole:
231 return elem (idx).m_tool_tip;
233 case Qt::BackgroundRole:
234 return elem (idx).m_background;
282 if (role != Qt::DisplayRole)
301 if (! lbl_txt.isEmpty ())
313 lbl_txt +=
" [undefined]";
369 if (role == Qt::DisplayRole)
381 if (! idx.isValid ())
384 return (QString (
"(%1,%2)")
385 .arg (idx.row () + 1)
386 .
arg (idx.column () + 1));
499 if (! idx.isValid ())
502 return (QString (
"{%1,%2}")
503 .arg (idx.row () + 1)
504 .
arg (idx.column () + 1));
517 return cval(
row,col);
589 if (role != Qt::DisplayRole)
596 return QString (
"Values");
680 std::ostringstream buf;
691 return (QString (
"unable to edit %1")
772 if (role != Qt::DisplayRole)
804 if (! idx.isValid ())
811 return (QString (
"(%1).%2")
812 .
arg (idx.row () + 1)
911 return (QString (
"(%1,%2)")
935 if ((
val.isnumeric () ||
val.islogical ()) &&
val.ndims () == 2)
937 else if (
val.is_string () && (
val.rows () == 1 ||
val.is_zero_by_zero ()))
939 else if (
val.iscell ())
941 else if (
val.isstruct ())
943 if (
val.numel () == 1)
945 else if (
val.ndims () == 2)
947 if (
val.rows () == 1 ||
val.columns () == 1)
965 this, SLOT (
user_error (
const QString&,
const QString&)));
975 beginInsertRows (QModelIndex (), 0,
display_rows () - 1);
985 const QVariant& v_user_input,
int role)
987 if (role != Qt::EditRole || ! v_user_input.canConvert (QVariant::String)
993 QString user_input = v_user_input.toString ();
1000 if (user_input.isEmpty () && ! qc)
1005 std::ostringstream
os;
1011 os <<
tmp.toStdString () <<
"=";
1016 os << user_input.toStdString ();
1023 octave_link::post_event<variable_editor_model, std::string, std::string, QModelIndex>
1032 int row = idx.row ();
1033 int col = idx.column ();
1036 return setData (idx, QVariant (
"0"));
1045 return Qt::NoItemFlags;
1047 Qt::ItemFlags
retval = QAbstractTableModel::flags (idx);
1050 retval |= Qt::ItemIsEditable;
1060 octave_link::post_event <variable_editor_model, std::string, std::string>
1062 QString (
"%1 = [ %1(1:%2,:) ; zeros(%3, columns(%1)) ; %1(%2+%3:end,:) ]")
1076 qDebug () <<
"Tried to remove too many rows " 1078 << count <<
" (" <<
row <<
")";
1082 octave_link::post_event <variable_editor_model, std::string, std::string>
1084 QString (
"%1(%2:%3, :) = []")
1096 octave_link::post_event <variable_editor_model, std::string, std::string>
1098 QString (
"%1 = [ %1(:,1:%2) ; zeros(rows(%1), %3) %1(:,%2+%3:end) ]")
1112 qDebug () <<
"Tried to remove too many cols " 1114 << count <<
" (" << col <<
")";
1118 octave_link::post_event <variable_editor_model, std::string, std::string>
1120 QString (
"%1(:, %2:%3) = []")
1132 const QModelIndex& idx)
1138 int parse_status = 0;
1155 emit dataChanged (idx, idx);
1172 QString msg = (QString (
"variable '%1' is invalid or undefined")
1187 int parse_status = 0;
1216 if (
name.back () ==
')' ||
name.back () ==
'}')
1221 int parse_status = 0;
1233 QString (
"failed to evaluate expression: '%1'")
1240 QMessageBox::critical (
nullptr, title, msg);
1253 if (
val.is_undefined ())
1255 QString msg = (QString (
"variable '%1' is invalid or undefined")
1273 if (new_rows != old_rows || new_cols != old_cols)
1279 emit dataChanged (QAbstractTableModel::index (0, 0),
1280 QAbstractTableModel::index (new_rows-1, new_cols-1));
1287 int new_rows,
int new_cols)
1289 if (new_rows < old_rows)
1291 beginRemoveRows (QModelIndex (), new_rows, old_rows-1);
1294 else if (new_rows > old_rows)
1296 beginInsertRows (QModelIndex (), old_rows, new_rows-1);
1300 if (new_cols < old_cols)
1302 beginRemoveColumns (QModelIndex (), new_cols, old_cols-1);
1303 endRemoveColumns ();
1305 else if (new_cols > old_cols)
1307 beginInsertColumns (QModelIndex (), old_cols, new_cols-1);
1308 endInsertColumns ();
1323 if (new_rows != old_rows)
1338 if (new_cols != old_cols)
bool requires_sub_editor(const QModelIndex &idx) const
~vector_struct_model(void)=default
string_vector fieldnames(void) const
string_model(const QString &expr, const octave_value &val)
void update_data_signal(const octave_value &val)
void eval_oct(const std::string &name, const std::string &expr)
std::string str(char sep='x') const
cell_model(const QString &expr, const octave_value &val)
scalar structure containing the fields
scalar_struct_model(const QString &expr, const octave_value &val)
void set_editable_signal(bool)
void clear_update_pending(void)
void description_changed(const QString &description)
octave_value value_at(const QModelIndex &idx) const
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
QVariant edit_display(const QModelIndex &idx, int) const
void update_data_cache(void)
void double_click(const QModelIndex &idx)
QString subscript_expression(const QModelIndex &idx) const
char quote_char(const QModelIndex &idx) const
void data_error_signal(const QString &name) const
octave_idx_type data_columns(void) const
virtual QString make_description_text(void) const
bool is_editable(void) const
bool islogical(void) const
octave_map map_value(void) const
string_vector fieldnames(void) const
void print_with_name(std::ostream &os, const std::string &name) const
variable_editor_model(const QString &expr, const octave_value &val, QObject *parent=nullptr)
int columnCount(const QModelIndex &=QModelIndex()) const
QString subscript_expression(const QModelIndex &idx) const
identity matrix If supplied two scalar respectively For allows like xample val
~cell_model(void)=default
char quote_char(const QModelIndex &idx) const
bool clear_content(const QModelIndex &idx)
for fields that display a single number
bool index_ok(const QModelIndex &idx, int &row, int &col) const
QVariant edit_display(const QModelIndex &, int) const
static bool cell_is_editable(const octave_value &val)
virtual QVariant header_data(int section, Qt::Orientation orientation, int role) const
bool setData(const QModelIndex &idx, const QVariant &v, int role=Qt::EditRole)
bool requires_sub_editor(const QModelIndex &idx) const
void maybe_resize_rows(int rows)
base_ve_model(const QString &expr, const octave_value &val)
void maybe_resize_columns(int cols)
QString edit_display_sub(const octave_value &elt, int role) const
QString fromStdString(const std::string &s)
bool requires_sub_editor(const QModelIndex &idx) const
char quote_char(const QModelIndex &idx) const
~numeric_model(void)=default
display_only_model & operator=(const display_only_model &)=delete
~display_only_model(void)=default
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
bool is_defined(void) const
QMap< QModelIndex, QString > m_update_pending
octave_idx_type m_data_rows
bool requires_sub_editor(const QModelIndex &idx) const
QString make_description_text(void) const
virtual void maybe_resize_columns(int)
void edit_variable_signal(const QString &name, const octave_value &val)
QString subscript_expression(const QModelIndex &idx) const
QString subscript_expression(const QModelIndex &idx) const
char quote_char(const QModelIndex &) const
numeric_model & operator=(const numeric_model &)=delete
static char get_quote_char(const octave_value &val)
void clear_update_pending(void)
numeric_model(const QString &expr, const octave_value &val)
string_model & operator=(const string_model &)=delete
display_only_model(const QString &expr, const octave_value &val)
void set_update_pending(const QModelIndex &idx, const QString &str)
void init_from_oct(const std::string &str)
bool update_pending(const QModelIndex &idx) const
void set_data_oct(const std::string &name, const std::string &expr, const QModelIndex &)
octave_idx_type m_data_cols
virtual char quote_char(const QModelIndex &idx) const
nd deftypefn *std::string name
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
void user_error(const QString &title, const QString &msg)
virtual octave_value value_at(const QModelIndex &idx) const
void change_display_size(int old_rows, int old_cols, int new_rows, int new_cols)
scalar_struct_model & operator=(const scalar_struct_model &)=delete
OCTINTERP_API octave_value_list eval_string(const std::string &, bool silent, int &parse_status, int nargout)
octave_idx_type numel(const octave_value_list &idx)
static base_ve_model * create(const QString &expr, const octave_value &val)
float_display_format m_display_fmt
octave_value value_at(const QModelIndex &idx) const
void maybe_resize_columns(int cols)
octave_idx_type data_rows(void) const
octave_value value_at(const QModelIndex &idx) const
QString update_pending_data(const QModelIndex &idx) const
bool is_single_type(void) const
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
char quote_char(const QModelIndex &idx) const
dim_vector dims(void) const
void maybe_resize_rows(int rows)
QVariant header_data(int section, Qt::Orientation orientation, int role) const
octave_idx_type rows(void) const
int column_width(void) const
QVariant edit_display(const QModelIndex &idx, int role) const
static void post_event(T *obj, void(T::*method)(void))
vector_struct_model(const QString &expr, const octave_value &val)
const Cell & contents(const_iterator p) const
virtual void maybe_resize_rows(int)
QVariant header_data(int section, Qt::Orientation orientation, int role) const
QVariant edit_display(const QModelIndex &, int) const
std::string class_name(void) const
Qt::ItemFlags flags(const QModelIndex &idx) const
static bool do_requires_sub_editor_sub(const octave_value &elt)
octave_value value_at(const QModelIndex &idx) const
void maybe_resize_rows(int rows)
octave_idx_type data_rows(void) const
void set_update_pending(const QModelIndex &idx, const QString &str)
~scalar_struct_model(void)=default
cell_model & operator=(const cell_model &)=delete
struct_model(const QString &expr, const octave_value &val)
QString subscript_expression(const QModelIndex &idx) const
int display_columns(void) const
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
int display_rows(void) const
octave_scalar_map scalar_map_value(void) const
octave_value value_at(const QModelIndex &idx) const
void evaluation_error(const std::string &expr) const
const octave_value & contents(const_iterator p) const
QVariant edit_display(const QModelIndex &idx, int role) const
bool is_undefined(void) const
static int symbol_exist(octave::interpreter &interp, const std::string &name, const std::string &type="any")
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
int rowCount(const QModelIndex &=QModelIndex()) const
bool requires_sub_editor(const QModelIndex &idx) const
octave_idx_type data_columns(void) const
QString make_description_text(void) const
virtual bool requires_sub_editor(const QModelIndex &idx) const
QString subscript_expression(const QModelIndex &idx) const
void maybe_resize_columns(int cols)
void update_data(const octave_value &val)
bool iscomplex(void) const
QVariant edit_display(const QModelIndex &idx, int role) const
std::string name(void) const
octave_value retrieve_variable(const std::string &name)
bool is_string(void) const
void maybe_resize_rows(int rows)
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
QVariant edit_display(const QModelIndex &idx, int role) const
bool is_editable(void) const
~struct_model(void)=default
void user_error_signal(const QString &title, const QString &msg) const
virtual QString subscript_expression(const QModelIndex &idx) const
char quote_char(const QModelIndex &idx) const
struct_model & operator=(const struct_model &)=delete
Vector representing the dimensions (size) of an Array.
std::string toStdString(const QString &s)
bool is_valid(void) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
~string_model(void)=default
void update_description(const QString &description=QString())
Cell cell_value(void) const
bool isnumeric(void) const
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
void maybe_resize_rows(int rows)
void data_error(const QString &msg)
void reset(const octave_value &val)
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
void maybe_resize_columns(int cols)
vector_struct_model & operator=(const vector_struct_model &)=delete
std::string name(void) const
virtual QVariant edit_display(const QModelIndex &idx, int role) const
static float_display_format get_edit_display_format(const octave_value &val)