Пример #1
0
void Matrix::deleteSelectedRows()
{
	QItemSelectionModel *selModel = d_table_view->selectionModel();
	if (!selModel || !selModel->hasSelection())
		return;

	int startRow = -1;
	int count = 0;
	int rows = numRows();
	for (int i=0; i<rows; i++){
		if (selModel->isRowSelected (i, QModelIndex())){
			if (startRow < 0)
				startRow = i;
			++count;
		}
	}
	if (startRow < 0 || !count)
		return;

	double *buffer = d_matrix_model->dataCopy(startRow, startRow + count - 1, 0, numCols() - 1);
	if (buffer){
    	d_undo_stack->push(new MatrixDeleteRowsCommand(d_matrix_model, startRow, count, buffer, tr("Delete Rows") + " " +
                      QString::number(startRow + 1) + " - " + QString::number(startRow + count)));
    	emit modifiedWindow(this);
	} else if (ignoreUndo()){
		d_matrix_model->removeRows(startRow, count);
		d_table_view->reset();
		emit modifiedWindow(this);
	}
}
Пример #2
0
int Matrix::numSelectedRows()
{
	QItemSelectionModel *selModel = d_table_view->selectionModel();
	if (!selModel || !selModel->hasSelection())
		return 0;

	int rows = numRows();
	int count = 0;
	for (int i = 0; i<rows; i++){
		if (selModel->isRowSelected (i, QModelIndex()))
			count++;
	}
	return count;
}
Пример #3
0
void DeepSkyBrowser::slotMarkSelected()
{
    QItemSelectionModel* sm = treeView->selectionModel();

    bool labelMarker = labelMarkerBox->checkState() == Qt::Checked;
    bool convertOK = false;
    QVariant markerData = markerSymbolBox->itemData(markerSymbolBox->currentIndex());
    MarkerRepresentation::Symbol markerSymbol = (MarkerRepresentation::Symbol) markerData.toInt(&convertOK);
    QVariant markerSize = markerSizeBox->itemData(markerSizeBox->currentIndex());
    float size = (float) markerSize.toInt(&convertOK);
    QColor markerColor = colorSwatch->color();
    Color color((float) markerColor.redF(),
                (float) markerColor.greenF(),
                (float) markerColor.blueF());
    
    Universe* universe = appCore->getSimulation()->getUniverse();
    string label;

    int nRows = dsoModel->rowCount(QModelIndex());
    for (int row = 0; row < nRows; row++)
    {
        if (sm->isRowSelected(row, QModelIndex()))
        {
            DeepSkyObject* dso = dsoModel->itemAtRow((unsigned int) row);
            if (dso != NULL)
            {
                if (convertOK)
                {
                    if (labelMarker)
                    {
                        label = universe->getDSOCatalog()->getDSOName(dso, true);
                        label = ReplaceGreekLetterAbbr(label);
                    }

                    universe->markObject(Selection(dso), 
                                         MarkerRepresentation(markerSymbol, size, color, label),
                                         1);
                }
                else
                {
                    universe->unmarkObject(Selection(dso), 1);
                }
            }
        } // isRowSelected
    } // for
}
Пример #4
0
// can not support recursive selected now.
void LocalView::slot_local_new_upload_requested()
{
    //qDebug() <<__FUNCTION__<<": "<<__LINE__<<":"<< __FILE__;
    TaskPackage pkg(PROTO_FILE);
    QString local_file_name;
    QByteArray ba;

    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    QModelIndex cidx, idx, pidx;

    cidx = ism->currentIndex();
    pidx = cidx.parent();

    for (int i = ism->model()->rowCount(pidx) - 1 ; i >= 0 ; --i) {
        if (ism->isRowSelected(i, pidx)) {
            QModelIndex midx = idx = ism->model()->index(i, 0, pidx);
            if (this->curr_item_view == this->uiw->treeView) {
                midx = this->dir_file_model->mapToSource(midx);
            }
            qDebug()<<this->model->fileName(midx);
            qDebug()<<this->model->filePath(midx);
            local_file_name = this->model->filePath(midx);
            pkg.files<<local_file_name;
        }
    }
    
    // QModelIndexList mil = ism->selectedIndexes(); // TODO should fix win x64

    // for (int i = 0 ; i < mil.count() ; i += this->curr_item_view->model()->columnCount(QModelIndex())) {
    //     QModelIndex midx = mil.at(i);
    //     if (this->curr_item_view==this->uiw->treeView) {
    //         midx = this->dir_file_model->mapToSource(midx);
    //     }
    //     qDebug()<<this->model->fileName(midx);
    //     qDebug()<<this->model->filePath(midx);
    //     local_file_name = this->model->filePath(midx);
    //     pkg.files<<local_file_name;
    // }
    emit new_upload_requested(pkg);
}
Пример #5
0
void LocalView::slot_remove()
{
    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    // QModelIndexList mil;
    QModelIndex cidx, idx;

    if (ism == 0 || !ism->hasSelection()) {
        QMessageBox::critical(this, tr("Warning..."), tr("No item selected").leftJustified(50, ' '));
        return;
    }
    // mil = ism->selectedIndexes();
    cidx = ism->currentIndex();
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());

    QString local_file = this->curr_item_view==this->uiw->treeView
        ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);

    QStringList local_files;
    for (int i = ism->model()->rowCount(cidx.parent())-1; i >= 0; --i) {
        idx = ism->model()->index(i, 0, cidx.parent());
        if (ism->isRowSelected(i, cidx.parent())) {
            local_file = this->curr_item_view==this->uiw->treeView
                ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);
            local_files.prepend(local_file);
        }
    }

    if (QMessageBox::question(this, tr("Question..."), 
                             QString("%1\n    %2").arg(QString(tr("Are you sure remove it?")))
                              .arg(local_files.join("\n    ")),
                             QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {

        bool bok;
        for (int i = ism->model()->rowCount(cidx.parent())-1; i >= 0; --i) {
            idx = ism->model()->index(i, 0, cidx.parent());
            if (ism->isRowSelected(i, cidx.parent())) {
                idx = ism->model()->index(i, 0, cidx.parent());
                if (ism->model() == this->model ?
                    this->model->isDir(idx) : this->model->isDir(idx)) {
                    bok = ism->model() == this->model ?
                        this->model->rmdir(idx) : this->model->rmdir(idx);
                } else {
                    bok = ism->model() == this->model ?
                        this->model->remove(idx) : this->model->remove(idx);
                }

                if (bok) {
                    // this->slot_refresh_directory_tree();
                } else {
                    local_file = this->curr_item_view==this->uiw->treeView
                        ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);
                    q_debug()<<"can not remove file/direcotry:"<<i<<local_file;
                }
            }
        }

        // if (QFile::remove(local_file)) {
        //     this->slot_refresh_directory_tree();    
        // } else {
        //     q_debug()<<"can not remove file:"<<local_file;
        // }
    }
}
Пример #6
0
void ResolutionCalculator::slotSelectionChanged() {
  QItemSelectionModel* selection = ui->rulerView->selectionModel();
  for (int n=0; n<rulers.size(); n++) {
    rulers.at(n)->highlight(selection->isRowSelected(n, QModelIndex()));
  }
}
Пример #7
0
void LogDelegate::paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QModelIndex sourceindex = d->proxy->mapToSource(index);
    QString text = d->soruce->data(sourceindex, Qt::DisplayRole).toString().replace("\n", QString(" ")+QChar(0x14A7)+" ");
    p->setFont(d->font);


    if(option.state & QStyle::State_Selected)
    {
        QItemSelectionModel *selection = d->view->selectionModel();
        bool upstairsneighborselected = selection->isRowSelected(index.row()-1, index.parent());
        bool downstairsneighborselected = selection->isRowSelected(index.row()+1, index.parent());

        int dx = 1;
        int dy = 1;
        int dh = 2;
        int dw = 2;

        if(upstairsneighborselected)
        {
            dy--;
            dh--;
        }
        if(downstairsneighborselected)
        {
            dh--;
        }

        int dashoffset = 0;
        int number_of_upstairsneighborsselected = 0;
        int r = index.row()-1;
        if(option.rect.height()%2)
        {
            while(selection->isRowSelected(r, index.parent()))
            {
                number_of_upstairsneighborsselected++;
                r--;
                if(r < 0) break;
            }
            dashoffset = number_of_upstairsneighborsselected%2;

        }


        p->fillRect(option.rect.x()+dx, option.rect.y()+dy, option.rect.width()-dw, option.rect.height()-dh, option.palette.highlight());

        QPen borderpen(Qt::CustomDashLine);
        borderpen.setColor(Qt::black);
        borderpen.setDashPattern(QVector<qreal>() << 1 << 1);
        borderpen.setDashOffset(dashoffset);
        p->setPen(borderpen);
        p->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
        p->drawLine(option.rect.topRight(), option.rect.bottomRight());
        if(!upstairsneighborselected)
        {
            p->drawLine(option.rect.topLeft(), option.rect.topRight());
        }
        if(!downstairsneighborselected)
        {
            p->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
        }

    }

    if(d->soruce->isRowForErrorStatus(sourceindex.row()))
    {
        if(!d->soruce->wasSuccessfull(sourceindex.row()))
        {
            text = tr("Error: %1").arg(text);
        }
    }

    if(d->soruce->wasSuccessfull(sourceindex.row()))
    {
        p->setPen(QColor(0,128,0));
    }
    else
    {
        if(option.state & QStyle::State_Selected)
        {
            p->setPen(QColor(255,0,0));
        }
        else
        {
            p->setPen(QColor(128,0,0));
        }
    }


    p->drawText(
                option.rect.left(),
                option.rect.bottom() - d->fontmetrics->boundingRect(text).height()/3.25,
                text
                );
}