mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-07 05:56:36 +03:00
Improve UICheckBox in different pixel densities.
Improve stylesheet units printing. Added `dpr` as device-pixel rounded stylesheet length unit. Fixes in 7GUIs Cells.
This commit is contained in:
@@ -26,12 +26,20 @@ EE_MAIN_FUNC int main( int, char** ) {
|
||||
table->setColumnsWidth( PixelDensity::dpToPx( 80 ) );
|
||||
table->setRowHeaderWidth( PixelDensity::dpToPx( 32 ) );
|
||||
table->setSelectionType( UITableView::SelectionType::Cell );
|
||||
table->setRowSearchByName( false );
|
||||
table->setEditable( true );
|
||||
table->setEditTriggers( UIAbstractView::EditTrigger::DoubleClicked |
|
||||
UIAbstractTableView::EditTrigger::EditKeyPressed );
|
||||
table->setEditShortcuts( { { KEY_F2 }, { KEY_RETURN }, { KEY_KP_ENTER } } );
|
||||
table->setSelection( model->index( 0, 0 ) );
|
||||
table->setFocus();
|
||||
table->on( Event::KeyDown, [table, model]( const Event* event ) {
|
||||
if ( table->getSelection().first().isValid() &&
|
||||
event->asKeyEvent()->getKeyCode() == KEY_DELETE ) {
|
||||
model->cell( table->getSelection().first() ).clear();
|
||||
model->invalidate( Model::UpdateFlag::DontInvalidateIndexes );
|
||||
}
|
||||
} );
|
||||
table->onCreateEditingDelegate = [table,
|
||||
model]( const ModelIndex& index ) -> ModelEditingDelegate* {
|
||||
auto ret = StringModelEditingDelegate::New();
|
||||
|
||||
@@ -54,6 +54,8 @@ void SheetFunction::initOpTable() {
|
||||
tot += val;
|
||||
return vals.empty() ? 0 : tot / vals.size();
|
||||
} } );
|
||||
opTable.insert( { String::hash( "COUNT" ),
|
||||
[]( const std::vector<double>& vals ) { return vals.size(); } } );
|
||||
}
|
||||
|
||||
std::vector<double> SheetFunction::evalList( const std::vector<std::shared_ptr<Formula>>& args,
|
||||
|
||||
@@ -16,20 +16,41 @@ void Cell::parseFormula( const std::string& formulaStr ) {
|
||||
|
||||
Cell::Cell( std::string val, Spreadsheet& sheet ) : value( std::move( val ) ), sheet( sheet ) {}
|
||||
|
||||
void Cell::setData( std::string&& data ) {
|
||||
Cell::~Cell() {}
|
||||
|
||||
bool Cell::subscribeToObservers() {
|
||||
if ( formula ) {
|
||||
for ( const auto& ref : formula->getReferences( sheet ) ) {
|
||||
if ( this == ref || hasObserver( ref ) ) {
|
||||
unsubscribeFromObservers();
|
||||
return false;
|
||||
}
|
||||
ref->addObserver( this );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Cell::unsubscribeFromObservers() {
|
||||
if ( formula ) {
|
||||
for ( const auto& ref : formula->getReferences( sheet ) )
|
||||
ref->deleteObserver( this );
|
||||
}
|
||||
}
|
||||
|
||||
void Cell::setData( std::string&& data ) {
|
||||
unsubscribeFromObservers();
|
||||
value = std::move( data );
|
||||
parseFormula( value );
|
||||
calc();
|
||||
if ( formula ) {
|
||||
for ( const auto& ref : formula->getReferences( sheet ) )
|
||||
ref->addObserver( this );
|
||||
bool circular = !subscribeToObservers();
|
||||
if ( circular ) {
|
||||
displayValue = "!CIRCULAR";
|
||||
formulaContainsErrors = true;
|
||||
} else {
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
std::optional<double> Cell::eval() const {
|
||||
@@ -72,6 +93,12 @@ void Cell::calc() {
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void Cell::clear() {
|
||||
value = displayValue = "";
|
||||
formula = {};
|
||||
formulaContainsErrors = false;
|
||||
}
|
||||
|
||||
void Cell::update() {
|
||||
calc();
|
||||
notifyObservers();
|
||||
|
||||
@@ -32,6 +32,8 @@ class Observable {
|
||||
|
||||
void notifyObservers();
|
||||
|
||||
bool hasObserver( Observer* observer ) { return mObservers.count( observer ); }
|
||||
|
||||
protected:
|
||||
std::unordered_set<Observer*> mObservers;
|
||||
std::atomic<bool> mChanged{ false };
|
||||
@@ -46,7 +48,7 @@ class Cell : public Observer, public Observable {
|
||||
public:
|
||||
Cell( std::string val, Spreadsheet& sheet );
|
||||
|
||||
virtual ~Cell() {}
|
||||
virtual ~Cell();
|
||||
|
||||
void setData( std::string&& data );
|
||||
|
||||
@@ -58,6 +60,8 @@ class Cell : public Observer, public Observable {
|
||||
|
||||
void calc();
|
||||
|
||||
void clear();
|
||||
|
||||
void update();
|
||||
|
||||
bool hasFormula() const;
|
||||
@@ -74,6 +78,10 @@ class Cell : public Observer, public Observable {
|
||||
bool formulaContainsErrors{ false };
|
||||
|
||||
void parseFormula( const std::string& formulaStr );
|
||||
|
||||
bool subscribeToObservers();
|
||||
|
||||
void unsubscribeFromObservers();
|
||||
};
|
||||
|
||||
class Spreadsheet : public Model {
|
||||
|
||||
Reference in New Issue
Block a user