Skip to content

Commit

Permalink
Added buttons and delete logic changed
Browse files Browse the repository at this point in the history
  • Loading branch information
alesapin committed Sep 17, 2016
1 parent f7d6ae6 commit 88b634a
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 48 deletions.
2 changes: 0 additions & 2 deletions Matches/matchesbasicwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ void MatchesBasicWidget::slotDeselectAllClicked()
{
list->slotDeselectAll();
list->slotSetUserCheckable(false);
selectAll->setEnabled(false);
deselectAll->setEnabled(false);
table->slotHideAll();
emit hideAll();
}
Expand Down
66 changes: 53 additions & 13 deletions Patterns/patternlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,17 @@ bool PatternListModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(parent);
beginRemoveRows(QModelIndex(), row, row + count - 1);
while(count--) rowData.removeAt(row);

while(count--) {
int index = positions[rowData[row].name];
positions.remove(rowData[row].name);
for (auto itr = positions.begin(); itr != positions.end(); ++itr){
if (itr.value() > index) {
positions[itr.key()]--;
}
}
rowData.removeAt(row);
}
endRemoveRows();
return true;
}
Expand Down Expand Up @@ -211,6 +221,48 @@ void PatternListModel::swapRows(int first, int second)
emit dataChanged(createIndex(first,0),createIndex(second,0));
}

QVector<int> PatternListModel::getSelectedPatterns() const
{
QVector<int> result;
for (int i =0; i < rowData.size(); ++i){
if(rowData[i].checked) result.push_front(i);
}
return result;
}

QStringList PatternListModel::getSelectedNames() const
{
QStringList result;
for(int i =0;i<rowData.size();++i){
if (rowData[i].checked){
result.append(rowData[i].name);
}
}
return result;
}

void PatternListModel::checkAll()
{
for(int i = 0;i<rowData.size();++i){
if(rowData[i].state != FailCompiled){
rowData[i].checked = true;
}
}
emit dataChanged(createIndex(0,0),createIndex(rowData.size(),0));
}

void PatternListModel::resetAll()
{
for(int i = 0;i<rowData.size();++i){
if(rowData[i].state != FailCompiled){
rowData[i].checked = false;
}
}
emit dataChanged(createIndex(0,0),createIndex(rowData.size(),0));
}



void PatternListModel::setPatternsUncompiled()
{
for(int i = 0;i<rowData.size();++i){
Expand All @@ -221,15 +273,3 @@ int PatternListModel::columnCount(const QModelIndex &parent) const {
return 2;
}


//QDataStream& operator<<(QDataStream& ostream, const PatternListModel::ListItem& ms)
//{
// ostream << ms.name << ms.text;
// return ostream;
//}

//QDataStream& operator>>(QDataStream& istream, PatternListModel::ListItem& ms)
//{
// istream >> ms.name >> ms.text;
// return istream;
//}
4 changes: 4 additions & 0 deletions Patterns/patternlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class PatternListModel : public QAbstractTableModel
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE;
void swapRows(int first,int second);
QVector<int> getSelectedPatterns() const;
QStringList getSelectedNames() const;
void checkAll() ;
void resetAll();
private:

QWidget* par;
Expand Down
53 changes: 49 additions & 4 deletions Patterns/patternsbasicwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ void PatternsBasicWidget::initPatternEditor()

buttonBar->setMovable(false);
buttonBar->setFloatable(false);
compileButton = new QPushButton(tr("Скомпилировать"),this);
clearAllButton= new QPushButton(tr("Удалить всё"),this);
compileButton = new QPushButton(tr("Компиляция"),this);
matchButton = new QPushButton(tr("Сопоставление"), this);
clearButton= new QPushButton(tr("Удалить"),this);
addButton = new QPushButton(tr("Добавить"),this);
selectAllButton = new QPushButton(tr("Выбрать всё"),this);
deselectAllButton = new QPushButton(tr("Сбросить всё"),this);
buttonBar->addWidget(compileButton);
buttonBar->addWidget(clearAllButton);
buttonBar->addWidget(matchButton);
buttonBar->addWidget(selectAllButton);
buttonBar->addWidget(deselectAllButton);
buttonBar->addWidget(clearButton);
QWidget* container =new QWidget(this);
QVBoxLayout* lay = new QVBoxLayout(container);
lay->setContentsMargins(0,0,0,0);
list = new PatternsList(comp,this);
editor = new PatternEditor(this);
connect(compileButton,SIGNAL(clicked(bool)),list,SLOT(slotCompilePatterns()));
connect(clearAllButton,SIGNAL(clicked(bool)),this,SLOT(slotClearPatterns()));
connect(clearButton,SIGNAL(clicked(bool)),this,SLOT(slotDeleteSelected()));
connect(matchButton,SIGNAL(clicked(bool)),this,SLOT(slotMatchClicked()));
connect(addButton,SIGNAL(clicked(bool)),this,SLOT(slotAddPattern()));
connect(selectAllButton,SIGNAL(clicked(bool)),list,SLOT(slotSelectAll()));
connect(deselectAllButton,SIGNAL(clicked(bool)),list,SLOT(slotDeselectAll()));
connect(list,SIGNAL(editPatternSignal(QString)),editor,SLOT(setText(QString)));
QHBoxLayout* line = new QHBoxLayout();
line->addWidget(editor);
Expand Down Expand Up @@ -120,6 +129,42 @@ void PatternsBasicWidget::slotAddPattern()
editor->clean();
}

void PatternsBasicWidget::slotEnableMatch()
{
matchButton->setEnabled(true);
}

void PatternsBasicWidget::slotMatchClicked()
{
matchButton->setDisabled(true);
emit matchClicked();
}

void PatternsBasicWidget::slotDisableMatch()
{
matchButton->setDisabled(true);
}

void PatternsBasicWidget::slotDeleteSelected()
{
QStringList selected = list->getSelectedPatternNames();
if(!selected.empty()) {
QMessageBox msgBox(
QMessageBox::Information,
tr("Удалить выбранные шаблоны?"),
"Данные шаблоны будут удалены: "+ selected.join(',')+ ".",
QMessageBox::Yes | QMessageBox::No
);
msgBox.setButtonText(QMessageBox::Yes, tr("Да"));
msgBox.setButtonText(QMessageBox::No, tr("Нет"));

if (msgBox.exec() == QMessageBox::Yes) {
list->slotDeleteChecked();
}
}
}





Expand Down
11 changes: 9 additions & 2 deletions Patterns/patternsbasicwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class PatternsBasicWidget : public BasicWidget
PatternEditor* editor;
QPushButton* compileButton;
QPushButton* addButton;
QPushButton* clearAllButton;
QPushButton* clearButton;
QPushButton* matchButton;
QPushButton* selectAllButton;
QPushButton* deselectAllButton;
PatternCompiler* comp;
PatternsList* list;
void initPatternEditor();
Expand All @@ -46,10 +49,14 @@ class PatternsBasicWidget : public BasicWidget
QStringList getPatterns() const;
void loadPatterns(const QStringList& patterns);
signals:

void matchClicked();
public slots:
void slotClearPatterns();
void slotAddPattern();
void slotEnableMatch();
void slotMatchClicked();
void slotDisableMatch();
void slotDeleteSelected();
};

#endif // PATTERNSBASICWIDGET_H
27 changes: 15 additions & 12 deletions Patterns/patternslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ PatternsList::PatternsList(PatternCompiler* compiler,QWidget *parent):QTableView
// setResizeMode(QListView::Adjust);
setContextMenuPolicy(Qt::ActionsContextMenu);
removeAction = new QAction("Удалить",this);
editAction = new QAction("Изменить", this);
this->horizontalHeader()->setStretchLastSection(true);
this->verticalHeader()->hide();
this->horizontalHeader()->hide();
this->setColumnWidth(PatternListModel::CHECK_COLUMN,10);
addAction(removeAction);
addAction(editAction);
this->resizeColumnsToContents();
this->resizeRowsToContents();
connect(removeAction,SIGNAL(triggered()),this,SLOT(slotRemovePattern()));
connect(editAction,SIGNAL(triggered()),this,SLOT(slotEditPattern()));
connect(delegate,SIGNAL(textUpdated()),this,SLOT(slotTextEntered()));
}

Expand Down Expand Up @@ -109,20 +106,26 @@ void PatternsList::slotRemovePattern()
}
}

void PatternsList::slotEditPattern()
void PatternsList::slotTextEntered()
{
QModelIndexList indexes = selectionModel()->selectedIndexes();
if(!indexes.isEmpty()) {
QModelIndex ind = indexes[0];
PatternListModel::ListItem dat = qvariant_cast<PatternListModel::ListItem>(ind.data(Qt::DisplayRole));
emit editPatternSignal(dat.name+" = "+dat.text);
myModel->removeRows(ind.row(),1,ind);
resize(this->width(),this->height()+1);
}

void PatternsList::slotDeleteChecked()
{
QVector<int> selRows = myModel->getSelectedPatterns();
for (int i = 0; i < selRows.size(); ++i){
myModel->removeRows(selRows[i],1,QModelIndex());
}
}

void PatternsList::slotSelectAll()
{
myModel->checkAll();
}

void PatternsList::slotTextEntered()
void PatternsList::slotDeselectAll()
{
resize(this->width(),this->height()+1);
myModel->resetAll();
}

5 changes: 4 additions & 1 deletion Patterns/patternslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PatternsList : public QTableView
void clearAll();
void addPattern(const QString& text);
void addPatterns(const QStringList& patterns);
QStringList getSelectedPatternNames() const {return myModel->getSelectedNames();}
protected:
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
private:
Expand All @@ -38,8 +39,10 @@ class PatternsList : public QTableView
public slots:
void slotCompilePatterns();
void slotRemovePattern();
void slotEditPattern();
void slotTextEntered();
void slotDeleteChecked();
void slotSelectAll();
void slotDeselectAll();
signals:
void editPatternSignal(const QString& text);
};
Expand Down
1 change: 0 additions & 1 deletion Text/matchtextviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ bool MatchTextViewer::isModified()
void MatchTextViewer::dehighlightAll()
{
setExtraSelections(QList<QTextEdit::ExtraSelection>());
emit jobDone();
}


Expand Down
10 changes: 1 addition & 9 deletions Text/textbasicwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ void TextBasicWidget::slotClearMatches()
textEdit->clearSelection();
}

void TextBasicWidget::slotAnalyzeText(){
if(textEdit->count() > 0){
emit buttonClicked();
}
}

void TextBasicWidget::slotEditEnable()
{
Expand Down Expand Up @@ -167,13 +162,10 @@ void TextBasicWidget::initButtons(QMainWindow* wrapper)
QToolBar* buttonBar = new QToolBar(this);
buttonBar->setMovable(false);
buttonBar->setFloatable(false);
analyze = new QPushButton(tr("Наложить"),this);
edit = new QPushButton(tr("Редактировать"),this);
edit = new QPushButton(tr("Редактирование"),this);
statistics = new QPushButton(tr("Статистика"),this);
connect(analyze,SIGNAL(clicked(bool)),this,SLOT(slotAnalyzeText()));
connect(edit,SIGNAL(clicked(bool)),this,SLOT(slotEditEnable()));
connect(statistics,SIGNAL(clicked(bool)),this,SLOT(slotShowStatistics()));
buttonBar->addWidget(analyze);
buttonBar->addWidget(edit);
buttonBar->addWidget(statistics);
wrapper->addToolBar(buttonBar);
Expand Down
2 changes: 0 additions & 2 deletions Text/textbasicwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ class TextBasicWidget : public BasicWidget
QString getText() const ;

signals:
void buttonClicked();
void editEnabled();
void tabClosed(int);
void tabChanged(int);
void checkingEnabled();
public slots:
void slotClearMatches();
void slotAnalyzeText();
void slotEditEnable();
void slotShowStatistics();
void slotSelectFragment(int from,int to);
Expand Down
8 changes: 6 additions & 2 deletions centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ CentralWidget::CentralWidget(QWidget *parent) : QWidget(parent), timeOut(DEFAULT
// vert->addWidget(progress);
mainLay->addWidget(vert);
setLayout(mainLay);
connect(txt,SIGNAL(buttonClicked()),this,SLOT(slotAnalyze()));
connect(pattern,SIGNAL(matchClicked()), this,SLOT(slotAnalyze()));
connect(matches,SIGNAL(patternWasUnchecked(QString)),txt,SLOT(slotPatternUncheked(QString)));
connect(matches,SIGNAL(patternWasChecked(QString)),txt,SLOT(slotPatternChecked(QString)));
connect(matches,SIGNAL(showAll()),txt,SLOT(slotHighlightAll()));
connect(matches,SIGNAL(showAll()),pattern,SLOT(slotDisableMatch()));
connect(matches,SIGNAL(hideAll()),txt,SLOT(slotDehighlightAll()));
connect(matches,SIGNAL(rowClicked(int,int)),txt,SLOT(slotSelectFragment(int,int)));
connect(matches,SIGNAL(patternWasUnchecked(QString)),this,SIGNAL(statusHighlighting()));
Expand All @@ -48,6 +49,7 @@ CentralWidget::CentralWidget(QWidget *parent) : QWidget(parent), timeOut(DEFAULT
connect(txt,SIGNAL(editEnabled()),this,SLOT(slotEdit()));
connect(txt,SIGNAL(checkingEnabled()),matches,SLOT(slotEnableChecking()));
connect(txt,SIGNAL(checkingEnabled()),this,SIGNAL(statusReady()));
connect(txt, SIGNAL(checkingEnabled()),pattern, SLOT(slotEnableMatch()));

connect(watcher,SIGNAL(finished()),this,SLOT(slotDisplay()));
connect(timeoutTimer,SIGNAL(timeout()),this,SLOT(slotTimeout()));
Expand Down Expand Up @@ -115,12 +117,14 @@ void CentralWidget::createBackup() const
void CentralWidget::slotAnalyze()
{
QStringList patternNames = pattern->getChoosenPatternsNames();
if(!patternNames.isEmpty()){
if(!patternNames.isEmpty() && !txt->getText().isEmpty()){
emit statusEngine();
txt->setReadOnly(true);
QFuture<QSharedPointer<PatternViewMap>> future = QtConcurrent::run(compiler,&PatternCompiler::analyzeText,patternNames,txt->getText());
watcher->setFuture(future);
timeoutTimer->start(timeOut);
} else {
pattern->slotEnableMatch();
}
}

Expand Down

0 comments on commit 88b634a

Please sign in to comment.