2021-02-05 Fred Gleason <fredg@paravelsystems.com>

* Added 'RDMacroCartModel'
	* Refactored the macro cart editor dialog in rdlibrary(1) to use the
	model-based API.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-02-05 15:44:43 -05:00
parent 5e1205cda4
commit e6eededea4
23 changed files with 556 additions and 293 deletions

View File

@ -21009,3 +21009,7 @@
2021-02-05 Fred Gleason <fredg@paravelsystems.com>
* Refactored the CD track ripper in rdlibrary(1) to use the
model-based API.
2021-02-05 Fred Gleason <fredg@paravelsystems.com>
* Added 'RDMacroCartModel'
* Refactored the macro cart editor dialog in rdlibrary(1) to use the
model-based API.

View File

@ -187,6 +187,7 @@ dist_librd_la_SOURCES = dbversion.h\
rdlogplay.cpp rdlogplay.h\
rdmacro.cpp rdmacro.h\
rdmacro_event.cpp rdmacro_event.h\
rdmacrocartmodel.cpp rdmacrocartmodel.h\
rdmarker_bar.cpp rdmarker_bar.h\
rdmarker_button.cpp rdmarker_button.h\
rdmarker_edit.cpp rdmarker_edit.h\
@ -361,6 +362,7 @@ nodist_librd_la_SOURCES = moc_rd3emptycart.cpp\
moc_rdlogmodel.cpp\
moc_rdlogplay.cpp\
moc_rdmacro_event.cpp\
moc_rdmacrocartmodel.cpp\
moc_rdmarker_bar.cpp\
moc_rdmarker_edit.cpp\
moc_rdmatrixlistmodel.cpp\

View File

@ -141,6 +141,7 @@ SOURCES += rdlogmodel.cpp
SOURCES += rdlogplay.cpp
SOURCES += rdmacro.cpp
SOURCES += rdmacro_event.cpp
SOURCES += rdmacrocartmodel.cpp
SOURCES += rdmarker_button.cpp
SOURCES += rdmarker_edit.cpp
SOURCES += rdmatrix.cpp
@ -316,6 +317,7 @@ HEADERS += rdlogmodel.h
HEADERS += rdlogplay.h
HEADERS += rdmacro.h
HEADERS += rdmacro_event.h
HEADERS += rdmacrocartmodel.h
HEADERS += rdmarker_button.h
HEADERS += rdmarker_edit.h
HEADERS += rdmatrix.h

View File

@ -3406,6 +3406,21 @@ Bitte Kofiguration prüfen und erneut versuchen.</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMacroCartModel</name>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMatrixListModel</name>
<message>

View File

@ -3395,6 +3395,21 @@ Bitte Kofiguration prüfen und erneut versuchen.</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMacroCartModel</name>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMatrixListModel</name>
<message>

View File

@ -3382,6 +3382,21 @@ Do you still want to proceed?</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMacroCartModel</name>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMatrixListModel</name>
<message>

View File

@ -2810,6 +2810,21 @@ Do you want to overwrite it?</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMacroCartModel</name>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMatrixListModel</name>
<message>

View File

@ -3349,6 +3349,21 @@ Sjekk eksportoppsettet ditt og prøv att.</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMacroCartModel</name>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMatrixListModel</name>
<message>

View File

@ -3349,6 +3349,21 @@ Sjekk eksportoppsettet ditt og prøv att.</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMacroCartModel</name>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMatrixListModel</name>
<message>

View File

@ -3384,6 +3384,21 @@ Por Favor, cheque suas configurações e tenbte outra vez.</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMacroCartModel</name>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDMatrixListModel</name>
<message>

View File

@ -0,0 +1,249 @@
// rdmacrocartmodel.cpp
//
// Data model for Rivendell services
//
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include "rdapplication.h"
#include "rdescape_string.h"
#include "rdmacrocartmodel.h"
RDMacroCartModel::RDMacroCartModel(unsigned cartnum,QObject *parent)
: QAbstractTableModel(parent)
{
d_cart_number=cartnum;
//
// Column Attributes
//
unsigned left=Qt::AlignLeft|Qt::AlignVCenter;
// unsigned center=Qt::AlignCenter;
unsigned right=Qt::AlignRight|Qt::AlignVCenter;
d_headers.push_back(tr("Line"));
d_alignments.push_back(right);
d_headers.push_back(tr("Command"));
d_alignments.push_back(left);
updateModel();
}
RDMacroCartModel::~RDMacroCartModel()
{
}
QPalette RDMacroCartModel::palette()
{
return d_palette;
}
void RDMacroCartModel::setPalette(const QPalette &pal)
{
d_palette=pal;
}
void RDMacroCartModel::setFont(const QFont &font)
{
d_font=font;
d_bold_font=font;
d_bold_font.setWeight(QFont::Bold);
}
int RDMacroCartModel::columnCount(const QModelIndex &parent) const
{
return d_headers.size();
}
int RDMacroCartModel::rowCount(const QModelIndex &parent) const
{
return d_texts.size();
}
QVariant RDMacroCartModel::headerData(int section,Qt::Orientation orient,
int role) const
{
if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) {
return d_headers.at(section);
}
return QVariant();
}
QVariant RDMacroCartModel::data(const QModelIndex &index,int role) const
{
QString str;
int col=index.column();
int row=index.row();
if(row<d_texts.size()) {
switch((Qt::ItemDataRole)role) {
case Qt::DisplayRole:
return d_texts.at(row).at(col);
case Qt::DecorationRole:
// Nothing to do!
break;
case Qt::TextAlignmentRole:
return d_alignments.at(col);
case Qt::FontRole:
if(col==0) {
return d_bold_font;
}
return d_font;
case Qt::TextColorRole:
// Nothing to do!
break;
case Qt::BackgroundRole:
// Nothing to do!
break;
default:
break;
}
}
return QVariant();
}
unsigned RDMacroCartModel::cartNumber() const
{
return d_cart_number;
}
int RDMacroCartModel::lineCount() const
{
return rowCount()-1;
}
bool RDMacroCartModel::isEndHandle(const QModelIndex &row) const
{
return row.row()==lineCount();
}
QString RDMacroCartModel::code(const QModelIndex &row) const
{
return d_texts.at(row.row()).at(1).toString();
}
QString RDMacroCartModel::allCode() const
{
QString macro;
for(int i=0;i<lineCount();i++) {
macro+=d_texts.at(i).at(1).toString();
}
return macro;
}
QModelIndex RDMacroCartModel::addLine(const QModelIndex &row,const QString &rml)
{
//
// Find the insertion offset
//
int offset=row.row();
beginInsertRows(QModelIndex(),offset,offset);
QList<QVariant> list;
for(int i=0;i<columnCount();i++) {
list.push_back(QVariant());
}
list[0]=QString().sprintf("%d",offset+1);
list[1]=rml;
d_texts.insert(offset,list);
endInsertRows();
return createIndex(offset,0);
}
void RDMacroCartModel::removeLine(const QModelIndex &row)
{
beginRemoveRows(QModelIndex(),row.row(),row.row());
d_texts.removeAt(row.row());
endRemoveRows();
}
void RDMacroCartModel::refresh(const QModelIndex &row,const QString &rml)
{
if(row.row()<d_texts.size()) {
d_texts[row.row()][1]=rml;
emit dataChanged(createIndex(row.row(),1),createIndex(row.row(),1));
}
}
void RDMacroCartModel::save() const
{
/*
QString macro;
for(int i=0;i<lineCount();i++) {
macro+=d_texts.at(i).at(1).toString();
}
*/
QString sql=QString("update CART set ")+
"MACROS=\""+RDEscapeString(allCode())+"\" where "+
QString().sprintf("NUMBER=%u",d_cart_number);
RDSqlQuery::apply(sql);
}
void RDMacroCartModel::updateModel()
{
QList<QVariant> texts;
for(int i=0;i<columnCount();i++) {
texts.push_back(QVariant());
}
QString sql=QString("select ")+
"MACROS "+ // 00
"from CART where "+
QString().sprintf("NUMBER=%u",d_cart_number);
beginResetModel();
d_texts.clear();
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
QStringList f0=q->value(0).toString().split("!",QString::SkipEmptyParts);
for(int i=0;i<f0.size();i++) {
d_texts.push_back(texts);
d_texts.back()[0]=QString().sprintf("%d",i+1);
d_texts.back()[1]=f0.at(i)+"!";
}
}
delete q;
d_texts.push_back(texts);
d_texts.back()[1]=tr("--- End of Cart ---");
endResetModel();
}

View File

@ -0,0 +1,71 @@
// rdmacrocartmodel.h
//
// Data model for Rivendell macro cart contents
//
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef RDMACROCARTMODEL_H
#define RDMACROCARTMODEL_H
#include <QAbstractTableModel>
#include <QFont>
#include <QList>
#include <QPalette>
#include <rddb.h>
#include <rdnotification.h>
class RDMacroCartModel : public QAbstractTableModel
{
Q_OBJECT
public:
RDMacroCartModel(unsigned cartnum,QObject *parent=0);
~RDMacroCartModel();
QPalette palette();
void setPalette(const QPalette &pal);
void setFont(const QFont &font);
int columnCount(const QModelIndex &parent=QModelIndex()) const;
int rowCount(const QModelIndex &parent=QModelIndex()) const;
QVariant headerData(int section,Qt::Orientation orient,
int role=Qt::DisplayRole) const;
QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const;
unsigned cartNumber() const;
int lineCount() const;
bool isEndHandle(const QModelIndex &row) const;
QString code(const QModelIndex &row) const;
QString allCode() const;
QModelIndex addLine(const QModelIndex &row,const QString &rml);
void removeLine(const QModelIndex &row);
void refresh(const QModelIndex &row,const QString &rml);
void save() const;
protected:
void updateModel();
private:
QPalette d_palette;
QFont d_font;
QFont d_bold_font;
QList<QVariant> d_headers;
QList<QVariant> d_alignments;
QList<QList<QVariant> > d_texts;
unsigned d_cart_number;
};
#endif // RDMACROCARTMODEL_H

View File

@ -2,7 +2,7 @@
//
// Edit a Rivendell Macro
//
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -18,26 +18,23 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qpushbutton.h>
#include <QPushButton>
#include "edit_macro.h"
EditMacro::EditMacro(RDMacro *cmd,bool highlight,QWidget *parent)
EditMacro::EditMacro(QWidget *parent)
: RDDialog(parent)
{
setModal(true);
//
// Fix the Window Size
//
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
setMaximumHeight(sizeHint().height());
setWindowTitle("RDLibrary - Edit Macro");
//
// Macro
//
edit_macro=cmd;
edit_macro_edit=new QLineEdit(this);
edit_macro_edit->setMaxLength(RD_RML_MAX_LENGTH-1);
@ -57,11 +54,6 @@ EditMacro::EditMacro(RDMacro *cmd,bool highlight,QWidget *parent)
edit_cancel_button->setFont(buttonFont());
edit_cancel_button->setText(tr("&Cancel"));
connect(edit_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
edit_macro_edit->setText(edit_macro->toString());
if(highlight) {
edit_macro_edit->selectAll();
}
}
@ -77,16 +69,29 @@ QSizePolicy EditMacro::sizePolicy() const
}
int EditMacro::exec(QString *code,bool highlight)
{
edit_code=code;
edit_macro_edit->setText(*code);
if(highlight) {
edit_macro_edit->selectAll();
}
return QDialog::exec();
}
void EditMacro::okData()
{
*edit_macro=RDMacro::fromString(edit_macro_edit->text());
done(0);
*edit_code=edit_macro_edit->text();
done(true);
}
void EditMacro::cancelData()
{
done(-1);
done(false);
}
@ -99,6 +104,7 @@ void EditMacro::closeEvent(QCloseEvent *e)
void EditMacro::resizeEvent(QResizeEvent *e)
{
edit_macro_edit->setGeometry(10,11,size().width()-20,19);
edit_ok_button->setGeometry(size().width()-180,size().height()-60,80,50);
edit_cancel_button->setGeometry(size().width()-90,size().height()-60,80,50);
}

View File

@ -2,7 +2,7 @@
//
// Edit a Rivendell Macro
//
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -21,7 +21,7 @@
#ifndef EDIT_MACRO_H
#define EDIT_MACRO_H
#include <qlineedit.h>
#include <QLineEdit>
#include <rddialog.h>
#include <rdmacro.h>
@ -30,10 +30,13 @@ class EditMacro : public RDDialog
{
Q_OBJECT
public:
EditMacro(RDMacro *cmd,bool highlight,QWidget *parent=0);
EditMacro(QWidget *parent=0);
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
public slots:
int exec(QString *code,bool highlight);
private slots:
void okData();
void cancelData();
@ -46,9 +49,8 @@ class EditMacro : public RDDialog
QLineEdit *edit_macro_edit;
QPushButton *edit_ok_button;
QPushButton *edit_cancel_button;
RDMacro *edit_macro;
QString *edit_code;
};
#endif
#endif // EDIT_MACRO_H

View File

@ -2,7 +2,7 @@
//
// The macro cart editor for RDLibrary.
//
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -31,10 +31,16 @@ MacroCart::MacroCart(RDCart *cart,QWidget *parent)
{
rdcart_length=0;
rdcart_cart=cart;
setCaption(QString().sprintf("%u",rdcart_cart->number())+" - "+
rdcart_cart->title());
rdcart_allow_modification=rda->user()->modifyCarts();
setWindowTitle(QString().sprintf("%u",rdcart_cart->number())+" - "+
rdcart_cart->title());
//
// Dialogs
//
rdcart_edit_macro_dialog=new EditMacro(this);
//
// Add Macro Button
//
@ -80,33 +86,26 @@ MacroCart::MacroCart(RDCart *cart,QWidget *parent)
// Cart Macro List
//
rdcart_events=new RDMacroEvent(rda->station()->address(),rda->ripc(),this);
rdcart_events->load(rdcart_cart->macros());
// rdcart_events->load(rdcart_cart->macros());
rdcart_macro_list=new Q3ListView(this);
rdcart_macro_list->setGeometry(100,0,430,sizeHint().height());
rdcart_macro_list->setAllColumnsShowFocus(true);
rdcart_macro_list->setItemMargin(5);
rdcart_macro_list->setSorting(-1);
connect(rdcart_macro_list,
SIGNAL(selectionChanged(Q3ListViewItem *)),
rdcart_macro_view=new RDTableView(this);
rdcart_macro_view->setSelectionMode(QAbstractItemView::SingleSelection);
rdcart_macro_view->setGeometry(100,0,430,sizeHint().height());
rdcart_macro_model=new RDMacroCartModel(cart->number(),this);
rdcart_macro_model->setFont(defaultFont());
rdcart_macro_model->setPalette(palette());
rdcart_macro_view->setModel(rdcart_macro_model);
connect(rdcart_macro_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(doubleClickedData(const QModelIndex &)));
connect(rdcart_macro_view->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &,
const QItemSelection &)),
this,
SLOT(selectionChangedData(Q3ListViewItem *)));
connect(rdcart_macro_list,
SIGNAL(doubleClicked(Q3ListViewItem *)),
this,
SLOT(doubleClickedData(Q3ListViewItem *)));
rdcart_macro_list->addColumn(tr("Line"));
rdcart_macro_list->setColumnAlignment(0,Qt::AlignHCenter);
rdcart_macro_list->addColumn(tr("Command"));
rdcart_macro_list->setColumnAlignment(1,Qt::AlignLeft);
rdcart_macro_list_label=new QLabel(rdcart_macro_list,tr("Macros"),this);
rdcart_macro_list_label->setGeometry(105,345,430,22);
rdcart_macro_list_label->setFont(progressFont());
RefreshList();
SLOT(selectionChangedData(const QItemSelection &,
const QItemSelection &)));
connect(rdcart_macro_model,SIGNAL(modelReset()),
rdcart_macro_view,SLOT(resizeColumnsToContents()));
rdcart_macro_view->resizeColumnsToContents();
//
// Edit Macro Button
@ -141,6 +140,12 @@ MacroCart::MacroCart(RDCart *cart,QWidget *parent)
}
MacroCart::~MacroCart()
{
delete rdcart_edit_macro_dialog;
}
QSize MacroCart::sizeHint() const
{
return QSize(640,290);
@ -161,116 +166,110 @@ unsigned MacroCart::length()
void MacroCart::save()
{
rdcart_cart->setMacros(rdcart_events->save());
rdcart_macro_model->save();
}
void MacroCart::addMacroData()
{
Q3ListViewItem *item=rdcart_macro_list->selectedItem();
RDMacro cmd;
unsigned line;
QString code;
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
if(item==NULL||item->text(0).isEmpty()) {
line=rdcart_events->size();
if((rows.size()!=1)||(!rdcart_allow_modification)) {
return;
}
else {
line=item->text(0).toUInt()-1;
}
EditMacro *edit=new EditMacro(&cmd,true,this);
if(edit->exec()!=-1) {
AddLine(line,&cmd);
if(rdcart_edit_macro_dialog->exec(&code,true)) {
rdcart_macro_model->addLine(rows.first(),code);
UpdateLength();
}
delete edit;
}
void MacroCart::deleteMacroData()
{
Q3ListViewItem *item=rdcart_macro_list->selectedItem();
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
if((item==NULL)||(item->text(0).isEmpty())) {
if((rows.size()!=1)||(!rdcart_allow_modification)) {
return;
}
DeleteLine(item);
rdcart_macro_model->removeLine(rows.first());
UpdateLength();
}
void MacroCart::copyMacroData()
{
Q3ListViewItem *item=rdcart_macro_list->selectedItem();
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
if((item==NULL)||(item->text(0).isEmpty())) {
if((rows.size()!=1)||(!rdcart_allow_modification)) {
return;
}
rdcart_clipboard=*rdcart_events->command(item->text(0).toUInt()-1);
rdcart_clipboard=rdcart_macro_model->code(rows.first());
paste_macro_button->setEnabled(rdcart_allow_modification);
}
void MacroCart::pasteMacroData()
{
Q3ListViewItem *item=rdcart_macro_list->selectedItem();
unsigned line;
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
if(item==NULL) {
if((rows.size()!=1)||(!rdcart_allow_modification)) {
return;
}
if(item->text(0).isEmpty()) {
line=rdcart_events->size();
QModelIndex row=
rdcart_macro_model->addLine(rows.first(),rdcart_clipboard);
if(row.isValid()) {
rdcart_macro_view->selectRow(row.row());
}
else {
line=item->text(0).toUInt()-1;
}
AddLine(line,&rdcart_clipboard);
UpdateLength();
}
void MacroCart::editMacroData()
{
Q3ListViewItem *item=rdcart_macro_list->selectedItem();
if((item==NULL)||(item->text(0).isEmpty())) {
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
if((rows.size()!=1)||(!rdcart_allow_modification)||
rdcart_macro_model->isEndHandle(rows.first())) {
return;
}
unsigned line=item->text(0).toUInt()-1;
EditMacro *edit=new EditMacro(rdcart_events->command(line),false,this);
if(edit->exec()!=-1) {
RefreshLine(item);
QString code=rdcart_macro_model->code(rows.first());
if(rdcart_edit_macro_dialog->exec(&code,false)) {
rdcart_macro_model->refresh(rows.first(),code);
UpdateLength();
}
delete edit;
}
void MacroCart::runLineMacroData()
{
Q3ListViewItem *item=rdcart_macro_list->selectedItem();
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
if((item==NULL)||(item->text(0).isEmpty())) {
if(rows.size()!=1) {
return;
}
unsigned line=item->text(0).toUInt()-1;
rdcart_events->exec(line);
rdcart_events->load(rdcart_macro_model->code(rows.first()));
rdcart_events->exec();
}
void MacroCart::runCartMacroData()
{
rdcart_events->load(rdcart_macro_model->allCode());
rdcart_events->exec();
}
void MacroCart::selectionChangedData(Q3ListViewItem *item)
void MacroCart::selectionChangedData(const QItemSelection &before,
const QItemSelection &after)
{
rdcart_add_button->setEnabled(rdcart_allow_modification);
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
rdcart_add_button->setEnabled((rows.size()==1)&&rdcart_allow_modification);
if(!rdcart_clipboard.isNull()) {
paste_macro_button->setEnabled(rdcart_allow_modification);
paste_macro_button->setEnabled((rows.size()==1)&&rdcart_allow_modification);
}
if(!item->text(0).isEmpty()) {
if((rows.size()>0)&&(!rdcart_macro_model->isEndHandle(rows.first()))) {
rdcart_runline_button->setEnabled(rdcart_allow_modification);
rdcart_delete_button->setEnabled(rdcart_allow_modification);
rdcart_copy_button->setEnabled(rdcart_allow_modification);
@ -285,10 +284,11 @@ void MacroCart::selectionChangedData(Q3ListViewItem *item)
}
void MacroCart::doubleClickedData(Q3ListViewItem *item)
void MacroCart::doubleClickedData(const QModelIndex &index)
{
if(rdcart_allow_modification) {
if((item==NULL)||(item->text(0).isEmpty())) {
QModelIndexList rows=rdcart_macro_view->selectionModel()->selectedRows();
if((rows.size()==1)&&rdcart_macro_model->isEndHandle(rows.first())) {
addMacroData();
}
else {
@ -298,97 +298,6 @@ void MacroCart::doubleClickedData(Q3ListViewItem *item)
}
void MacroCart::RefreshList()
{
Q3ListViewItem *item=NULL;
Q3ListViewItem *selected;
QString line;
selected=rdcart_macro_list->selectedItem();
if(selected!=NULL) {
line=selected->text(0);
}
rdcart_macro_list->clear();
for(int i=0;i<rdcart_events->size();i++) {
item=new Q3ListViewItem(rdcart_macro_list);
item->setText(0,QString().sprintf("%03d",i+1));
item->setText(1,rdcart_events->command(i)->toString());
}
SortLines();
if(item!=NULL) {
item=new Q3ListViewItem(rdcart_macro_list,item);
}
else {
item=new Q3ListViewItem(rdcart_macro_list);
}
item->setText(1,tr("--- End of Cart ---"));
if (!line.isEmpty()) {
selected=rdcart_macro_list->findItem(line,0);
if(selected!=NULL) {
rdcart_macro_list->setSelected(selected,true);
}
}
}
void MacroCart::RefreshLine(Q3ListViewItem *item)
{
int line=item->text(0).toInt()-1;
item->setText(1,rdcart_events->command(line)->toString());
}
void MacroCart::SortLines()
{
rdcart_macro_list->setSorting(0);
rdcart_macro_list->sort();
rdcart_macro_list->setSorting(-1);
}
void MacroCart::AddLine(unsigned line,RDMacro *cmd)
{
unsigned curr_line;
Q3ListViewItem *item=rdcart_macro_list->firstChild();
for(int i=0;i<rdcart_macro_list->childCount();i++) {
if(((curr_line=(item->text(0).toUInt()-1))>=line)&&
(!item->text(0).isEmpty())) {
item->setText(0,QString().sprintf("%03u",curr_line+2));
}
item=item->nextSibling();
}
rdcart_events->insert(line,cmd);
item=new Q3ListViewItem(rdcart_macro_list);
item->setText(0,QString().sprintf("%03u",line+1));
item->setText(1,rdcart_events->command(line)->toString());
rdcart_macro_list->setSelected(item,true);
RefreshList();
}
void MacroCart::DeleteLine(Q3ListViewItem *item)
{
unsigned line=item->text(0).toUInt()-1;
unsigned curr_line;
Q3ListViewItem *next=item->nextSibling();
rdcart_macro_list->removeItem(item);
rdcart_events->remove(line);
Q3ListViewItem *l=rdcart_macro_list->firstChild();
for(int i=0;i<rdcart_macro_list->childCount();i++) {
if(((curr_line=(l->text(0).toUInt()-1))>line)&&
(!l->text(0).isEmpty())) {
l->setText(0,QString().sprintf("%03u",curr_line));
}
l=l->nextSibling();
}
if(next!=NULL) {
rdcart_macro_list->setSelected(next,true);
}
}
void MacroCart::UpdateLength()
{
if(rdcart_events->length()!=rdcart_length) {

View File

@ -2,7 +2,7 @@
//
// The macro cart editor for RDLibrary.
//
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@ -25,8 +25,11 @@
#include <qpushbutton.h>
#include <rdmacro_event.h>
#include <rdmacrocartmodel.h>
#include <rdtableview.h>
#include <rdwidget.h>
#include "edit_macro.h"
#include "globals.h"
class MacroCart : public RDWidget
@ -34,6 +37,7 @@ class MacroCart : public RDWidget
Q_OBJECT
public:
MacroCart(RDCart *cart,QWidget *parent=0);
~MacroCart();
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
unsigned length();
@ -50,21 +54,19 @@ class MacroCart : public RDWidget
void editMacroData();
void runLineMacroData();
void runCartMacroData();
void selectionChangedData(Q3ListViewItem *);
void doubleClickedData(Q3ListViewItem *);
void selectionChangedData(const QItemSelection &before,
const QItemSelection &after);
void doubleClickedData(const QModelIndex &index);
private:
void RefreshList();
void RefreshLine(Q3ListViewItem *item);
void AddLine(unsigned line,RDMacro *cmd);
void DeleteLine(Q3ListViewItem *item);
void UpdateLength();
void SortLines();
RDCart *rdcart_cart;
Q3ListView *rdcart_macro_list;
EditMacro *rdcart_edit_macro_dialog;
RDTableView *rdcart_macro_view;
RDMacroCartModel *rdcart_macro_model;
QLabel *rdcart_macro_list_label;
RDMacroEvent *rdcart_events;
RDMacro rdcart_clipboard;
QString rdcart_clipboard;
QPushButton *paste_macro_button;
QPushButton *rdcart_add_button;
QPushButton *rdcart_delete_button;
@ -77,5 +79,4 @@ class MacroCart : public RDWidget
};
#endif
#endif // MACRO_CART_H

View File

@ -1060,7 +1060,7 @@ poznámky</translation>
</message>
<message>
<source>Macros</source>
<translation>Makra</translation>
<translation type="obsolete">Makra</translation>
</message>
<message>
<source>Edit</source>
@ -1082,18 +1082,6 @@ vozík</translation>
<source>--- End of cart ---</source>
<translation type="obsolete">--- Konec vozíku ---</translation>
</message>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWidget</name>

View File

@ -1048,7 +1048,7 @@ Notes</source>
</message>
<message>
<source>Macros</source>
<translation>Makros</translation>
<translation type="obsolete">Makros</translation>
</message>
<message>
<source>Edit</source>
@ -1070,18 +1070,6 @@ starten</translation>
<source>--- End of cart ---</source>
<translation type="obsolete">--- Ende des Carts ---</translation>
</message>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWidget</name>

View File

@ -1057,7 +1057,7 @@ Notas</translation>
</message>
<message>
<source>Macros</source>
<translation>Macros</translation>
<translation type="obsolete">Macros</translation>
</message>
<message>
<source>Edit</source>
@ -1079,18 +1079,6 @@ Cartucho</translation>
<source>--- End of cart ---</source>
<translation type="obsolete">--- Fin del cartucho ---</translation>
</message>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWidget</name>

View File

@ -741,10 +741,6 @@ Notes</source>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Macros</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
@ -759,18 +755,6 @@ Line</source>
Cart</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWidget</name>

View File

@ -1040,7 +1040,7 @@ Notes</source>
</message>
<message>
<source>Macros</source>
<translation>Makroar</translation>
<translation type="obsolete">Makroar</translation>
</message>
<message>
<source>Edit</source>
@ -1062,18 +1062,6 @@ korg</translation>
<source>--- End of cart ---</source>
<translation type="obsolete">--- Slutten korga ---</translation>
</message>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWidget</name>

View File

@ -1040,7 +1040,7 @@ Notes</source>
</message>
<message>
<source>Macros</source>
<translation>Makroar</translation>
<translation type="obsolete">Makroar</translation>
</message>
<message>
<source>Edit</source>
@ -1062,18 +1062,6 @@ korg</translation>
<source>--- End of cart ---</source>
<translation type="obsolete">--- Slutten korga ---</translation>
</message>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWidget</name>

View File

@ -1042,7 +1042,7 @@ limite do sistema! Você ainda quer salvar?</translation>
</message>
<message>
<source>Macros</source>
<translation>Macros</translation>
<translation type="obsolete">Macros</translation>
</message>
<message>
<source>Edit</source>
@ -1064,18 +1064,6 @@ Cartão</translation>
<source>--- End of cart ---</source>
<translation type="obsolete">-- Fim do Cartão --</translation>
</message>
<message>
<source>Line</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>--- End of Cart ---</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWidget</name>